Feature #44385 ยป replace-mini_mime-with-marcel.patch
| Gemfile | ||
|---|---|---|
|
gem 'rails', '8.1.3.1'
|
||
|
gem 'rouge', '~> 5.0'
|
||
|
gem 'mini_mime', '~> 1.1.0'
|
||
|
gem "actionpack-xml_parser"
|
||
|
gem 'roadie-rails', '~> 3.4.0'
|
||
|
gem 'marcel'
|
||
| lib/redmine/mime_type.rb | ||
|---|---|---|
|
'image/png' => 'png',
|
||
|
'image/tiff' => 'tiff,tif',
|
||
|
'image/webp' => 'webp',
|
||
|
# Not registered with IANA, but matches Marcel's type for .ai
|
||
|
'application/illustrator' => 'ai',
|
||
|
'application/javascript' => 'js',
|
||
|
'application/pdf' => 'pdf',
|
||
|
'video/mp4' => 'mp4',
|
||
| ... | ... | |
|
# returns mime type for name or nil if unknown
|
||
|
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
|
||
|
ext = File.extname(name.to_s).delete_prefix('.').downcase
|
||
|
return if ext.empty?
|
||
|
EXTENSIONS.fetch(ext) do
|
||
|
type = Marcel::MimeType.for(extension: ext)
|
||
|
# Marcel falls back to application/octet-stream for unknown extensions
|
||
|
type unless type == Marcel::MimeType::BINARY
|
||
|
end
|
||
|
end
|
||
| test/unit/lib/redmine/mime_type_test.rb | ||
|---|---|---|
|
assert_includes image_types, 'image/webp'
|
||
|
end
|
||
|
def test_should_default_to_mime_type_gem
|
||
|
def test_should_fall_back_to_marcel
|
||
|
assert !Redmine::MimeType::EXTENSIONS.key?("zip")
|
||
|
assert_equal "application/zip", Redmine::MimeType.of("file.zip")
|
||
|
end
|
||