about summary refs log tree commit diff
path: root/app/services/backup_service.rb
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2018-08-22 19:33:10 +0200
committerGitHub <noreply@github.com>2018-08-22 19:33:10 +0200
commit1b282299df67b0b9681e8d396fbe98f687ff9bba (patch)
tree3370d749dc20e193c59c047af6c8c32aacbdb132 /app/services/backup_service.rb
parent4bdab203ac5ca06d757d08af8a2bc184c86e3bbe (diff)
Add favourites to archive takeout (#8351)
Remove experimental key export
Diffstat (limited to 'app/services/backup_service.rb')
-rw-r--r--app/services/backup_service.rb24
1 files changed, 21 insertions, 3 deletions
diff --git a/app/services/backup_service.rb b/app/services/backup_service.rb
index da7db6462..4cfa22ab8 100644
--- a/app/services/backup_service.rb
+++ b/app/services/backup_service.rb
@@ -44,6 +44,7 @@ class BackupService < BaseService
         Gem::Package::TarWriter.new(gz) do |tar|
           dump_media_attachments!(tar)
           dump_outbox!(tar)
+          dump_likes!(tar)
           dump_actor!(tar)
         end
       end
@@ -82,6 +83,8 @@ class BackupService < BaseService
 
     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[: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.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|
       io.write(json)
     end
+  end
+
+  def dump_likes!(tar)
+    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
 
-    tar.add_file_simple('key.pem', 0o444, account.private_key.bytesize) do |io|
-      io.write(account.private_key)
+      GC.start
+    end
+
+    json = Oj.dump(collection)
+
+    tar.add_file_simple('likes.json', 0o444, json.bytesize) do |io|
+      io.write(json)
     end
   end
 
   def collection_presenter
     ActivityPub::CollectionPresenter.new(
-      id: account_outbox_url(account),
+      id: 'outbox.json',
       type: :ordered,
       size: account.statuses_count,
       items: []