Patch #32146

Add more supported mimetypes

Added by Antonio McDeal 3 months ago. Updated 3 months ago.

Status:NewStart date:
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:Files
Target version:Candidate for next major release

Description

The patch adds more mime-types which are supported by browsers natively, this is considering that Redmine can now also preview some multimedia formats.

more-mimetypes.patch Magnifier (956 Bytes) Antonio McDeal, 2019-09-26 07:40

History

#1 Updated by Go MAEDA 3 months ago

  • Target version set to Candidate for next major release

#2 Updated by Go MAEDA 3 months ago

Maybe we don't have to add .svg, .webp, .ico, .ogg, .wav, and .flac because mini_mime knows them.

[8] pry(main)> MiniMime.lookup_by_filename("a.svg")&.content_type
=> "image/svg+xml" 
[9] pry(main)> MiniMime.lookup_by_filename("a.webp")&.content_type
=> "image/webp" 
[10] pry(main)> MiniMime.lookup_by_filename("a.ico")&.content_type
=> "image/vnd.microsoft.icon" 
[12] pry(main)> MiniMime.lookup_by_filename("a.ogg")&.content_type
=> "audio/ogg" 
[13] pry(main)> MiniMime.lookup_by_filename("a.wav")&.content_type
=> "audio/x-wav" 
[14] pry(main)> MiniMime.lookup_by_filename("a.flac")&.content_type
=> "audio/x-flac" 

#3 Updated by Go MAEDA 3 months ago

"image/apng" is not a registered media type (https://www.iana.org/assignments/media-types/media-types.xhtml). Instead, we can assign "image/png" to ".apng" extension. I was able to preview an APNG animation with the following change.

Index: lib/redmine/mime_type.rb
===================================================================
--- lib/redmine/mime_type.rb    (リビジョン 18541)
+++ lib/redmine/mime_type.rb    (作業コピー)
@@ -41,7 +41,7 @@
       'text/x-po' => 'po',
       'image/gif' => 'gif',
       'image/jpeg' => 'jpg,jpeg,jpe',
-      'image/png' => 'png',
+      'image/png' => 'png,apng',
       'image/tiff' => 'tiff,tif',
       'image/x-ms-bmp' => 'bmp',
       'application/javascript' => 'js',

#4 Updated by Antonio McDeal 3 months ago

Go MAEDA wrote:

Maybe we don't have to add .svg, .webp, .ico, .ogg, .wav, and .flac because mini_mime knows them.

It's for attachment media previewing I suppose.

Or else, does helper Redmine::MimeType.is_type?() also uses mini_mime to check the supported mime-type of a file then?

I was working on feature to enable file previews + side by side revision comparison of multimedia binaries in the repository view, so it's already kind-of partially implemented but only for attachments at the moment -> #27336, but it doesn't work in the repo view as of right now.

For some reason, a helper Redmine::MimeType.is_type?() which it seems like, even #27336 relies on, doesn't return any trues on filetypes, unless they are added to mime_type.rb, hence it seems like a preview won't happen unless things are added to mime_type.rb

Or could I otherwise be doing something wrong?

#5 Updated by Antonio McDeal 3 months ago

Go MAEDA wrote:

"image/apng" is not a registered media type (https://www.iana.org/assignments/media-types/media-types.xhtml). Instead, we can assign "image/png" to ".apng" extension. I was able to preview an APNG animation with the following change.

Yes, thanks for that fix, I used MDN's mime-type list as reference, so hence why I defined it separately.

#6 Updated by Go MAEDA 3 months ago

Antonio McDeal wrote:

Go MAEDA wrote:

Maybe we don't have to add .svg, .webp, .ico, .ogg, .wav, and .flac because mini_mime knows them.

It's for attachment media previewing I suppose.

Or else, does helper Redmine::MimeType.is_type?() also uses mini_mime to check the supported mime-type of a file then?

Yes. For example, .wav is not included in MIME_TYPES constant, but Redmine::MimeType.is_type? says it is a audio file.

[1] pry(main)> Redmine::MimeType.is_type?('audio', 'a.wav')
=> true

This is because mini_mime is used to determine the media type if the given extension is not included in MIME_TYPES constant. The behavior is implemented in Redmine::MimeType.of.

    def self.of(name)
      ext = File.extname(name.to_s)[1..-1]
      if ext
        ext.downcase!
        EXTENSIONS[ext] || MiniMime.lookup_by_extension(ext)&.content_type
      end
    end

#7 Updated by Go MAEDA 3 months ago

Antonio McDeal wrote:

I was working on feature to enable file previews + side by side revision comparison of multimedia binaries in the repository view, so it's already kind-of partially implemented but only for attachments at the moment -> #27336, but it doesn't work in the repo view as of right now.

Maybe it is another issue. I confirmed that audio/video preview in the repository browser does not work at all. Please see #32153.

Also available in: Atom PDF