2018-11-08 19:23:39 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
class PersonalFileUploader < FileUploader
|
2018-03-17 18:26:18 +05:30
|
|
|
# Re-Override
|
|
|
|
def self.root
|
|
|
|
options.storage_path
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
def self.base_dir(model, store = nil)
|
|
|
|
base_dirs(model)[store || Store::LOCAL]
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.base_dirs(model)
|
|
|
|
{
|
|
|
|
Store::LOCAL => File.join(options.base_dir, model_path_segment(model)),
|
|
|
|
Store::REMOTE => model_path_segment(model)
|
|
|
|
}
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
def self.model_path_segment(model)
|
|
|
|
return 'temp/' unless model
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
File.join(model.class.to_s.underscore, model.id.to_s)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
def object_store
|
|
|
|
return Store::LOCAL unless model
|
|
|
|
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
# model_path_segment does not require a model to be passed, so we can always
|
|
|
|
# generate a path, even when there's no model.
|
|
|
|
def model_valid?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
# Revert-Override
|
|
|
|
def store_dir
|
2018-05-09 12:01:36 +05:30
|
|
|
store_dirs[object_store]
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
private
|
|
|
|
|
|
|
|
def secure_url
|
|
|
|
File.join('/', base_dir, secret, file.filename)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|