summaryrefslogtreecommitdiff
path: root/app/uploaders
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-02-16 19:58:40 +0100
committerDouwe Maan <douwe@gitlab.com>2015-02-17 22:23:31 +0100
commitd2ebdf664b42d4fac6b2e060ef79aa9fe0b0e72d (patch)
tree061aa99c9a95b506a4ee665c25bd1d83a467c46f /app/uploaders
parent192e7306626e073a5e6fb3b41d69f0e3fddb0821 (diff)
downloadgitlab-ce-d2ebdf664b42d4fac6b2e060ef79aa9fe0b0e72d.tar.gz
Refactor.
Diffstat (limited to 'app/uploaders')
-rw-r--r--app/uploaders/attachment_uploader.rb2
-rw-r--r--app/uploaders/file_uploader.rb38
2 files changed, 13 insertions, 27 deletions
diff --git a/app/uploaders/attachment_uploader.rb b/app/uploaders/attachment_uploader.rb
index 22742d287a4..58dc6e90c1e 100644
--- a/app/uploaders/attachment_uploader.rb
+++ b/app/uploaders/attachment_uploader.rb
@@ -21,7 +21,7 @@ class AttachmentUploader < CarrierWave::Uploader::Base
end
def secure_url
- Gitlab.config.gitlab.relative_url_root + "/files/#{model.class.to_s.underscore}/#{model.id}/#{file.filename}"
+ File.join(Gitlab.config.gitlab.relative_url_root, "files", model.class.to_s.underscore, model.id.to_s, file.filename)
end
def file_storage?
diff --git a/app/uploaders/file_uploader.rb b/app/uploaders/file_uploader.rb
index 51ae8040e52..c040f6bbe92 100644
--- a/app/uploaders/file_uploader.rb
+++ b/app/uploaders/file_uploader.rb
@@ -2,47 +2,33 @@
class FileUploader < CarrierWave::Uploader::Base
storage :file
- def initialize(base_dir, path = '', allowed_extensions = nil)
- @base_dir = base_dir
- @path = path
- @allowed_extensions = allowed_extensions
+ def initialize(project, secret = self.class.generate_secret)
+ @project = project
+ @secret = secret
end
def base_dir
- @base_dir
+ "#{Rails.root}/uploads"
end
def store_dir
- File.join(@base_dir, @path)
+ File.join(base_dir, @project.path_with_namespace, @secret)
end
def cache_dir
- File.join(@base_dir, 'tmp', @path)
+ File.join(base_dir, 'tmp', @project.path_with_namespace, @secret)
end
- def extension_white_list
- @allowed_extensions || super
- end
-
- def store!(file)
- @filename = self.class.generate_filename(file)
- super
- end
-
- def self.generate_filename(file)
- original_filename = File.basename(file.original_filename, '.*')
- extension = File.extname(file.original_filename)
- new_filename = Digest::MD5.hexdigest(original_filename) + extension
- end
-
- def self.generate_dir
+ def self.generate_secret
SecureRandom.hex(5)
end
def secure_url
- path_array = @path.split('/')
- path = File.join(path_array[0],path_array[1],'uploads',path_array[2])
- Gitlab.config.gitlab.relative_url_root + "/#{path}/#{@filename}"
+ File.join(Gitlab.config.gitlab.relative_url_root, @project.path_with_namespace, "uploads", @secret, file.filename)
+ end
+
+ def file_storage?
+ self.class.storage == CarrierWave::Storage::File
end
def image?