2015-12-10 17:13:39 +01:00
|
|
|
# encoding: utf-8
|
|
|
|
|
|
|
|
class ProcedureLogoUploader < CarrierWave::Uploader::Base
|
|
|
|
|
|
|
|
# Choose what kind of storage to use for this uploader:
|
2016-05-13 16:08:51 +02:00
|
|
|
if Features.remote_storage
|
|
|
|
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
|
2016-05-18 11:43:32 +02:00
|
|
|
unless Features.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
|
|
|
|
|
2016-05-13 16:08:51 +02:00
|
|
|
def cache_dir
|
|
|
|
'/tmp/tps-cache'
|
|
|
|
end
|
2015-12-10 17:13:39 +01:00
|
|
|
|
|
|
|
# Add a white list of extensions which are allowed to be uploaded.
|
|
|
|
# For images you might use something like this:
|
|
|
|
def extension_white_list
|
|
|
|
%w(jpg jpeg png)
|
|
|
|
end
|
|
|
|
|
2016-05-13 16:08:51 +02:00
|
|
|
def filename
|
2016-05-18 11:43:32 +02:00
|
|
|
if original_filename.present? || model.logo_secure_token
|
2016-05-13 16:08:51 +02:00
|
|
|
if Features.remote_storage
|
2016-05-24 17:34:25 +02:00
|
|
|
filename = "#{model.class.to_s.underscore}-#{secure_token}.#{file.extension.downcase}"
|
|
|
|
else
|
|
|
|
filename = "logo.#{file.extension.downcase}"
|
2016-05-13 16:08:51 +02:00
|
|
|
end
|
|
|
|
end
|
2016-05-18 11:43:32 +02:00
|
|
|
filename
|
2016-05-13 16:08:51 +02:00
|
|
|
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
|