Skip to content
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

Fix some MP3 files not being recognized as such #12809

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion app/models/concerns/attachmentable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ module Attachmentable
MAX_MATRIX_LIMIT = 16_777_216 # 4096x4096px or approx. 16MB
GIF_MATRIX_LIMIT = 921_600 # 1280x720px

BOGUS_MIME_TYPES = %w(application/x-font-gdos).freeze

included do
before_post_process :obfuscate_file_name
before_post_process :set_file_extensions
Expand Down Expand Up @@ -63,7 +65,12 @@ def appropriate_extension(attachment)
end

def calculated_content_type(attachment)
content_type = Paperclip.run('file', '-b --mime :file', file: attachment.queued_for_write[:original].path).split(/[:;\s]+/).first.chomp
content_types = Paperclip.run('file', '-b -k -r --mime :file', file: attachment.queued_for_write[:original].path).split("\n- ")
content_types -= BOGUS_MIME_TYPES

return '' if content_types.empty?

content_type = content_types.first.split(/[:;\s]+/).first.chomp
content_type = 'video/mp4' if content_type == 'video/x-m4v'
content_type
rescue Terrapin::CommandLineError
Expand Down