diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2018-02-28 21:14:25 +0100 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2018-02-28 21:14:25 +0100 |
commit | 79a5e7fb539dc6df7de590efb69fb9ab9d4614eb (patch) | |
tree | 951e2f3194c4b4d5488864791a9a94afe7122280 /app/uploaders/file_uploader.rb | |
parent | 729391fbfce4dea58478b65c684a24a1bfd125a2 (diff) | |
parent | 7e424eb852716495073881710e8a8851b4a4cd5a (diff) | |
download | gitlab-ce-79a5e7fb539dc6df7de590efb69fb9ab9d4614eb.tar.gz |
Merge commit '7e424eb852716495073881710e8a8851b4a4cd5a' into object-storage-ee-to-ce-backport
Diffstat (limited to 'app/uploaders/file_uploader.rb')
-rw-r--r-- | app/uploaders/file_uploader.rb | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/app/uploaders/file_uploader.rb b/app/uploaders/file_uploader.rb index 81952dacce4..051f1b19938 100644 --- a/app/uploaders/file_uploader.rb +++ b/app/uploaders/file_uploader.rb @@ -17,6 +17,8 @@ class FileUploader < GitlabUploader attr_accessor :model + after :remove, :prune_store_dir + def self.root File.join(options.storage_path, 'uploads') end @@ -62,9 +64,13 @@ class FileUploader < GitlabUploader SecureRandom.hex end - def initialize(model, secret = nil) + attr_accessor :model + + def initialize(model, mounted_as = nil, **uploader_context) + super(model, nil, **uploader_context) + @model = model - @secret = secret + apply_context!(uploader_context) end def base_dir @@ -107,15 +113,17 @@ class FileUploader < GitlabUploader self.file.filename end - # the upload does not hold the secret, but holds the path - # which contains the secret: extract it def upload=(value) + super + + return unless value + return if apply_context!(value.uploader_context) + + # fallback to the regex based extraction if matches = DYNAMIC_PATH_PATTERN.match(value.path) @secret = matches[:secret] @identifier = matches[:identifier] end - - super end def secret @@ -124,6 +132,22 @@ class FileUploader < GitlabUploader private + def apply_context!(uploader_context) + @secret, @identifier = uploader_context.values_at(:secret, :identifier) + + !!(@secret && @identifier) + end + + def build_upload + super.tap do |upload| + upload.secret = secret + end + end + + def prune_store_dir + storage.delete_dir!(store_dir) # only remove when empty + end + def markdown_name (image_or_video? ? File.basename(filename, File.extname(filename)) : filename).gsub("]", "\\]") end |