-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: override blob MIME type #3995
Conversation
Warning There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure. 🔧 eslint
src/wavesurfer.tsOops! Something went wrong! :( ESLint: 9.17.0 ESLint couldn't find an eslint.config.(js|mjs|cjs) file. From ESLint v9.0.0, the default configuration file is now eslint.config.js. https://eslint.org/docs/latest/use/configure/migration-guide If you still have problems after following the migration guide, please stop by WalkthroughThe pull request introduces a new optional property Changes
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (2)
src/wavesurfer.ts (2)
81-82
: Enhance the documentation commentWhile the documentation is clear, it would be helpful to add more context about when this option should be used and provide an example of a valid MIME type.
- /** Override the Blob MIME type */ + /** Override the Blob MIME type when the server's content-type header is incorrect. + * Example: 'audio/wav' or 'audio/mpeg' + */
440-443
: Fix grammatical error in variable nameThe variable name
overridedMimeType
is grammatically incorrect.- const overridedMimeType = this.options.mimeType + const overriddenMimeType = this.options.mimeType
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/wavesurfer.ts
(2 hunks)
🔇 Additional comments (2)
src/wavesurfer.ts (2)
440-443
: Implementation looks good overall!The implementation correctly addresses the issue mentioned in the PR objectives, allowing users to override the MIME type when the server's content-type header is incorrect. The changes are minimal and maintain backward compatibility.
440-443
: Consider adding tests for the new mimeType optionThe PR objectives mention that this should be covered by end-to-end tests, but it would be beneficial to add unit tests as well.
Would you like me to help create unit tests for this new feature?
src/wavesurfer.ts
Outdated
const overridedMimeType = this.options.mimeType | ||
if (overridedMimeType) { | ||
blob = new Blob([blob], { type: overridedMimeType }) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add MIME type validation
The current implementation doesn't validate the provided MIME type, which could lead to runtime errors if an invalid value is provided.
const overriddenMimeType = this.options.mimeType
if (overriddenMimeType) {
+ // Validate that the MIME type starts with 'audio/'
+ if (!overriddenMimeType.startsWith('audio/')) {
+ throw new Error(`Invalid MIME type: ${overriddenMimeType}. Must be an audio MIME type starting with 'audio/'`)
+ }
blob = new Blob([blob], { type: overriddenMimeType })
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
const overridedMimeType = this.options.mimeType | |
if (overridedMimeType) { | |
blob = new Blob([blob], { type: overridedMimeType }) | |
} | |
const overridedMimeType = this.options.mimeType | |
if (overridedMimeType) { | |
// Validate that the MIME type starts with 'audio/' | |
if (!overridedMimeType.startsWith('audio/')) { | |
throw new Error(`Invalid MIME type: ${overridedMimeType}. Must be an audio MIME type starting with 'audio/'`) | |
} | |
blob = new Blob([blob], { type: overridedMimeType }) | |
} |
src/wavesurfer.ts
Outdated
@@ -78,6 +78,8 @@ export type WaveSurferOptions = { | |||
backend?: 'WebAudio' | 'MediaElement' | |||
/** Nonce for CSP if necessary */ | |||
cspNonce?: string | |||
/** Override the Blob MIME type */ | |||
mimeType?: string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since it's only for Blobs, should we call it blobMimeType
?
src/wavesurfer.ts
Outdated
if (overridedMimeType) { | ||
blob = new Blob([blob], { type: overridedMimeType }) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (overridedMimeType) { | |
blob = new Blob([blob], { type: overridedMimeType }) | |
} | |
if (overridenMimeType) { | |
blob = new Blob([blob], { type: overridenMimeType }) | |
} |
Tbh I'm not sure wavesurfer should be handling this. As mentioned in the linked discussion, your server should send the right content-type header. |
Yes, fetch the blob and call |
Thank you! Will release it now. |
Short description
Add a new option(mimeType) to override the blob MIME when the server doesn't send the correct MIME in content-type.
discussion: #3621
related pr: #3471
Implementation details
After fetchBlob in loadAudio, if there there is mimeType option, override the Blob MIME.
How to test it
Screenshots
Checklist
Summary by CodeRabbit