Commit 3c31de75 authored by James Lopez's avatar James Lopez

refactor uploads manager

parent 414939c9
No related merge requests found
class UploadService
def initialize(model, file, uploader_class = FileUploader)
@model, @file, @uploader_class = model, file, uploader_class
def initialize(model, file, uploader_class = FileUploader, **uploader_context)
@model, @file, @uploader_class, @uploader_context = model, file, uploader_class, uploader_context
end
def execute
return nil unless @file && @file.size <= max_attachment_size
uploader = @uploader_class.new(@model)
uploader = @uploader_class.new(@model, nil, @uploader_context)
uploader.store!(@file)
uploader.to_h
......
......@@ -29,10 +29,15 @@ module Gitlab
Dir["#{uploads_export_path}/**/*"].each do |upload|
next if File.directory?(upload)
UploadService.new(@project, File.open(upload, 'r'), FileUploader).execute
end
secret, identifier = upload.split('/').last(2)
true
uploader_context = {
secret: secret,
identifier: identifier
}
UploadService.new(@project, File.open(upload, 'r'), FileUploader, uploader_context).execute
end
rescue => e
@shared.error(e)
false
......
......@@ -48,7 +48,7 @@ describe Gitlab::ImportExport::UploadsManager do
stub_uploads_object_storage(FileUploader)
end
it 'downloads the file to include in an archive' do
it 'saves the file' do
fake_uri = double
expect(fake_uri).to receive(:open).and_return(StringIO.new('File content'))
......@@ -70,7 +70,7 @@ describe Gitlab::ImportExport::UploadsManager do
FileUtils.touch(File.join(shared.export_path, 'uploads/random', "dummy.txt"))
end
it 'downloads the file to include in an archive' do
it 'restores the file' do
manager.restore
expect(project.uploads.size).to eq(1)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment