diff options
author | Eugen <eugen@zeonfederated.com> | 2017-04-19 23:21:00 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-19 23:21:00 +0200 |
commit | 2e4afccd9d5327c072cf0a0fe5d4c6e97ecc10cf (patch) | |
tree | 1f7c6a8b165d65b1d50f635af683251400c9ce34 /app | |
parent | 0876a06e4544bc0946f3f6d884c7e2507ee12def (diff) |
Fix #2108 - Fix gif uploads (#2171)
* Fix #2108 - Fix gif uploads Add specs for media attachment gifv conversion * Add ffmpeg to travis * Make travis install ffmpeg, not libav * Switch travis to trusty
Diffstat (limited to 'app')
-rw-r--r-- | app/models/media_attachment.rb | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/app/models/media_attachment.rb b/app/models/media_attachment.rb index bb16adb5b..181e01674 100644 --- a/app/models/media_attachment.rb +++ b/app/models/media_attachment.rb @@ -106,13 +106,18 @@ class MediaAttachment < ApplicationRecord end def set_type_and_extension - if file.blank? - self.type = :unknown - else - self.type = VIDEO_MIME_TYPES.include?(file_content_type) ? :video : :image - extension = Paperclip::Interpolations.content_type_extension(file, :original) - basename = Paperclip::Interpolations.basename(file, :original) - file.instance_write :file_name, [basename, extension].delete_if(&:empty?).join('.') - end + self.type = VIDEO_MIME_TYPES.include?(file_content_type) ? :video : :image + extension = appropriate_extension + basename = Paperclip::Interpolations.basename(file, :original) + file.instance_write :file_name, [basename, extension].delete_if(&:empty?).join('.') + end + + def appropriate_extension + mime_type = MIME::Types[file.content_type] + + extensions_for_mime_type = mime_type.empty? ? [] : mime_type.first.extensions + original_extension = Paperclip::Interpolations.extension(file, :original) + + extensions_for_mime_type.include?(original_extension) ? original_extension : extensions_for_mime_type.first end end |