1
0
mirror of https://github.com/mastodon/mastodon synced 2024-11-27 14:28:24 +09:00

Add multiline user data export JSON files

This commit is contained in:
Edward Moulsdale 2024-09-28 19:21:08 +00:00 committed by Edward Moulsdale
parent 4c0e44ebbe
commit d336eff59e

View File

@ -21,11 +21,11 @@ class BackupService < BaseService
skeleton = serialize(collection_presenter, ActivityPub::CollectionSerializer) skeleton = serialize(collection_presenter, ActivityPub::CollectionSerializer)
skeleton[:@context] = full_context skeleton[:@context] = full_context
skeleton[:orderedItems] = ['!PLACEHOLDER!'] skeleton[:orderedItems] = ['!PLACEHOLDER!']
skeleton = Oj.dump(skeleton) skeleton = Oj.dump(skeleton, indent: 2)
prepend, append = skeleton.split('"!PLACEHOLDER!"') prepend, append = skeleton.split('"!PLACEHOLDER!"')
add_comma = false add_comma = false
file.write(prepend) file.write("#{prepend.rstrip}\n")
account.statuses.with_includes.reorder(nil).find_in_batches do |statuses| account.statuses.with_includes.reorder(nil).find_in_batches do |statuses|
file.write(',') if add_comma file.write(',') if add_comma
@ -41,8 +41,11 @@ class BackupService < BaseService
end end
end end
Oj.dump(item) json_str = Oj.dump(item, indent: 2)
end.join(',')) json_str.lines.map do |line|
" #{line.chomp}"
end.join("\n")
end.join(",\n"))
GC.start GC.start
end end
@ -104,7 +107,7 @@ class BackupService < BaseService
download_to_zip(zipfile, account.avatar, "avatar#{File.extname(account.avatar.path)}") if account.avatar.exists? download_to_zip(zipfile, account.avatar, "avatar#{File.extname(account.avatar.path)}") if account.avatar.exists?
download_to_zip(zipfile, account.header, "header#{File.extname(account.header.path)}") if account.header.exists? download_to_zip(zipfile, account.header, "header#{File.extname(account.header.path)}") if account.header.exists?
json = Oj.dump(actor) json = Oj.dump(actor, indent: 2)
zipfile.get_output_stream('actor.json') do |io| zipfile.get_output_stream('actor.json') do |io|
io.write(json) io.write(json)
@ -115,7 +118,7 @@ class BackupService < BaseService
skeleton = serialize(ActivityPub::CollectionPresenter.new(id: 'likes.json', type: :ordered, size: 0, items: []), ActivityPub::CollectionSerializer) skeleton = serialize(ActivityPub::CollectionPresenter.new(id: 'likes.json', type: :ordered, size: 0, items: []), ActivityPub::CollectionSerializer)
skeleton.delete(:totalItems) skeleton.delete(:totalItems)
skeleton[:orderedItems] = ['!PLACEHOLDER!'] skeleton[:orderedItems] = ['!PLACEHOLDER!']
skeleton = Oj.dump(skeleton) skeleton = Oj.dump(skeleton, indent: 2)
prepend, append = skeleton.split('"!PLACEHOLDER!"') prepend, append = skeleton.split('"!PLACEHOLDER!"')
zipfile.get_output_stream('likes.json') do |io| zipfile.get_output_stream('likes.json') do |io|
@ -129,7 +132,7 @@ class BackupService < BaseService
io.write(statuses.map do |status| io.write(statuses.map do |status|
Oj.dump(ActivityPub::TagManager.instance.uri_for(status)) Oj.dump(ActivityPub::TagManager.instance.uri_for(status))
end.join(',')) end.join(",\n "))
GC.start GC.start
end end
@ -142,7 +145,7 @@ class BackupService < BaseService
skeleton = serialize(ActivityPub::CollectionPresenter.new(id: 'bookmarks.json', type: :ordered, size: 0, items: []), ActivityPub::CollectionSerializer) skeleton = serialize(ActivityPub::CollectionPresenter.new(id: 'bookmarks.json', type: :ordered, size: 0, items: []), ActivityPub::CollectionSerializer)
skeleton.delete(:totalItems) skeleton.delete(:totalItems)
skeleton[:orderedItems] = ['!PLACEHOLDER!'] skeleton[:orderedItems] = ['!PLACEHOLDER!']
skeleton = Oj.dump(skeleton) skeleton = Oj.dump(skeleton, indent: 2)
prepend, append = skeleton.split('"!PLACEHOLDER!"') prepend, append = skeleton.split('"!PLACEHOLDER!"')
zipfile.get_output_stream('bookmarks.json') do |io| zipfile.get_output_stream('bookmarks.json') do |io|
@ -155,7 +158,7 @@ class BackupService < BaseService
io.write(statuses.map do |status| io.write(statuses.map do |status|
Oj.dump(ActivityPub::TagManager.instance.uri_for(status)) Oj.dump(ActivityPub::TagManager.instance.uri_for(status))
end.join(',')) end.join(",\n "))
GC.start GC.start
end end