gitlab-org--gitlab-foss/app/uploaders/file_uploader.rb

34 lines
606 B
Ruby
Raw Normal View History

# encoding: utf-8
class FileUploader < CarrierWave::Uploader::Base
include UploaderHelper
storage :file
attr_accessor :project, :secret
2015-02-16 13:58:40 -05:00
def initialize(project, secret = self.class.generate_secret)
@project = project
@secret = secret
end
def base_dir
"uploads"
end
def store_dir
2015-02-16 13:58:40 -05:00
File.join(base_dir, @project.path_with_namespace, @secret)
end
def cache_dir
2015-02-16 13:58:40 -05:00
File.join(base_dir, 'tmp', @project.path_with_namespace, @secret)
end
2015-02-16 13:58:40 -05:00
def self.generate_secret
2015-02-16 16:08:55 -05:00
SecureRandom.hex
end
2015-02-20 09:56:12 -05:00
def secure_url
File.join("/uploads", @secret, file.filename)
2015-02-20 09:56:12 -05:00
end
end