chore: unified file domain model#380
Conversation
📝 WalkthroughWalkthroughThis PR centralizes file type handling by introducing a new shared Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Fix all issues with AI agents
In `@services/platform/lib/shared/file-types.ts`:
- Around line 91-94: The isParseable and getParseEndpoint functions disagree on
allowed extensions which can cause silent fallback to the PDF parser; update
isParseable and the parsing-extension checks in getParseEndpoint to use the
exact same normalized extension set (include or exclude .doc/.ppt consistently)
and add a defensive processLogger/console.warn inside getParseEndpoint (or its
caller) to log when an unexpected extension is received and the code is falling
back to the PDF route; reference the isParseable function and getParseEndpoint
function names to locate where to align the extension list and insert the
warning.
- Around line 43-69: The MIME sets (IMAGE_MIME_TYPES, DOCUMENT_MIME_TYPES,
PRESENTATION_MIME_TYPES, SPREADSHEET_MIME_TYPES, TEXT_MIME_TYPES) are strict
allow-lists while the helper functions (isImage, isTextFile) use broader
heuristics (e.g., startsWith('image/') and extension checks); add brief doc
comments above each exported ReadonlySet (at least above IMAGE_MIME_TYPES and
TEXT_MIME_TYPES) explaining that the sets are for strict
validation/allow-listing and that isImage() and isTextFile() intentionally
perform looser classification for routing/UX, so they are not interchangeable —
mention examples like image/svg+xml and .txt/.log to clarify intent.
- Around line 218-225: Update getFileTypeLabelKey to detect spreadsheet MIME
types so they don't fall through to 'file': use the existing
SPREADSHEET_MIME_TYPES (and/or MIME_TYPES.XLS, MIME_TYPES.XLSX, MIME_TYPES.CSV)
to check if mimeType matches any spreadsheet entry (e.g.,
SPREADSHEET_MIME_TYPES.includes(mimeType) or compare against MIME_TYPES
constants) and return an appropriate label such as 'spreadsheet' (or specific
keys like 'xls'/'xlsx'/'csv' if you prefer); add this check before the final
return so spreadsheet MIME types are handled by getFileTypeLabelKey.
Add lib/shared/file-types.ts as single source of truth for MIME types, file extensions, accept strings, size limits, classification helpers, and parse endpoint routing. Migrate 13 files to use the shared registry, removing ~120 lines of duplicated file type definitions.
30350ed to
8787c9b
Compare
Summary
lib/shared/file-types.tsas single source of truth for all file type definitions across the platformWhat's in the registry
MIME_TYPES.PDF,MIME_TYPES.DOCX, etc.IMAGE_MIME_TYPES,DOCUMENT_MIME_TYPES,SPREADSHEET_MIME_TYPESisImage(),isTextFile(),isSpreadsheet(),isParseable()extractExtension(),getDisplayExtension()CHAT_UPLOAD_ACCEPT,DOCUMENT_UPLOAD_ACCEPT,SPREADSHEET_IMPORT_ACCEPTCHAT_MAX_FILE_SIZE,DOCUMENT_MAX_FILE_SIZEgetParseEndpoint()getFileTypeLabelKey()Files migrated
use-convex-file-upload.tschat-input.tsxdocument-upload-dialog.tsxMAX_FILE_SIZE_BYTESuse-document-upload.tsMAX_FILE_SIZE_BYTESconstantvendor-import-form.tsx.endsWith()checks + hardcoded acceptproduct-import-form.tsxcustomer-import-form.tsxparse_file.tsgetParseEndpoint()extract_extension.tsprocess_attachments.tsisTextFile+ image classificationdocument-helpers.tsgetFileExtension()→ re-exportdocument-icon.tsxgetExtension()file-parsing.tsisExcelFile()→ uses sharedisSpreadsheet()Test plan
Summary by CodeRabbit