perf(web): optimize document upload validation with static sets, MIME checks, and 50MB size guard - #1604
Open
muskanai0409-cell wants to merge 1 commit into
Conversation
… checks, and 50MB size guard - Hoist ALLOWED_EXTENSIONS and ALLOWED_MIME_TYPES Sets to module scope so batch drag-and-drop no longer re-allocates them per file check - Fail fast on files larger than 50MB (matching the chat attachment and backend worker limit) with a dedicated toast instead of uploading them only to be rejected at the gateway - Verify MIME types directly (application/pdf, Office types, text/csv, text/plain, ...) so extensionless uploads such as mobile blobs are accepted, stripping parameters like ";charset=utf-8" before lookup, with the extension check kept as fallback - Add application/pdf to FILE_ACCEPT, matching CHAT_ATTACHMENT_ACCEPT Fixes supermemoryai#1559 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1559
What changed
Refactors
isAcceptedFile()inapps/web/components/add-document/file.tsxper the issue:ALLOWED_EXTENSIONSandALLOWED_MIME_TYPESare now created once at module load instead of re-instantiating aSeton every call, eliminating redundant heap allocations during batch drag-and-drop.isAcceptedFile()now rejects files overMAX_FILE_SIZE_BYTES(50MB), matching the limit already enforced by chat attachments (CHAT_ATTACHMENT_MAX_BYTESinapps/web/components/chat/attachments.ts) and the backend workers. Oversized files never start uploading, andaddFiles()shows a dedicated toast ("One file exceeds the 50 MB limit") separate from the unsupported-type toast, so users get accurate feedback.ALLOWED_MIME_TYPESfirst (application/pdf, Word/Excel Office types,text/csv,text/plain,text/markdown,application/json,text/html) withimage/*prefix support, so extensionless mobile uploads (e.g. ablobwithtype: "application/pdf") are accepted. MIME parameters such as;charset=utf-8are stripped before the lookup. The extension check is kept as a fallback for files with no/unknown MIME type.application/pdfadded toFILE_ACCEPT, aligning it withCHAT_ATTACHMENT_ACCEPT.Behavior notes
Verification
bun test(extension matrix, case-insensitivity, extensionless MIME acceptance, charset parameters,image/*, exact-50MB boundary, >50MB rejection, unsupported types) — 12 tests, all passing locally.bunx biome checkon the changed file: clean.tsc --noEmitinapps/web: no new errors introduced (the 84 pre-existing errors onmainare unchanged).🤖 Generated with Claude Code