Rename AvatarTransfer to FileTransfer

parent 053ff3ba
......@@ -18,7 +18,7 @@ module Geo
begin
uploader_class.new(object_db_id, data).execute
rescue NameError
log("unknown file type: #{object_type}")
log("Unknown file type: #{object_type}")
{}
end
end
......
......@@ -5,7 +5,7 @@ module Gitlab
upload = Upload.find_by_id(object_db_id)
return unless upload.present?
transfer = ::Gitlab::Geo::AvatarTransfer.new(upload)
transfer = ::Gitlab::Geo::FileTransfer.new(:avatar, upload)
transfer.download_from_primary
end
end
......
......@@ -2,7 +2,7 @@ module Gitlab
module Geo
class AvatarUploader < FileUploader
def execute
upload = Upload.find(object_db_id)
upload = Upload.find_by_id(object_db_id)
return error unless upload.present?
return error unless valid?(upload)
......
module Gitlab
module Geo
class AvatarTransfer < Transfer
def initialize(upload)
@file_type = :avatar
class FileTransfer < Transfer
def initialize(file_type, upload)
@file_type = file_type
@file_id = upload.id
@filename = upload.path
@request_data = build_request_data(upload)
......
......@@ -12,6 +12,8 @@ module Gitlab
raise NotImplementedError
end
private
def success(file)
{ code: :ok, message: 'Success', file: file }
end
......
......@@ -7,7 +7,7 @@ describe Gitlab::Geo::AvatarDownloader do
context '#download_from_primary' do
it 'downlods the avatar' do
allow_any_instance_of(Gitlab::Geo::AvatarTransfer)
allow_any_instance_of(Gitlab::Geo::FileTransfer)
.to receive(:download_from_primary).and_return(100)
downloader = described_class.new(upload.id)
......
......@@ -125,7 +125,7 @@ describe API::Geo, api: true do
let!(:secondary_node) { create(:geo_node) }
let(:user) { create(:user, avatar: fixture_file_upload(Rails.root + 'spec/fixtures/dk.png', 'image/png')) }
let(:upload) { Upload.find_by(model: user, uploader: 'AvatarUploader') }
let(:transfer) { Gitlab::Geo::AvatarTransfer.new(upload) }
let(:transfer) { Gitlab::Geo::FileTransfer.new(upload) }
let(:req_header) { Gitlab::Geo::TransferRequest.new(transfer.request_data).headers }
before do
......
......@@ -18,7 +18,7 @@ describe Geo::FileDownloadService, services: true do
it 'downloads an user avatar' do
allow_any_instance_of(Gitlab::ExclusiveLease)
.to receive(:try_obtain).and_return(true)
allow_any_instance_of(Gitlab::Geo::AvatarTransfer)
allow_any_instance_of(Gitlab::Geo::FileTransfer)
.to receive(:download_from_primary).and_return(100)
expect{ subject.execute }.to change { Geo::FileRegistry.count }.by(1)
......@@ -34,7 +34,7 @@ describe Geo::FileDownloadService, services: true do
it 'downloads a group avatar' do
allow_any_instance_of(Gitlab::ExclusiveLease)
.to receive(:try_obtain).and_return(true)
allow_any_instance_of(Gitlab::Geo::AvatarTransfer)
allow_any_instance_of(Gitlab::Geo::FileTransfer)
.to receive(:download_from_primary).and_return(100)
expect{ subject.execute }.to change { Geo::FileRegistry.count }.by(1)
......@@ -50,7 +50,7 @@ describe Geo::FileDownloadService, services: true do
it 'downloads a project avatar' do
allow_any_instance_of(Gitlab::ExclusiveLease)
.to receive(:try_obtain).and_return(true)
allow_any_instance_of(Gitlab::Geo::AvatarTransfer)
allow_any_instance_of(Gitlab::Geo::FileTransfer)
.to receive(:download_from_primary).and_return(100)
expect{ subject.execute }.to change { Geo::FileRegistry.count }.by(1)
......
......@@ -8,8 +8,8 @@ describe Geo::FileUploadService, services: true do
let(:user) { create(:user, avatar: fixture_file_upload(Rails.root + 'spec/fixtures/dk.png', 'image/png')) }
let(:upload) { Upload.find_by(model: user, uploader: 'AvatarUploader') }
let(:params) { { id: upload.id, type: 'avatar' } }
let(:avatar_transfer) { Gitlab::Geo::AvatarTransfer.new(upload) }
let(:transfer_request) { Gitlab::Geo::TransferRequest.new(avatar_transfer.request_data) }
let(:file_transfer) { Gitlab::Geo::FileTransfer.new(:avatar, upload) }
let(:transfer_request) { Gitlab::Geo::TransferRequest.new(file_transfer.request_data) }
let(:req_header) { transfer_request.headers['Authorization'] }
it 'sends avatar file' do
......@@ -32,8 +32,8 @@ describe Geo::FileUploadService, services: true do
let(:group) { create(:group, avatar: fixture_file_upload(Rails.root + 'spec/fixtures/dk.png', 'image/png')) }
let(:upload) { Upload.find_by(model: group, uploader: 'AvatarUploader') }
let(:params) { { id: upload.id, type: 'avatar' } }
let(:avatar_transfer) { Gitlab::Geo::AvatarTransfer.new(upload) }
let(:transfer_request) { Gitlab::Geo::TransferRequest.new(avatar_transfer.request_data) }
let(:file_transfer) { Gitlab::Geo::FileTransfer.new(:avatar, upload) }
let(:transfer_request) { Gitlab::Geo::TransferRequest.new(file_transfer.request_data) }
let(:req_header) { transfer_request.headers['Authorization'] }
it 'sends avatar file' do
......@@ -56,8 +56,8 @@ describe Geo::FileUploadService, services: true do
let(:project) { create(:empty_project, avatar: fixture_file_upload(Rails.root + 'spec/fixtures/dk.png', 'image/png')) }
let(:upload) { Upload.find_by(model: project, uploader: 'AvatarUploader') }
let(:params) { { id: upload.id, type: 'avatar' } }
let(:avatar_transfer) { Gitlab::Geo::AvatarTransfer.new(upload) }
let(:transfer_request) { Gitlab::Geo::TransferRequest.new(avatar_transfer.request_data) }
let(:file_transfer) { Gitlab::Geo::FileTransfer.new(:avatar, upload) }
let(:transfer_request) { Gitlab::Geo::TransferRequest.new(file_transfer.request_data) }
let(:req_header) { transfer_request.headers['Authorization'] }
it 'sends avatar file' do
......
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