2016-08-18 10:31:44 -04:00
|
|
|
class GitlabUploader < CarrierWave::Uploader::Base
|
2017-02-28 13:34:43 -05:00
|
|
|
def self.absolute_path(upload_record)
|
|
|
|
File.join(CarrierWave.root, upload_record.path)
|
|
|
|
end
|
|
|
|
|
2017-02-23 16:54:25 -05:00
|
|
|
def self.base_dir
|
|
|
|
'uploads'
|
|
|
|
end
|
|
|
|
|
|
|
|
delegate :base_dir, to: :class
|
|
|
|
|
2017-06-01 03:52:19 -04:00
|
|
|
def file_storage?
|
2017-05-04 17:02:51 -04:00
|
|
|
storage.is_a?(CarrierWave::Storage::File)
|
|
|
|
end
|
|
|
|
|
2017-06-01 03:52:19 -04:00
|
|
|
def file_cache_storage?
|
2017-05-04 17:02:51 -04:00
|
|
|
cache_storage.is_a?(CarrierWave::Storage::File)
|
2017-02-23 16:54:25 -05:00
|
|
|
end
|
|
|
|
|
2016-08-18 10:31:44 -04:00
|
|
|
# Reduce disk IO
|
|
|
|
def move_to_cache
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
# Reduce disk IO
|
|
|
|
def move_to_store
|
|
|
|
true
|
|
|
|
end
|
2017-02-28 13:34:43 -05:00
|
|
|
|
|
|
|
# Designed to be overridden by child uploaders that have a dynamic path
|
|
|
|
# segment -- that is, a path that changes based on mutable attributes of its
|
|
|
|
# associated model
|
|
|
|
#
|
|
|
|
# For example, `FileUploader` builds the storage path based on the associated
|
|
|
|
# project model's `path_with_namespace` value, which can change when the
|
|
|
|
# project or its containing namespace is moved or renamed.
|
|
|
|
def relative_path
|
|
|
|
self.file.path.sub("#{root}/", '')
|
|
|
|
end
|
2017-05-01 09:14:35 -04:00
|
|
|
|
|
|
|
def exists?
|
|
|
|
file.try(:exists?)
|
|
|
|
end
|
2016-08-18 10:31:44 -04:00
|
|
|
end
|