Skip to content

feat(uploads): make MIME type map extensible via config.uploads.mimeTypes (#3407)#3408

Merged
PierreBrisorgueil merged 2 commits into
masterfrom
feat/uploads-extensible-mime-types
Apr 7, 2026
Merged

feat(uploads): make MIME type map extensible via config.uploads.mimeTypes (#3407)#3408
PierreBrisorgueil merged 2 commits into
masterfrom
feat/uploads-extensible-mime-types

Conversation

@PierreBrisorgueil

@PierreBrisorgueil PierreBrisorgueil commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

Allows downstream projects to extend the MIME type map without forking the service.

config.uploads.mimeTypes is merged at runtime into the built-in map inside createFromBuffer, so projects can add types like text/html in their own config.

Closes #3407

Summary by CodeRabbit

Release Notes

  • New Features

    • The upload system now supports custom MIME type to file extension mappings via configuration, giving administrators the ability to define custom extensions for specific content types beyond the built-in defaults.
  • Tests

    • Added test coverage verifying that custom MIME type mappings are correctly applied to uploaded file extensions.

…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).
Copilot AI review requested due to automatic review settings April 7, 2026 10:20
@coderabbitai

coderabbitai Bot commented Apr 7, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@PierreBrisorgueil has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 20 minutes and 25 seconds before requesting another review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 2d44d5fc-7776-4199-be81-6e2e06ee6573

📥 Commits

Reviewing files that changed from the base of the PR and between b2d65e3 and b2b55d7.

📒 Files selected for processing (2)
  • modules/uploads/services/uploads.service.js
  • modules/uploads/tests/uploads.createFromBuffer.unit.tests.js

Walkthrough

The uploads service's createFromBuffer method now merges the built-in MIME type-to-extension mappings with optional custom mappings from config.uploads.mimeTypes, allowing projects to extend supported file types without forking the service. A corresponding unit test verifies this functionality.

Changes

Cohort / File(s) Summary
MIME Type Mapping Extension
modules/uploads/services/uploads.service.js
Updated createFromBuffer to merge custom MIME type mappings from config.uploads.mimeTypes with the default MIME_TO_EXT object, enabling runtime extensibility of supported content types.
Test Coverage
modules/uploads/tests/uploads.createFromBuffer.unit.tests.js
Added unit test verifying that custom file extensions from config.uploads.mimeTypes are correctly applied when generating upload filenames for custom MIME types.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The description is concise and addresses the core change, but omits most required template sections such as scope, validation checklist, guardrails, and notes for reviewers. Fill out the provided template sections including scope (modules impacted, cross-module impact, risk level), validation checklist items, guardrails verification, and relevant reviewer notes for completeness.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and accurately describes the main feature: making the MIME type map extensible via config, which aligns with the code changes that merge config.uploads.mimeTypes into the built-in MIME_TO_EXT mapping.
Linked Issues check ✅ Passed The code changes fully implement the issue #3407 objective by merging config.uploads.mimeTypes into the built-in MIME_TO_EXT map at runtime, enabling downstream projects to extend MIME type mappings without forking.
Out of Scope Changes check ✅ Passed All code changes in both the service and test files are directly scoped to the MIME type extensibility feature described in issue #3407, with no extraneous modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/uploads-extensible-mime-types

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented Apr 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.53%. Comparing base (3337568) to head (b2b55d7).
⚠️ Report is 7 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.mimeTypes into the built-in MIME type map when deriving the file extension in createFromBuffer.
  • 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.

Comment thread modules/uploads/services/uploads.service.js Outdated
Comment thread modules/uploads/services/uploads.service.js Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 207b248 and b2d65e3.

📒 Files selected for processing (2)
  • modules/uploads/services/uploads.service.js
  • modules/uploads/tests/uploads.createFromBuffer.unit.tests.js

Comment thread modules/uploads/tests/uploads.createFromBuffer.unit.tests.js
@PierreBrisorgueil
PierreBrisorgueil merged commit 9b490d2 into master Apr 7, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(uploads): make MIME type map extensible via config.uploads.mimeTypes

2 participants