2016-11-02 10:18:59 +01:00
|
|
|
class ProcedureLogoUploader < BaseUploader
|
2016-05-24 18:35:25 +02:00
|
|
|
def root
|
2018-03-06 13:44:29 +01:00
|
|
|
Rails.root.join("public")
|
2016-05-24 18:35:25 +02:00
|
|
|
end
|
|
|
|
|
2015-12-10 17:13:39 +01:00
|
|
|
# Choose what kind of storage to use for this uploader:
|
2018-04-18 12:24:37 +02:00
|
|
|
if Flipflop.remote_storage?
|
2016-05-13 16:08:51 +02:00
|
|
|
storage :fog
|
|
|
|
else
|
|
|
|
storage :file
|
|
|
|
end
|
2015-12-10 17:13:39 +01:00
|
|
|
|
|
|
|
# Override the directory where uploaded files will be stored.
|
|
|
|
# This is a sensible default for uploaders that are meant to be mounted:
|
|
|
|
def store_dir
|
2018-04-18 12:24:37 +02:00
|
|
|
if !Flipflop.remote_storage?
|
2016-05-13 16:08:51 +02:00
|
|
|
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
|
|
|
|
end
|
2015-12-10 17:13:39 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
# Add a white list of extensions which are allowed to be uploaded.
|
|
|
|
# For images you might use something like this:
|
2019-05-07 13:20:20 +02:00
|
|
|
def extension_whitelist
|
2018-10-01 13:55:12 +02:00
|
|
|
['jpg', 'jpeg', 'png']
|
2015-12-10 17:13:39 +01:00
|
|
|
end
|
|
|
|
|
2016-05-13 16:08:51 +02:00
|
|
|
def filename
|
2018-11-27 14:02:29 +01:00
|
|
|
if file.present?
|
|
|
|
if original_filename.present? || model.logo_secure_token
|
|
|
|
if Flipflop.remote_storage?
|
2019-02-25 14:52:52 +01:00
|
|
|
filename = "#{model.class.to_s.underscore}-#{secure_token}.#{file.extension&.downcase}"
|
2018-11-27 14:02:29 +01:00
|
|
|
else
|
2019-02-25 14:52:52 +01:00
|
|
|
filename = "logo-#{secure_token}.#{file.extension&.downcase}"
|
2018-11-27 14:02:29 +01:00
|
|
|
end
|
2016-05-13 16:08:51 +02:00
|
|
|
end
|
2018-11-27 14:02:29 +01:00
|
|
|
filename
|
2016-05-13 16:08:51 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def secure_token
|
|
|
|
model.logo_secure_token ||= generate_secure_token
|
|
|
|
end
|
|
|
|
|
|
|
|
def generate_secure_token
|
|
|
|
SecureRandom.uuid
|
|
|
|
end
|
2015-12-10 17:13:39 +01:00
|
|
|
end
|