Skip to content
Snippets Groups Projects
Commit aea57700 authored by Kamil Trzcińśki's avatar Kamil Trzcińśki
Browse files

WIP [ci skip]

Former-commit-id: f3eb2314
parent 2604e094
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -893,8 +893,8 @@ DEPENDENCIES
faraday (~> 0.11.0)
ffaker (~> 2.4)
flay (~> 2.8.0)
fog-aws (~> 0.9)
fog-core (~> 1.40)
fog-aws (~> 1.3.0)
fog-core (~> 1.42.0)
fog-google (~> 0.5)
fog-local (~> 0.3)
fog-openstack (~> 0.1)
Loading
Loading
Loading
Loading
@@ -31,10 +31,8 @@ class ArtifactUploader < GitlabUploader
 
if object_store_options.enabled
storage :fog
#cache_storage :fog
else
storage :file
#cache_storage :file
end
 
def initialize(job, field)
Loading
Loading
@@ -69,10 +67,6 @@ class ArtifactUploader < GitlabUploader
}
end
 
def filename
file.try(:filename)
end
def exists?
file.try(:exists?)
end
Loading
Loading
@@ -84,25 +78,33 @@ class ArtifactUploader < GitlabUploader
def upload_authorize
result = { TempPath: ArtifactUploader.artifacts_upload_path }
 
if use_object_store?
path = File.join('tmp', 'cache', 'upload', SecureRandom.hex)
use_cache_object_storage do
self.cache_id = CarrierWave.generate_cache_id
self.original_filename = SecureRandom.hex
expire_at = ::Fog::Time.now + fog_authenticated_url_expiration
result[:UploadPath] = path
result[:UploadPath] = cache_name
result[:UploadURL] = storage.connection.put_object_url(
fog_directory, path, expire_at)
fog_directory, cache_path, expire_at)
end
 
result
end
 
def retrive_uploaded!(path)
CarrierWave::Storage::Fog::File.new(self, storage, path)
end
def upload_cache_path(path = nil)
File.join(cache_dir, path)
end
 
def cache!(new_file = nil)
use_cache_object_storage do
retrieve_from_cache!(new_file.upload_path)
@filename = new_file.original_filename
store_path
return
end if new_file&.upload_path
super
end
private
 
def object_store_options
Loading
Loading
@@ -112,4 +114,29 @@ class ArtifactUploader < GitlabUploader
def use_object_store?
object_store_options.enabled
end
def cache_storage
if @use_storage_for_cache
storage
else
super
end
end
def use_cache_object_storage
return unless use_object_store?
@use_storage_for_cache = true
yield
ensure
@use_storage_for_cache = false
end
def move_to_store
storage.is_a?(CarrierWave::Storage::File)
end
def move_to_cache
cache_storage.is_a?(CarrierWave::Storage::File)
end
end
Loading
Loading
@@ -298,17 +298,11 @@ module API
file_path = File.realpath(params["#{field}.path"])
bad_request!('Bad file path') unless file_path.start_with?(uploads_path)
 
# if file was uploaded, retrieve the cached filed
if params["#{field}.upload_path"]
file = uploader.retrive_uploaded!(params["#{field}.upload_path"])
return file
end
UploadedFile.new(
file_path,
params["#{field}.name"],
params["#{field}.type"] || 'application/octet-stream',
params["#{field}.upload_path"]
)
end
 
Loading
Loading
Loading
Loading
@@ -9,15 +9,19 @@ class UploadedFile
# The tempfile
attr_reader :tempfile
 
# The upload_path for asynchronous uploads
attr_reader :upload_path
# The content type of the "uploaded" file
attr_accessor :content_type
 
def initialize(path, filename, content_type = "text/plain")
def initialize(path, filename, content_type = "text/plain", upload_path = nil)
raise "#{path} file does not exist" unless ::File.exist?(path)
 
@content_type = content_type
@original_filename = filename || ::File.basename(path)
@tempfile = File.new(path, 'rb')
@upload_path = upload_path
end
 
def path
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment