From 922fb74197ef65e6f6ebfba627f80eb483486c1c Mon Sep 17 00:00:00 2001 From: Akihiko Odaki Date: Tue, 30 May 2017 01:14:16 +0900 Subject: Remove methods from ObfuscateFilename and spec (#3347) * Remove methods from ObfuscateFilename * Spec ObfuscateFilename --- app/controllers/concerns/obfuscate_filename.rb | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'app/controllers/concerns') 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 -- cgit