diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2020-01-04 01:54:07 +0100 |
---|---|---|
committer | multiple creatures <dev@multiple-creature.party> | 2020-02-21 02:34:04 -0600 |
commit | e46051ca94690782ca24741a570f2051296cd2d5 (patch) | |
tree | f16b80b68fa0975e2acd73862bfdceed9a63c95d /app/models | |
parent | 90f2752375145432747c559e0d44e0c86b2eef53 (diff) |
port tootsuite#12748 to monsterfork: Fix base64-encoded file uploads not being possible
Fix #3804, Fix #5776
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/concerns/attachmentable.rb | 19 | ||||
-rw-r--r-- | app/models/media_attachment.rb | 3 |
2 files changed, 22 insertions, 0 deletions
diff --git a/app/models/concerns/attachmentable.rb b/app/models/concerns/attachmentable.rb index de4cf8775..dd11e0814 100644 --- a/app/models/concerns/attachmentable.rb +++ b/app/models/concerns/attachmentable.rb @@ -8,6 +8,7 @@ module Attachmentable MAX_MATRIX_LIMIT = 16_777_216 # 4096x4096px or approx. 16MB included do + before_post_process :obfuscate_file_name before_post_process :set_file_extensions before_post_process :check_image_dimensions end @@ -47,4 +48,22 @@ module Attachmentable extension 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_type = 'video/mp4' if content_type == 'video/x-m4v' + content_type + rescue Terrapin::CommandLineError + '' + end + + def obfuscate_file_name + self.class.attachment_definitions.each_key do |attachment_name| + attachment = send(attachment_name) + + next if attachment.blank? + + attachment.instance_write :file_name, SecureRandom.hex(8) + File.extname(attachment.instance_read(:file_name)) + end + end end diff --git a/app/models/media_attachment.rb b/app/models/media_attachment.rb index 4f0a09784..d2db899ab 100644 --- a/app/models/media_attachment.rb +++ b/app/models/media_attachment.rb @@ -184,9 +184,12 @@ class MediaAttachment < ApplicationRecord end after_commit :reset_parent_cache, on: :update + before_create :prepare_description, unless: :local? before_create :set_shortcode + before_post_process :set_type_and_extension + before_save :set_meta class << self |