闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
455 B

  1. # frozen_string_literal: true
  2. module ObfuscateFilename
  3. extend ActiveSupport::Concern
  4. class_methods do
  5. def obfuscate_filename(*args)
  6. before_action { obfuscate_filename(*args) }
  7. end
  8. end
  9. def obfuscate_filename(path)
  10. file = params.dig(*path)
  11. return if file.nil?
  12. file.original_filename = secure_token + File.extname(file.original_filename)
  13. end
  14. def secure_token(length = 16)
  15. SecureRandom.hex(length / 2)
  16. end
  17. end