Rename AvatarTransfer to FileTransfer

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