fix: add new env variable for allowed file extensions to upload#951
Conversation
Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
📝 WalkthroughWalkthroughAdds FILE_UPLOAD_ALLOWED_EXTENSIONS (example env), exposes it as window.FILE_UPLOAD_ALLOWED_EXTENSIONS in app init, adds getFileUploadAllowedExtensions() to parse it, and updates three upload components to use that parsed list for their allowedExtensions. ChangesFile Upload Extensions Configuration
Sequence DiagramsequenceDiagram
participant Build as Build/Server
participant App as App Init (src/app.js)
participant Window as window
participant Util as getFileUploadAllowedExtensions()
participant Component as Upload Components
Build->>App: provide process.env.FILE_UPLOAD_ALLOWED_EXTENSIONS
App->>Window: set window.FILE_UPLOAD_ALLOWED_EXTENSIONS
Component->>Util: call getFileUploadAllowedExtensions()
Util-->>Component: return parsed extensions array
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/utils/methods.js (1)
633-634: ⚡ Quick winNormalize extension tokens before returning them.
Line 634 currently keeps whitespace/dot/case as-is, so values like
"pdf, jpg"or".PDF"can produce unusable entries.Suggested patch
-export const getFileUploadAllowedExtensions = () => - window.FILE_UPLOAD_ALLOWED_EXTENSIONS?.split(",").filter(Boolean) ?? []; +export const getFileUploadAllowedExtensions = () => + (window.FILE_UPLOAD_ALLOWED_EXTENSIONS ?? "") + .split(",") + .map((ext) => ext.trim().replace(/^\./, "").toLowerCase()) + .filter(Boolean);🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/utils/methods.js` around lines 633 - 634, getFileUploadAllowedExtensions currently returns raw tokens which may contain whitespace, leading dots or mixed case; update the function (getFileUploadAllowedExtensions) to normalize each token after split by trimming whitespace, stripping any leading dot(s), converting to lowercase, and then filtering out empty strings so the returned array contains clean extension tokens (preserve the existing null/undefined handling with optional chaining and the fallback empty array).src/pages/sponsors-global/form-templates/sponsor-inventory-popup.js (1)
81-82: ⚡ Quick winRemove debug logging from upload dialog.
Line 81 introduces a console debug statement that should not ship.
Suggested patch
- console.log("CHECK!", getFileUploadAllowedExtensions()); -🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/pages/sponsors-global/form-templates/sponsor-inventory-popup.js` around lines 81 - 82, Remove the stray debug console.log call so it doesn't ship; specifically delete the console.log("CHECK!", getFileUploadAllowedExtensions()) statement in the sponsor upload/dialog code (the line invoking getFileUploadAllowedExtensions()). Leave any real logging or error handling intact and, if needed, replace with a proper processLogger or debug-flagged logger rather than console.log.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/pages/sponsors-global/form-templates/sponsor-inventory-popup.js`:
- Around line 81-82: Remove the stray debug console.log call so it doesn't ship;
specifically delete the console.log("CHECK!", getFileUploadAllowedExtensions())
statement in the sponsor upload/dialog code (the line invoking
getFileUploadAllowedExtensions()). Leave any real logging or error handling
intact and, if needed, replace with a proper processLogger or debug-flagged
logger rather than console.log.
In `@src/utils/methods.js`:
- Around line 633-634: getFileUploadAllowedExtensions currently returns raw
tokens which may contain whitespace, leading dots or mixed case; update the
function (getFileUploadAllowedExtensions) to normalize each token after split by
trimming whitespace, stripping any leading dot(s), converting to lowercase, and
then filtering out empty strings so the returned array contains clean extension
tokens (preserve the existing null/undefined handling with optional chaining and
the fallback empty array).
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 3a3a2583-87b6-41e3-a3a6-c67acc8dd3fe
📒 Files selected for processing (6)
.env.examplesrc/app.jssrc/pages/sponsors-global/form-templates/sponsor-inventory-popup.jssrc/pages/sponsors-global/page-templates/page-template-popup/modules/page-template-document-download-module.jssrc/pages/sponsors/sponsor-form-item-list-page/components/sponsor-form-item-form.jssrc/utils/methods.js
Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/app.js`:
- Around line 109-110: The assignment to window.FILE_UPLOAD_ALLOWED_EXTENSIONS
falls back to ALLOWED_INVENTORY_IMAGE_FORMATS which is likely an array, breaking
the env contract that expects a CSV string; update the fallback in the
window.FILE_UPLOAD_ALLOWED_EXTENSIONS assignment so it always yields a CSV
string (e.g. convert ALLOWED_INVENTORY_IMAGE_FORMATS to a comma-separated string
or use the same CSV literal used in .env.example) so downstream parsing receives
a consistent string type.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 71b09160-31b4-42d0-8bf5-39976608da83
📒 Files selected for processing (5)
.env.examplesrc/app.jssrc/pages/sponsors-global/form-templates/sponsor-inventory-popup.jssrc/pages/sponsors-global/page-templates/page-template-popup/modules/page-template-document-download-module.jssrc/pages/sponsors/sponsor-form-item-list-page/components/sponsor-form-item-form.js
| window.FILE_UPLOAD_ALLOWED_EXTENSIONS = | ||
| process.env.FILE_UPLOAD_ALLOWED_EXTENSIONS || ALLOWED_INVENTORY_IMAGE_FORMATS; |
There was a problem hiding this comment.
Keep fallback format/content aligned with the env contract.
This fallback uses ALLOWED_INVENTORY_IMAGE_FORMATS, but .env.example defines a broader CSV list for FILE_UPLOAD_ALLOWED_EXTENSIONS. If the env var is missing, behavior can diverge and the value type may differ from the parser’s expected string contract.
Proposed fix
+const DEFAULT_FILE_UPLOAD_ALLOWED_EXTENSIONS = [
+ "pdf",
+ ...ALLOWED_INVENTORY_IMAGE_FORMATS
+].join(",");
+
window.FILE_UPLOAD_ALLOWED_EXTENSIONS =
- process.env.FILE_UPLOAD_ALLOWED_EXTENSIONS || ALLOWED_INVENTORY_IMAGE_FORMATS;
+ process.env.FILE_UPLOAD_ALLOWED_EXTENSIONS ||
+ DEFAULT_FILE_UPLOAD_ALLOWED_EXTENSIONS;🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/app.js` around lines 109 - 110, The assignment to
window.FILE_UPLOAD_ALLOWED_EXTENSIONS falls back to
ALLOWED_INVENTORY_IMAGE_FORMATS which is likely an array, breaking the env
contract that expects a CSV string; update the fallback in the
window.FILE_UPLOAD_ALLOWED_EXTENSIONS assignment so it always yields a CSV
string (e.g. convert ALLOWED_INVENTORY_IMAGE_FORMATS to a comma-separated string
or use the same CSV literal used in .env.example) so downstream parsing receives
a consistent string type.
* fix: add new env variable for allowed file extensions to upload Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com> * fix: clean console log, adjust extensions prop, add fallback value Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com> --------- Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
ref: https://app.clickup.com/t/86ba0v63v
Signed-off-by: Tomás Castillo tcastilloboireau@gmail.com
Summary by CodeRabbit