about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/concerns/obfuscate_filename.rb20
1 files changed, 7 insertions, 13 deletions
diff --git a/app/controllers/concerns/obfuscate_filename.rb b/app/controllers/concerns/obfuscate_filename.rb
index 9c896fb09..22736ec3a 100644
--- a/app/controllers/concerns/obfuscate_filename.rb
+++ b/app/controllers/concerns/obfuscate_filename.rb
@@ -4,19 +4,13 @@ module ObfuscateFilename
   extend ActiveSupport::Concern
 
   class_methods do
-    def obfuscate_filename(*args)
-      before_action { obfuscate_filename(*args) }
-    end
-  end
-
-  def obfuscate_filename(path)
-    file = params.dig(*path)
-    return if file.nil?
+    def obfuscate_filename(path)
+      before_action do
+        file = params.dig(*path)
+        next if file.nil?
 
-    file.original_filename = secure_token + File.extname(file.original_filename)
-  end
-
-  def secure_token(length = 16)
-    SecureRandom.hex(length / 2)
+        file.original_filename = SecureRandom.hex(8) + File.extname(file.original_filename)
+      end
+    end
   end
 end