LibreChat/client/src/utils
Danny Avila e079fc4900
📎 fix: Enforce File Count and Size Limits Across All Attachment Paths (#12239)
* 🐛 fix: Enforce fileLimit and totalSizeLimit in Attached Files panel

The Files side panel (PanelTable) was not checking fileLimit or
totalSizeLimit from fileConfig when attaching previously uploaded files,
allowing users to bypass per-endpoint file count and total size limits.

* 🔧 fix: Address review findings on file limit enforcement

- Fix totalSizeLimit double-counting size of already-attached files
- Clarify fileLimit error message: "File limit reached: N files (endpoint)"
- Replace Array.from(...).reduce with for...of loop to avoid intermediate allocation
- Extract inline `type TFile` into standalone `import type` per project conventions

*  test: Add PanelTable handleFileClick file limit tests

Cover fileLimit guard, totalSizeLimit guard, passing case,
double-count prevention for re-attached files, and boundary case.

* 🔧 test: Harden PanelTable test mock setup

- Use explicit endpoint key matching mockConversation.endpoint
  instead of relying on default fallback behavior
- Add supportedMimeTypes to mock config for explicit MIME coverage
- Throw on missing filename cell in clickFilenameCell to prevent
  silent false-positive blocking assertions

* ♻️ refactor: Align file validation ordering and messaging across upload paths

- Reorder handleFileClick checks to match validateFiles:
  disabled → fileLimit → fileSizeLimit → checkType → totalSizeLimit
- Change fileSizeLimit comparison from > to >= in handleFileClick
  to match validateFiles behavior
- Align validateFiles error strings with localized key wording:
  "File limit reached:", "File size limit exceeded:", etc.
- Remove stray console.log in validateFiles MIME-type check

*  test: Add validateFiles unit tests for both paths' consistency

13 tests covering disabled, empty, fileLimit (reject + boundary),
fileSizeLimit (>= at limit + under limit), checkType, totalSizeLimit
(reject + at limit), duplicate detection, and check ordering.
Ensures both validateFiles and handleFileClick enforce the same
validation rules in the same order.
2026-03-15 10:39:42 -04:00
..
__tests__ 📎 fix: Enforce File Count and Size Limits Across All Attachment Paths (#12239) 2026-03-15 10:39:42 -04:00
agents.tsx 📌 feat: Pin Agents and Models in the Sidebar (#10634) 2025-12-11 16:38:20 -05:00
artifacts.ts 🏎️ refactor: Replace Sandpack Code Editor with Monaco for Artifact Editing (#12109) 2026-03-06 15:02:04 -05:00
buildDefaultConvo.ts 🎭 feat: Override Custom Endpoint Schema with Specified Params Endpoint (#11788) 2026-02-13 23:04:51 -05:00
buildTree.ts 🐛 fix: String Interpolation in Messages Endpoint from #9155 (#9312) 2025-08-27 13:48:48 -04:00
citations.ts 📑 refactor: File Search Citations Dual-Format Unicode Handling (#10888) 2025-12-10 13:25:56 -05:00
cleanupPreset.ts 🎭 feat: Override Custom Endpoint Schema with Specified Params Endpoint (#11788) 2026-02-13 23:04:51 -05:00
cn.ts 🪟 fix+feat: General UI Enhancements (#2619) 2024-05-09 17:46:16 -04:00
collection.ts 🗨️ feat: Prompt Slash Commands (#3219) 2024-06-27 17:34:48 -04:00
conversationTags.spec.ts 🔖 feat: Conversation Bookmarks (#3344) 2024-07-29 10:45:59 -04:00
conversationTags.ts 🔖 feat: Conversation Bookmarks (#3344) 2024-07-29 10:45:59 -04:00
convos.fakeData.ts 🔧 chore: Update ESLint Config & Run Linter (#10986) 2025-12-15 17:55:25 -05:00
convos.spec.ts 🌊 feat: Resumable LLM Streams with Horizontal Scaling (#10926) 2025-12-19 12:14:19 -05:00
convos.ts 🌊 feat: Resumable LLM Streams with Horizontal Scaling (#10926) 2025-12-19 12:14:19 -05:00
createChatSearchParams.spec.ts feat: implement search parameter updates (#7151) 2025-05-09 13:03:33 -04:00
createChatSearchParams.ts 🌐 fix: Preserve URL Query Params Through Auth Refresh and Conversation Init (#12028) 2026-03-02 23:32:53 -05:00
drafts.ts 🏄‍♂️ fix: Handle SSE Stream Edge Case (#8556) 2025-07-19 13:44:02 -04:00
email.ts 📬 feat: Agent Support Email Address Validation (#9128) 2025-08-19 11:07:01 -04:00
endpoints.spec.ts 📂 refactor: Cleanup File Filtering Logic, Improve Validation (#10414) 2025-11-10 19:05:30 -05:00
endpoints.ts 🗂️ refactor: Artifacts via Model Specs & Scope Badge Persistence by Spec Context (#11796) 2026-02-14 13:56:50 -05:00
errors.ts 🧭 fix: Robust 404 Conversation Not Found Redirect (#11853) 2026-02-18 11:41:53 -05:00
files.ts 📎 fix: Enforce File Count and Size Limits Across All Attachment Paths (#12239) 2026-03-15 10:39:42 -04:00
forms.tsx 👤 feat: Agent Avatar Removal and Decouple upload/reset from Agent Updates (#10527) 2025-11-17 17:04:01 -05:00
getDefaultEndpoint.ts 🔃 refactor: Streamline Navigation, Message Loading UX (#7118) 2025-04-28 18:18:13 -04:00
getLoginError.ts 🔒feat: Enable OpenID Auto-Redirect (#6066) 2025-03-19 09:51:56 -04:00
getThemeFromEnv.js 📦 feat: Move Shared Components to @librechat/client (#8685) 2025-07-27 12:19:01 -04:00
heicConverter.ts 🖼️ feat: Add support for HEIC image format (#7914) 2025-06-17 21:12:15 -04:00
imageResize.ts 🖼️ feat: Add Optional Client-Side Image Resizing to Prevent Upload Errors (#7909) 2025-06-24 10:43:29 -04:00
index.ts 🎞️ refactor: Image Rendering with Preview Caching and Layout Reservation (#12114) 2026-03-06 19:09:52 -05:00
json.ts feat: Google Gemini ❇️ (#1355) 2023-12-15 02:18:07 -05:00
languages.ts 🎉 feat: Code Interpreter API and Agents Release (#4860) 2024-12-04 15:48:13 -05:00
latex.spec.ts 💲 fix: Prevent Single-dollar LaTeX for abbrev. Currency (K, M, B) (#9293) 2025-08-26 23:33:56 -04:00
latex.ts 💲 fix: Prevent Single-dollar LaTeX for abbrev. Currency (K, M, B) (#9293) 2025-08-26 23:33:56 -04:00
localStorage.ts 💾 chore: Enhance Local Storage Handling and Update MCP SDK (#6809) 2025-04-09 18:38:48 -04:00
logger.ts 🗝️ fix: React Key Props and Minor UI Fixes from a11y Updates (#10954) 2025-12-12 23:09:05 -05:00
map.ts 🔒 feat: View/Delete Shared Agent Files (#8419) 2025-07-12 01:52:46 -04:00
markdown.ts 📝 feat: Add Markdown Rendering Support for Artifacts (#10049) 2025-10-11 10:37:35 -04:00
memory.ts 🧠 feat: User Memories for Conversational Context (#7760) 2025-06-07 18:52:22 -04:00
mermaid.ts 🌗 refactor: Consistent Mermaid Theming for Inline and Artifact Renderers (#12055) 2026-03-04 09:28:19 -05:00
messages.ts 🔧 refactor: Display name logic in Parallel Responses (#11149) 2025-12-29 21:42:21 -05:00
presets.ts 🏷️ refactor: EditPresetDialog UI and Remove chatGptLabel from Presets (#7543) 2025-05-24 19:24:42 -04:00
previewCache.ts 🎞️ refactor: Image Rendering with Preview Caching and Layout Reservation (#12114) 2026-03-06 19:09:52 -05:00
promptGroups.ts 🗨️ feat: Prompt Slash Commands (#3219) 2024-06-27 17:34:48 -04:00
prompts.ts 🗓️ feat: Add Special Variables for Prompts & Agents, Prompt UI Improvements (#7123) 2025-04-29 03:49:02 -04:00
redirect.ts 🔒 fix: Request interceptor for Shared Link Page Scenarios (#12036) 2026-03-03 12:03:33 -05:00
resetConvo.ts 🐛 fix: Update resetConvo.ts (#3105) 2024-06-21 10:13:21 -04:00
resources.ts style(MCP): Enhance dialog accessibility and styling consistency (#11585) 2026-02-11 22:08:40 -05:00
roles.ts 🛸 feat: Remote Agent Access with External API Support (#11503) 2026-01-28 17:44:33 -05:00
routes.ts 🤝 feat: View Artifacts in Shared Conversations (#10477) 2025-11-13 16:59:46 -05:00
share.ts 🔗 fix: Share Links Respect Custom Base Path (#11087) 2025-12-24 17:59:40 -05:00
textarea.ts feat: Quality-of-Life Chat/Edit-Message Enhancements (#5194) 2025-01-06 22:47:24 -05:00
timestamps.ts 📌 fix: Exclude Pinned Keys from Cleanup and Fix MCP Pin State (#9867) 2025-09-27 17:21:48 -04:00