question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Editor: Make mime type config less confusing

See original GitHub issue

Task Description

We currently pass this list of mime/file types to the editor:

https://github.com/GoogleForCreators/web-stories-wp/blob/f130e0cfa2c69ddd07201db7c1b74d58b24bf341/includes/Admin/Editor.php#L363-L369

As we are working on some documentation on using the decoupled story editor, it became more obvious how confusing this config is.

  • allowedMimeTypes: map of allowed mime types for actual story elements. For example, allowedMimeTypes.image might contain image/svg+xml or something to say that you can drop SVGs on the canvas
  • allowedImageMimeTypes : this is used for places in the design/document tab where you can upload images (video poster, story poster, publisher logo). For example, here we would never want to allow uploading SVGs. Hence this separate config.
  • allowedAudioMimeTypes: similarly, this is used for when you want to add background audio to a page.

In addition to that, allowedFileTypes is just a simple array of file types so that in the editor we can say “You are only allowed to upload jpeg, png, gif” etc. We can just get rid of this and use getExtensionFromMimeType from the media package instead.

allowedTranscodableMimeTypes is really pointless too, which is why I opened #10591 for that already.

To-do

  • Rename allowedMimeTypes to somehting more obvious, like for example allowedElementMimeTypes
  • Maybe rename allowedImageMimeTypes and allowedAudioMimeTypes to something more obvious too
  • Make allowedFileTypes obsolete by assembling that on-the-fly in the editor instead, using getExtensionFromMimeType

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
ayushnirwalcommented, Feb 24, 2022

There might be a problem with passing down mime types and getting an extension array in the case of image/jpeg since both .jpeg and .jpg have the mime-type image/jpeg. if allowedImageMimeTypes is ['image/jpeg'] allowedImageFileTypes would be ['jpeg'] but MediaUpload would accept both jpeg and jpg files.

1reaction
swissspidycommented, Feb 21, 2022

Precisely. That’s what I meant in the ticket description by saying we can make it obsolete.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Properly configuring server MIME types - MDN Web Docs
If a web server or application reports an incorrect MIME type for content (including a "default type" for unknown content), a web browser...
Read more >
arch linux - Digging deeper into differing mime-type associations
It is normal to have different mime-type file associations on different systems, even when those systems are running the same version of the ......
Read more >
How to add *.less to IIS 7.0? - Stack Overflow
There is no need to add a handler. Just add a MIME type (now known as Internet Media Type) for .less and set...
Read more >
All known MIME types - mimetype.io
KRA is the file format for Krita, a raster graphics editor. It is a ZIP archive containing a number of files, including the...
Read more >
Files starting with a comment have the wrong mime type
I've tried editing the /etc/mime.types file to make the system aware of the extension. First I added less as an extension of text/css...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found