about summary refs log tree commit diff
path: root/app/models
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2019-06-22 16:54:06 +0200
committermultiple creatures <dev@multiple-creature.party>2020-02-21 03:44:25 -0600
commit698684843748b9b847b8a6cf8cd2a30e3b507884 (patch)
tree32b8d34a5354261ef6aa1c8d582a2003684d79fc /app/models
parent81681f04cad137f19e77dacecc619bccde38b8fb (diff)
port tootsuite#11151 to monsterfork: Fix audio-only OGG and WebM files not being processed as such
Also, because Chrome sends audio/mp3 instead of audio/mpeg as it's
supposed to, we need to whitelist that mime type as well
Diffstat (limited to 'app/models')
-rw-r--r--app/models/concerns/attachmentable.rb11
-rw-r--r--app/models/media_attachment.rb7
2 files changed, 17 insertions, 1 deletions
diff --git a/app/models/concerns/attachmentable.rb b/app/models/concerns/attachmentable.rb
index 08af107c7..c3c7c7a35 100644
--- a/app/models/concerns/attachmentable.rb
+++ b/app/models/concerns/attachmentable.rb
@@ -11,10 +11,21 @@ module Attachmentable
     before_post_process :obfuscate_file_name
     before_post_process :set_file_extensions
     before_post_process :check_image_dimensions
+    before_post_process :set_file_content_type
   end
 
   private
 
+  def set_file_content_type
+    self.class.attachment_definitions.each_key do |attachment_name|
+      attachment = send(attachment_name)
+
+      next if attachment.blank? || attachment.queued_for_write[:original].blank?
+
+      attachment.instance_write :content_type, calculated_content_type(attachment)
+    end
+  end
+
   def set_file_extensions
     self.class.attachment_definitions.each_key do |attachment_name|
       attachment = send(attachment_name)
diff --git a/app/models/media_attachment.rb b/app/models/media_attachment.rb
index 74f6c8899..4e57571d8 100644
--- a/app/models/media_attachment.rb
+++ b/app/models/media_attachment.rb
@@ -30,10 +30,15 @@ class MediaAttachment < ApplicationRecord
   VIDEO_FILE_EXTENSIONS = ['.webm', '.mp4', '.m4v', '.mov'].freeze
   AUDIO_FILE_EXTENSIONS = ['.ogg', '.oga', '.mp3', '.wav', '.flac', '.opus'].freeze
 
+<<<<<<< HEAD
   IMAGE_MIME_TYPES             = ['image/jpeg', 'image/png', 'image/gif'].freeze
   VIDEO_MIME_TYPES             = ['video/webm', 'video/mp4', 'video/quicktime'].freeze
+=======
+  IMAGE_MIME_TYPES             = ['image/jpeg', 'image/png', 'image/gif', 'image/webp'].freeze
+  VIDEO_MIME_TYPES             = ['video/webm', 'video/mp4', 'video/quicktime', 'video/ogg'].freeze
+>>>>>>> b927bb3f0... Fix audio-only OGG and WebM files not being processed as such (#11151)
   VIDEO_CONVERTIBLE_MIME_TYPES = ['video/webm', 'video/quicktime'].freeze
-  AUDIO_MIME_TYPES             = ['audio/wave', 'audio/wav', 'audio/x-wav', 'audio/x-pn-wave', 'audio/ogg', 'audio/mpeg', 'audio/webm', 'audio/flac'].freeze
+  AUDIO_MIME_TYPES             = ['audio/wave', 'audio/wav', 'audio/x-wav', 'audio/x-pn-wave', 'audio/ogg', 'audio/mpeg', 'audio/mp3', 'audio/webm', 'audio/flac'].freeze
 
   BLURHASH_OPTIONS = {
     x_comp: 4,