about summary refs log tree commit diff
path: root/app/models/concerns/attachmentable.rb
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2020-01-05 13:51:50 +0100
committerGitHub <noreply@github.com>2020-01-05 13:51:50 +0100
commitbcfd6e3bb48f6e0eb88f7f3a650832842ab69166 (patch)
tree0e2bb7334c7954bee2962ed78565046e3b974725 /app/models/concerns/attachmentable.rb
parent22daf24600d8e99e4569740ee5836d25c70c1e8b (diff)
parent83359fef2b04e81b35b047510ddb0c79bcf8ddaa (diff)
Merge pull request #1259 from ThibG/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'app/models/concerns/attachmentable.rb')
-rw-r--r--app/models/concerns/attachmentable.rb11
1 files changed, 11 insertions, 0 deletions
diff --git a/app/models/concerns/attachmentable.rb b/app/models/concerns/attachmentable.rb
index 3bbc6453c..1e8c4806f 100644
--- a/app/models/concerns/attachmentable.rb
+++ b/app/models/concerns/attachmentable.rb
@@ -9,6 +9,7 @@ module Attachmentable
   GIF_MATRIX_LIMIT = 921_600    # 1280x720px
 
   included do
+    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
@@ -68,4 +69,14 @@ module Attachmentable
   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