The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { errorDisplayMessage } from "@t3tools/client-runtime/errors"; |
| 2 | import { isZipError } from "@t3tools/client-runtime/zip/error"; |
| 3 | import { ZIP_ERROR_MESSAGES } from "@t3tools/client-runtime/zip/error-messages"; |
| 4 | import { msg } from "gt-react"; |
| 5 | |
| 6 | import { m, type MessageResolver } from "~/i18n/messages"; |
| 7 | |
| 8 | import { isPreviewError, type PreviewFailure } from "./previewFailure"; |
| 9 | |
| 10 | const PREVIEW_FAILURE_MESSAGES = { |
| 11 | ...ZIP_ERROR_MESSAGES, |
| 12 | "file-load-failed": msg("The file could not be loaded. Close it and try again."), |
| 13 | "file-unavailable": msg("The file is unavailable."), |
| 14 | "document-unavailable": msg("This file is unavailable."), |
| 15 | "document-unavailable-or-too-large": msg("This file is unavailable or too large to preview."), |
| 16 | "document-too-large": msg("This file is too large to preview."), |
| 17 | "preview-failed": msg("Could not preview this file."), |
| 18 | "read-failed": msg("Could not read this file."), |
| 19 | "parse-failed": msg("Could not parse this file."), |
| 20 | "tar-numeric-format": msg("This TAR uses an unsupported numeric format."), |
| 21 | "tar-header-damaged": msg("The TAR header is damaged."), |
| 22 | "archive-entry-damaged": msg("An archive entry is too large or damaged."), |
| 23 | "archive-metadata-too-large": msg("Archive metadata is too large."), |
| 24 | "tar-metadata-damaged": msg("The TAR metadata is damaged."), |
| 25 | "archive-empty": msg("This archive has no readable entries."), |
| 26 | "archive-entry-unavailable": msg("This archive entry is unavailable."), |
| 27 | "archive-entry-too-large": msg("Entry previews are limited to 10 MB."), |
| 28 | "table-unavailable": msg("This table is unavailable."), |
| 29 | "database-too-many-tables": msg("Database previews are limited to 100 tables."), |
| 30 | "text-too-large": msg("Text previews support files up to 256 MB."), |
| 31 | "text-binary": msg("This file contains binary data."), |
| 32 | "text-line-too-long": msg("A line or record exceeds the 1 MB preview limit."), |
| 33 | "text-too-many-rows": msg("Text previews support up to 5 million rows."), |
| 34 | "text-download-incomplete": msg("The file download was incomplete. Close it and try again."), |
| 35 | "text-copy-before-loaded": msg("Wait for the file to finish loading before copying."), |
| 36 | "sheet-unavailable": msg("This sheet is unavailable."), |
| 37 | "xml-invalid": msg("This document contains invalid or unsupported XML."), |
| 38 | "xml-too-deep": msg("This document is nested too deeply to preview."), |
| 39 | "xml-too-much-content": msg("This document has too much content to preview."), |
| 40 | "rendered-too-large": msg("The rendered document is too large to preview."), |
| 41 | "repeated-content-invalid": msg("This document contains invalid repeated content."), |
| 42 | "odf-no-content": msg("This OpenDocument file has no readable content."), |
| 43 | "ods-sheet-count": msg("This workbook has no sheets or too many sheets to preview."), |
| 44 | "ods-cell-too-large": msg("A spreadsheet cell is too large to preview."), |
| 45 | "ods-too-much-text": msg("This spreadsheet has too much text to preview."), |
| 46 | "odf-page-count": msg("This document has no pages or too many pages to preview."), |
| 47 | "epub-no-package": msg("This EPUB has no readable package."), |
| 48 | "epub-chapter-count": msg("This EPUB has no chapters or too many chapters to preview."), |
| 49 | "epub-no-chapters": msg("This EPUB has no readable XHTML chapters."), |
| 50 | "notebook-cell-too-large": msg("A notebook cell is too large to preview."), |
| 51 | "notebook-too-large": msg("Notebook preview limited to files under 8 MB."), |
| 52 | "notebook-unsupported": msg("Preview supports version 4 notebooks with up to 500 cells."), |
| 53 | "notebook-too-many-outputs": msg("A notebook cell has too many outputs to preview."), |
| 54 | "rtf-too-large": msg("Rich text preview limited to files under 8 MB."), |
| 55 | "rtf-invalid": msg("This is not a valid rich text document."), |
| 56 | "rtf-too-many-pages": msg("Rich text preview limited to 500 pages."), |
| 57 | "rtf-too-much-content": msg("This rich text document has too much content to preview."), |
| 58 | "rtf-too-deep": msg("This rich text document is nested too deeply."), |
| 59 | "rtf-damaged": msg("This rich text document is damaged."), |
| 60 | "rtf-byte-escape": msg("Invalid rich text byte escape."), |
| 61 | "rtf-binary-data": msg("Invalid rich text binary data."), |
| 62 | "rtf-code-page": msg("This rich text code page is not supported."), |
| 63 | "office-xml-declarations": msg("This document contains unsupported XML declarations."), |
| 64 | "word-xml-nesting": msg("This Word document has excessive XML nesting."), |
| 65 | "word-section-markup": msg("This Word document has too much section markup."), |
| 66 | "word-limited-section-markup": msg( |
| 67 | "Preview limited: this Word document has too much section markup.", |
| 68 | ), |
| 69 | "word-no-body": msg("This Word document has no readable body."), |
| 70 | "word-limited-aliased-part": msg( |
| 71 | "Preview limited: this Word document has an aliased document part.", |
| 72 | ), |
| 73 | "word-limited-relationship": msg( |
| 74 | "Preview limited: this Word document has an unsupported document relationship.", |
| 75 | ), |
| 76 | "word-limited-xml-nesting": msg("Preview limited: this Word document has excessive XML nesting."), |
| 77 | "word-limited-archive-paths": msg( |
| 78 | "Preview limited: this Word document has unsupported archive paths.", |
| 79 | ), |
| 80 | "word-limited-auxiliary-markup": msg( |
| 81 | "Preview limited: this Word document has too much auxiliary markup.", |
| 82 | ), |
| 83 | "word-limited-expanded-markup": msg( |
| 84 | "Preview limited: this Word document has too much expanded markup.", |
| 85 | ), |
| 86 | "word-fonts-unprepared": msg("The document's fonts could not be prepared"), |
| 87 | "word-no-pages": msg("The document produced no pages"), |
| 88 | "workbook-cell-coordinates": msg("This workbook contains invalid cell coordinates."), |
| 89 | "workbook-dimensions": msg("This workbook contains invalid worksheet dimensions."), |
| 90 | "workbook-xml-nesting": msg("This workbook contains excessive XML nesting."), |
| 91 | "workbook-structure": msg("This workbook contains invalid worksheet structure."), |
| 92 | "workbook-row-coordinates": msg("This workbook contains invalid row coordinates."), |
| 93 | "workbook-too-many-rows": msg("This workbook exceeds the preview limit: 250,000 rows."), |
| 94 | "workbook-inconsistent-rows": msg("This workbook contains inconsistent cell rows."), |
| 95 | "workbook-too-many-cells": msg( |
| 96 | "This workbook exceeds the preview limit: 2 million cells or 8 million grid positions.", |
| 97 | ), |
| 98 | "workbook-cell-metadata": msg("This workbook contains invalid cell metadata."), |
| 99 | "workbook-no-data": msg("This workbook has no worksheet data."), |
| 100 | "workbook-duplicate-styles": msg("This workbook contains duplicate stylesheet blocks."), |
| 101 | "workbook-number-formats": msg("This workbook has too many custom number formats."), |
| 102 | "workbook-sheet-count": msg("This workbook has invalid or too many sheets."), |
| 103 | "workbook-missing-sheet": msg("This workbook has a missing worksheet."), |
| 104 | "office-too-large-expanded": msg("The expanded document is too large to preview safely."), |
| 105 | "office-invalid": msg("This file is damaged, encrypted, or not a valid Office document."), |
| 106 | "office-too-many-entries": msg("This file contains too many archive entries to preview."), |
| 107 | "office-not-open-xml": msg( |
| 108 | "This is not a valid Office Open XML file. Encrypted files are not supported.", |
| 109 | ), |
| 110 | "office-timeout": msg("This document took too long to preview. Open it in another app."), |
| 111 | "office-engine-stopped": msg("The Office engine stopped"), |
| 112 | "office-engine-unreadable": msg("The Office engine sent an unreadable reply"), |
| 113 | "presentation-no-worker-fonts": msg("This browser has no fonts in workers"), |
| 114 | "tiff-metadata-invalid": msg("Invalid TIFF metadata."), |
| 115 | "tiff-metadata-truncated": msg("This TIFF has too much or truncated metadata."), |
| 116 | "tiff-metadata-type": msg("Unsupported TIFF metadata type."), |
| 117 | "tiff-metadata-pointer": msg("Invalid TIFF metadata pointer."), |
| 118 | "image-too-large": msg("Image previews are limited to 32 megapixels and 16,384 pixels per side."), |
| 119 | "image-metadata-too-large": msg("This image has too much metadata."), |
| 120 | "heif-metadata-invalid": msg("Invalid HEIF metadata."), |
| 121 | "heif-dimensions-invalid": msg("Invalid HEIF dimensions."), |
| 122 | "heif-no-dimensions": msg("This HEIF image has no readable dimensions."), |
| 123 | "tiff-strip-invalid-or-oversized": msg("Invalid or oversized TIFF strip."), |
| 124 | "tiff-lzw-invalid": msg("Invalid TIFF LZW dictionary."), |
| 125 | "tiff-strip-truncated": msg("Truncated TIFF strip."), |
| 126 | "tiff-strip-layout": msg("Unsupported TIFF strip layout."), |
| 127 | "tiff-strip-invalid": msg("Invalid TIFF strip."), |
| 128 | "tiff-strip-oversized": msg("Oversized TIFF strip."), |
| 129 | "tiff-compression": msg("This TIFF compression is not supported."), |
| 130 | "tiff-data-too-large": msg("This TIFF has too much image data."), |
| 131 | "tiff-no-image": msg("This TIFF has no readable image."), |
| 132 | "tiff-orientation": msg("This TIFF orientation is not supported."), |
| 133 | "tiff-color-format": msg("This TIFF color format is not supported."), |
| 134 | "image-decoding-unavailable": msg("Image decoding is unavailable."), |
| 135 | "image-decode-failed": msg("Could not decode this image."), |
| 136 | } as const; |
| 137 | |
| 138 | export type PreviewFailureCode = keyof typeof PREVIEW_FAILURE_MESSAGES; |
| 139 | |
| 140 | export function previewFailureText(failure: PreviewFailure, resolve: MessageResolver = m): string { |
| 141 | return failure.code ? resolve(PREVIEW_FAILURE_MESSAGES[failure.code]) : failure.message; |
| 142 | } |
| 143 | |
| 144 | export function previewErrorText(cause: unknown, fallback: string): string { |
| 145 | if (isPreviewError(cause) || isZipError(cause)) return m(PREVIEW_FAILURE_MESSAGES[cause.code]); |
| 146 | return errorDisplayMessage(cause, m) ?? fallback; |
| 147 | } |