feat(uploads): make MIME type map extensible via config.uploads.mimeTypes (#3407)#3408
Conversation
…ypes (#3407) Merge config.uploads.mimeTypes at runtime inside createFromBuffer so downstream projects can add custom MIME types without forking the service. Add unit test covering a custom mimeType extension (text/html -> .html).
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 20 minutes and 25 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughThe uploads service's Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3408 +/- ##
==========================================
+ Coverage 85.22% 85.53% +0.31%
==========================================
Files 112 114 +2
Lines 2883 2897 +14
Branches 788 793 +5
==========================================
+ Hits 2457 2478 +21
+ Misses 337 333 -4
+ Partials 89 86 -3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR makes the uploads createFromBuffer filename extension mapping extensible by merging config.uploads.mimeTypes into the built-in MIME→extension map at runtime, enabling downstream projects to add new MIME types without forking.
Changes:
- Merge
config.uploads.mimeTypesinto the built-in MIME type map when deriving the file extension increateFromBuffer. - Add a unit test to verify a custom MIME type (
text/html) maps to a configured extension (.html).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| modules/uploads/services/uploads.service.js | Extends MIME→extension lookup with config.uploads.mimeTypes during createFromBuffer. |
| modules/uploads/tests/uploads.createFromBuffer.unit.tests.js | Adds unit coverage for custom MIME mapping via config. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@modules/uploads/tests/uploads.createFromBuffer.unit.tests.js`:
- Around line 162-176: Add a unit test that exercises the fallback-to-'bin'
logic in UploadsService.createFromBuffer by configuring mockConfig.uploads for a
generic kind that accepts 'application/octet-stream', mocking
mockGridfs.createFromBuffer to resolve with contentType
'application/octet-stream', calling UploadsService.createFromBuffer with that
MIME type and kind, and asserting the filename passed to
mockGridfs.createFromBuffer ends with '.bin' (this covers the branch where
MIME_TO_EXT and config.uploads.mimeTypes do not provide an extension).
🪄 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: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: c71b5b98-a58a-4e5f-85e8-c7d54d14e23e
📒 Files selected for processing (2)
modules/uploads/services/uploads.service.jsmodules/uploads/tests/uploads.createFromBuffer.unit.tests.js
…, add bin fallback test
Allows downstream projects to extend the MIME type map without forking the service.
config.uploads.mimeTypesis merged at runtime into the built-in map insidecreateFromBuffer, so projects can add types liketext/htmlin their own config.Closes #3407
Summary by CodeRabbit
Release Notes
New Features
Tests