diff --git a/Gemfile.lock b/Gemfile.lock index 143f06c997..60c127fca9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -75,7 +75,7 @@ PATH activerecord (= 7.0.0.alpha) activesupport (= 7.0.0.alpha) marcel (~> 0.3.1) - mimemagic (~> 0.3.2) + mini_mime (~> 1.0.2) activesupport (7.0.0.alpha) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) diff --git a/activestorage/activestorage.gemspec b/activestorage/activestorage.gemspec index e3a4c13149..28a55b9ba6 100644 --- a/activestorage/activestorage.gemspec +++ b/activestorage/activestorage.gemspec @@ -37,5 +37,5 @@ Gem::Specification.new do |s| s.add_dependency "activerecord", version s.add_dependency "marcel", "~> 0.3.1" - s.add_dependency "mimemagic", "~> 0.3.2" + s.add_dependency "mini_mime", "~> 1.0.2" end diff --git a/activestorage/app/models/active_storage/blob/representable.rb b/activestorage/app/models/active_storage/blob/representable.rb index 065ac3ad0c..e2c2663331 100644 --- a/activestorage/app/models/active_storage/blob/representable.rb +++ b/activestorage/app/models/active_storage/blob/representable.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require "mimemagic" +require "mini_mime" module ActiveStorage::Blob::Representable extend ActiveSupport::Concern @@ -110,10 +110,10 @@ module ActiveStorage::Blob::Representable end def format - if filename.extension.present? && MimeMagic.by_extension(filename.extension)&.to_s == content_type + if filename.extension.present? && MiniMime.lookup_by_extension(filename.extension)&.content_type == content_type filename.extension else - MimeMagic.new(content_type).extensions.first + MiniMime.lookup_by_content_type(content_type).extension end end diff --git a/activestorage/app/models/active_storage/variation.rb b/activestorage/app/models/active_storage/variation.rb index 8aa36f005e..70979b613e 100644 --- a/activestorage/app/models/active_storage/variation.rb +++ b/activestorage/app/models/active_storage/variation.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require "mimemagic" +require "mini_mime" # A set of transformations that can be applied to a blob to create a variant. This class is exposed via # the ActiveStorage::Blob#variant method and should rarely be used directly. @@ -59,14 +59,14 @@ class ActiveStorage::Variation def format transformations.fetch(:format, :png).tap do |format| - if MimeMagic.by_extension(format).nil? + if MiniMime.lookup_by_extension(format.to_s).nil? raise ArgumentError, "Invalid variant format (#{format.inspect})" end end end def content_type - MimeMagic.by_extension(format).to_s + MiniMime.lookup_by_extension(format.to_s).content_type end # Returns a signed key for all the +transformations+ that this variation was instantiated with.