Skip to content

fix: use jsdelivr's content-type header to detect binary file - #2036

Merged
serhalp merged 4 commits into
mainfrom
shuuji3/fix/improve-binary-file-detection-with-content-type
Mar 15, 2026
Merged

fix: use jsdelivr's content-type header to detect binary file#2036
serhalp merged 4 commits into
mainfrom
shuuji3/fix/improve-binary-file-detection-with-content-type

Conversation

@shuuji3

@shuuji3shuuji3 commented Mar 11, 2026

Copy link
Copy Markdown
Member

🔗 Linked issue

resolve#2034

🧭 Context

#1959 introduced a new feature to detect the binary file to prevent showing binary content in the text content viewer. But the current detection method is only checking the filename, resulting in the possible false positive detection.

This switches the logic to use the content-type header from the upstream CDN response.

📚 Description

  • Currently, the server API endpoint to fetch a requested file from jsdelivr CDN, only returns the CDN file content to the client, now it also returns the content-type header value from CDN.
  • Update the binary detection logic on the client side to use content-type. For example, image/* will be estimated as a binary file, instead of checking if the file path ends with .png, .jpg, etc.

Example:

screenshot of binary warning, saying 'Binary file File type 'application/wasm' is not supported for preview. View raw file'

@vercel

vercelBot commented Mar 11, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

ProjectDeploymentActionsUpdated (UTC)
docs.npmx.devReadyReadyPreview, CommentMar 14, 2026 8:37am
npmx.devReadyReadyPreview, CommentMar 14, 2026 8:37am
1 Skipped Deployment
ProjectDeploymentActionsUpdated (UTC)
npmx-lunariaIgnoredIgnoredMar 14, 2026 8:37am

Request Review

@codecov

codecovBot commented Mar 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@shuuji3shuuji3 closed this Mar 12, 2026
@shuuji3
shuuji3force-pushed the shuuji3/fix/improve-binary-file-detection-with-content-type branch from 46a7626 to d3cfce5CompareMarch 12, 2026 02:38
@github-actions

github-actionsBot commented Mar 13, 2026

Copy link
Copy Markdown

Lunaria Status Overview

🌕 This pull request will trigger status changes.

Learn more

By default, every PR changing files present in the Lunaria configuration's files property will be considered and trigger status changes accordingly.

You can change this by adding one of the keywords present in the ignoreKeywords property in your Lunaria configuration file in the PR's title (ignoring all files) or by including a tracker directive in the merged commit's description.

Tracked Files

FileNote
i18n/locales/en.jsonSource changed, localizations will be marked as outdated.
Warnings reference
IconDescription
🔄️The source for this localization has been updated since the creation of this pull request, make sure all changes in the source have been applied.

@shuuji3shuuji3 changed the title fix: add contentType key to /api/registry/file/... responsefix: use jsdlvr's content-type header to detect binary fileMar 14, 2026
@shuuji3shuuji3 changed the title fix: use jsdlvr's content-type header to detect binary filefix: use jsdelivr's content-type header to detect binary fileMar 14, 2026
@coderabbitai

coderabbitaiBot commented Mar 14, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Refactors binary-file detection from path-extension based logic to MIME type-based checks by replacing isBinaryFilePath with isBinaryContentType. The server file fetcher now returns { content, contentType } and the API response exposes a new contentType field. The shared PackageFileContentResponse type gains an optional contentType: string | null. Frontend guards that previously excluded binary files by path were removed; UI warnings for unsupported previews now include the actual MIME content type.

Possibly related PRs

  • feat: add binary file warning #1959: Introduced extension-based binary detection and related UI warning; this PR replaces that detection with MIME-based logic and threads contentType from the server.

Suggested reviewers

  • 43081j
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check nameStatusExplanation
Linked Issues check✅ PassedThe PR addresses issue #2034 by implementing content-type-based binary detection via CDN headers instead of solely relying on file extensions.
Out of Scope Changes check✅ PassedAll changes are scoped to resolving #2034: adding contentType to the API response, updating binary detection logic, and displaying the content type in warnings.
Description check✅ PassedThe pull request description is directly related to the changeset, providing context about the shift from path-based to content-type-based binary file detection.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch shuuji3/fix/improve-binary-file-detection-with-content-type
📝 Coding Plan
  • Generate coding plan for human review comments

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.

@serhalp
serhalp added this pull request to the merge queueMar 15, 2026
Merged via the queue into main with commit d21b146Mar 15, 2026
26 checks passed
@serhalp
serhalp deleted the shuuji3/fix/improve-binary-file-detection-with-content-type branch March 15, 2026 14:55
@github-actionsgithub-actionsBot mentioned this pull request Mar 15, 2026
thegreatalxx added a commit to thegreatalxx/npmx.dev that referenced this pull request Mar 22, 2026
thegreatalxx added a commit to thegreatalxx/npmx.dev that referenced this pull request Mar 22, 2026
Sign up for freeto 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.

Improve binary file detection logic

2 participants

@shuuji3@serhalp