Send new remote_photo_path in migration message
This commit is contained in:
parent
34528521f2
commit
e9f7bf382e
4 changed files with 43 additions and 5 deletions
|
|
@ -10,7 +10,7 @@ class ImportService
|
|||
def import_by_files(path_to_profile, path_to_photos, username, opts={})
|
||||
if path_to_profile.present?
|
||||
logger.info "Import for profile #{username} at path #{path_to_profile} requested"
|
||||
import_user_profile(path_to_profile, username, opts)
|
||||
import_user_profile(path_to_profile, username, opts.merge(photo_migration: path_to_photos.present?))
|
||||
end
|
||||
|
||||
user = User.find_by(username: username)
|
||||
|
|
|
|||
|
|
@ -60,7 +60,8 @@ class MigrationService
|
|||
new_person: archive_importer.user.person,
|
||||
old_private_key: archive_importer.serialized_private_key,
|
||||
old_person_diaspora_id: archive_importer.archive_author_diaspora_id,
|
||||
archive_contacts: archive_importer.contacts
|
||||
archive_contacts: archive_importer.contacts,
|
||||
remote_photo_path: remote_photo_path
|
||||
)
|
||||
end
|
||||
|
||||
|
|
@ -131,6 +132,16 @@ class MigrationService
|
|||
File.delete(@intermediate_file)
|
||||
end
|
||||
|
||||
def remote_photo_path
|
||||
return unless opts.fetch(:photo_migration, false)
|
||||
|
||||
if AppConfig.environment.s3.enable?
|
||||
return "https://#{AppConfig.environment.s3.bucket.get}.s3.amazonaws.com/uploads/images/"
|
||||
end
|
||||
|
||||
"#{AppConfig.pod_uri}uploads/images/"
|
||||
end
|
||||
|
||||
class ArchiveValidationFailed < RuntimeError
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -26,9 +26,10 @@ module Diaspora
|
|||
|
||||
def self.account_migration(account_migration)
|
||||
DiasporaFederation::Entities::AccountMigration.new(
|
||||
author: account_migration.sender.diaspora_handle,
|
||||
profile: profile(account_migration.new_person.profile),
|
||||
signature: account_migration.signature
|
||||
author: account_migration.sender.diaspora_handle,
|
||||
profile: profile(account_migration.new_person.profile),
|
||||
remote_photo_path: account_migration.remote_photo_path,
|
||||
signature: account_migration.signature
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -312,6 +312,32 @@ describe MigrationService do
|
|||
end
|
||||
end
|
||||
|
||||
context "photo migration" do
|
||||
it "doesn't include a new remote_photo_path" do
|
||||
service = MigrationService.new(archive_file.path, new_username)
|
||||
service.send(:find_or_create_user)
|
||||
account_migration = service.send(:account_migration)
|
||||
expect(account_migration.remote_photo_path).to be_nil
|
||||
end
|
||||
|
||||
it "includes url to new pod image upload folder in remote_photo_path" do
|
||||
service = MigrationService.new(archive_file.path, new_username, photo_migration: true)
|
||||
service.send(:find_or_create_user)
|
||||
account_migration = service.send(:account_migration)
|
||||
expect(account_migration.remote_photo_path).to eq("#{AppConfig.pod_uri}uploads/images/")
|
||||
end
|
||||
|
||||
it "includes url to S3 image upload folder in remote_photo_path when S3 is enabled" do
|
||||
AppConfig.environment.s3.enable = true
|
||||
AppConfig.environment.s3.bucket = "test-bucket"
|
||||
|
||||
service = MigrationService.new(archive_file.path, new_username, photo_migration: true)
|
||||
service.send(:find_or_create_user)
|
||||
account_migration = service.send(:account_migration)
|
||||
expect(account_migration.remote_photo_path).to eq("https://test-bucket.s3.amazonaws.com/uploads/images/")
|
||||
end
|
||||
end
|
||||
|
||||
context "compressed archives" do
|
||||
it "uncompresses gz archive" do
|
||||
gz_compressed_file = create_gz_archive
|
||||
|
|
|
|||
Loading…
Reference in a new issue