diff options
author | Douwe Maan <douwe@gitlab.com> | 2015-02-20 15:37:37 +0100 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2015-02-20 15:37:37 +0100 |
commit | 218283b368161130f43333e75629870c9649b319 (patch) | |
tree | c266f2c98aa3b199569a482fc0a651c484dd486f /app/uploaders | |
parent | 4ef6ffaad3e9b7a29b438722e5e101de78521ec7 (diff) | |
parent | 65b125a5035cb021aeb81e168fd4ae1ad6c74c11 (diff) | |
download | gitlab-ce-218283b368161130f43333e75629870c9649b319.tar.gz |
Merge branch 'extend_markdown_upload' into generic-uploads
# Conflicts:
# app/controllers/files_controller.rb
# app/controllers/projects/uploads_controller.rb
# app/uploaders/attachment_uploader.rb
Diffstat (limited to 'app/uploaders')
-rw-r--r-- | app/uploaders/file_uploader.rb | 43 |
1 files changed, 23 insertions, 20 deletions
diff --git a/app/uploaders/file_uploader.rb b/app/uploaders/file_uploader.rb index 0fa987c93f6..36a28f93c49 100644 --- a/app/uploaders/file_uploader.rb +++ b/app/uploaders/file_uploader.rb @@ -2,40 +2,43 @@ 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 + attr_accessor :project, :secret + + def initialize(project, secret = self.class.generate_secret) + @project = project + @secret = secret end def base_dir - @base_dir + "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) - end - - def extension_white_list - @allowed_extensions + File.join(base_dir, 'tmp', @project.path_with_namespace, @secret) end - def store!(file) - @filename = self.class.generate_filename(file) - super + def self.generate_secret + SecureRandom.hex 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 + def file_storage? + self.class.storage == CarrierWave::Storage::File end - def self.generate_dir - SecureRandom.hex(5) + def image? + img_ext = %w(png jpg jpeg gif bmp tiff) + if file.respond_to?(:extension) + img_ext.include?(file.extension.downcase) + else + # Not all CarrierWave storages respond to :extension + ext = file.path.split('.').last.downcase + img_ext.include?(ext) + end + rescue + false end end |