Add favourites to archive takeout (#8351)

Remove experimental key export
pull/665/head^2
Eugen Rochko 2018-08-22 19:33:10 +02:00 committed by GitHub
parent 4bdab203ac
commit 1b282299df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 3 deletions

View File

@ -44,6 +44,7 @@ class BackupService < BaseService
Gem::Package::TarWriter.new(gz) do |tar| Gem::Package::TarWriter.new(gz) do |tar|
dump_media_attachments!(tar) dump_media_attachments!(tar)
dump_outbox!(tar) dump_outbox!(tar)
dump_likes!(tar)
dump_actor!(tar) dump_actor!(tar)
end end
end end
@ -82,6 +83,8 @@ class BackupService < BaseService
actor[:icon][:url] = 'avatar' + File.extname(actor[:icon][:url]) if actor[:icon] actor[:icon][:url] = 'avatar' + File.extname(actor[:icon][:url]) if actor[:icon]
actor[:image][:url] = 'header' + File.extname(actor[:image][:url]) if actor[:image] actor[:image][:url] = 'header' + File.extname(actor[:image][:url]) if actor[:image]
actor[:outbox] = 'outbox.json'
actor[:likes] = 'likes.json'
download_to_tar(tar, account.avatar, 'avatar' + File.extname(account.avatar.path)) if account.avatar.exists? download_to_tar(tar, account.avatar, 'avatar' + File.extname(account.avatar.path)) if account.avatar.exists?
download_to_tar(tar, account.header, 'header' + File.extname(account.header.path)) if account.header.exists? download_to_tar(tar, account.header, 'header' + File.extname(account.header.path)) if account.header.exists?
@ -91,15 +94,30 @@ class BackupService < BaseService
tar.add_file_simple('actor.json', 0o444, json.bytesize) do |io| tar.add_file_simple('actor.json', 0o444, json.bytesize) do |io|
io.write(json) io.write(json)
end end
end
tar.add_file_simple('key.pem', 0o444, account.private_key.bytesize) do |io| def dump_likes!(tar)
io.write(account.private_key) collection = serialize(ActivityPub::CollectionPresenter.new(id: 'likes.json', type: :ordered, size: 0, items: []), ActivityPub::CollectionSerializer)
Status.reorder(nil).joins(:favourites).includes(:account).merge(account.favourites).find_in_batches do |statuses|
statuses.each do |status|
collection[:totalItems] += 1
collection[:orderedItems] << ActivityPub::TagManager.instance.uri_for(status)
end
GC.start
end
json = Oj.dump(collection)
tar.add_file_simple('likes.json', 0o444, json.bytesize) do |io|
io.write(json)
end end
end end
def collection_presenter def collection_presenter
ActivityPub::CollectionPresenter.new( ActivityPub::CollectionPresenter.new(
id: account_outbox_url(account), id: 'outbox.json',
type: :ordered, type: :ordered,
size: account.statuses_count, size: account.statuses_count,
items: [] items: []