Skip to content

feat: configure mime/type option #398

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

isaac-martin
Copy link

@isaac-martin isaac-martin commented Jan 3, 2025

Improve Audio File Handling and MIME Type Validation

Currently, the plugin's handling of audio files isn't optimal despite Mux supporting audio uploads. This was also reported in issue #382.

You could always upload audio types in this plugin (mainly due to a bug that was allowing it via drag and drop) but this makes it more configurable. It appears that this maybe used to be supported due to some history i found, but appears to be removed at some point.
There is still work to be done to make audio a first class citizen, but this is a good start.

Heres a screen recording of the states working.

Attached is the code for the schema including the various options, and a screenshot of how it would look

image
import { defineField, defineType } from "sanity";

export default defineType({
  name: "muxTest",
  title: "Mux Files",
  type: "document",
  fields: [
    defineField({
      name: "audioFile",
      title: "Audio File",
      type: "mux.video",
      options: {
        acceptedMimeTypes: ["audio/*"],
      },
    }),
    defineField({
      name: "videoFile",
      title: "Video File",
      type: "mux.video",
      options: {
        acceptedMimeTypes: ["video/*"],
      },
    }),
    defineField({
      name: "either",
      title: "Either File",
      type: "mux.video",
    }),
  ],
});

Key Changes

  • Allow acceptedMimeTypes to be configurable at a field and a config level
  • Block files from being uploaded if there is an error in the mime type
  • Fix bug in drag and drop that would allow any file type to be uploaded
  • Do not attempt to upload to Mux if the file type is invalid.
  • Updated documentation, to show examples of overwriting config on a per field level.

Was unsure if we should set the default to audio / video or just video. Technically right now you can do both, due to the broken drag and drop input, so i set both as the default for backwards compatibility.

Note: some browsers when using the audio/* will allow an mp4 to be uploaded as mimeType is just a hint, so we block in the upload and show a toast.

Copy link

vercel bot commented Jan 3, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
sanity-plugin-mux-input-codesandbox ⬜️ Ignored (Inspect) Visit Preview Jan 22, 2025 0:39am

Copy link

vercel bot commented Jan 3, 2025

@isaac-martin is attempting to deploy a commit to the Sanity Sandbox Team on Vercel.

A member of the Team first needs to authorize it.

@isaac-martin isaac-martin changed the title configure mime/type option feat: configure mime/type option Jan 3, 2025
@isaac-martin isaac-martin marked this pull request as ready for review January 3, 2025 09:24
@isaac-martin isaac-martin requested a review from a team as a code owner January 3, 2025 09:24
@isaac-martin
Copy link
Author

@stipsan or @hdoro i think you'd be best to review this considering your contributions to this plugin in the past

name: 'mainVideo',
type: 'mux.video',
options: {
encoding_tier: 'baseline',

Choose a reason for hiding this comment

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

encoding_tier has been renamed to video_quality (and smart -> plus and baseline -> basic)

I don't think the Sanity plugin supports video_quality yet, so this isn't an actionable comment. Just making a note that, at some point, we'll need to update the Sanity plugin to reflect this.

Copy link
Contributor

@R-Delfino95 R-Delfino95 left a comment

Choose a reason for hiding this comment

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

I got some errors when trying to build the plugin locally but by making these changes it worked as in the recording

isaac-martin and others added 2 commits January 22, 2025 11:39
Co-authored-by: Renzo Delfino <[email protected]>
Signed-off-by: Isaac Martin <[email protected]>
Co-authored-by: Renzo Delfino <[email protected]>
Signed-off-by: Isaac Martin <[email protected]>
Copy link
Contributor

@R-Delfino95 R-Delfino95 left a comment

Choose a reason for hiding this comment

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

After running the linter, I noticed that the config prop is not being used in the UploadPlaceholder component. It seems unnecessary, so we should remove it.
Let me know if there's any reason to keep it that I might have missed

@@ -364,6 +411,8 @@ export default function Uploader(props: Props) {
/>
) : (
<UploadPlaceholder
accept={acceptMimeString}
config={props.config}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
config={props.config}

@@ -12,9 +12,11 @@ interface UploadPlaceholderProps {
hovering: boolean
needsSetup: boolean
onSelect: FileInputButtonProps['onSelect']
accept: string
config: PluginConfig
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
config: PluginConfig

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.

3 participants