|
1 | 1 | /*!
|
2 |
| - * Copyright (c) 2021 Interop Alliance and Dmitri Zagidulin. All rights reserved. |
| 2 | + * Copyright (c) 2024 Interop Alliance and Dmitri Zagidulin. All rights reserved. |
3 | 3 | */
|
4 |
| -export { Example } from './Example' |
| 4 | +import * as tar from 'tar-stream' |
| 5 | +import { type Pack } from 'tar-stream' |
| 6 | +import YAML from 'yaml' |
| 7 | + |
| 8 | +export type ActorProfileOptions = { |
| 9 | + actorProfile?: any |
| 10 | + outbox?: any |
| 11 | + followers?: any |
| 12 | + followingAccounts?: any |
| 13 | + lists?: any |
| 14 | + bookmarks?: any |
| 15 | + likes?: any |
| 16 | + blockedAccounts?: any |
| 17 | + blockedDomains?: any |
| 18 | + mutedAccounts?: any |
| 19 | +} |
| 20 | + |
| 21 | +export function exportActorProfile ({ |
| 22 | + actorProfile, outbox, followers, followingAccounts, lists, bookmarks, likes, |
| 23 | + blockedAccounts, blockedDomains, mutedAccounts |
| 24 | +}: ActorProfileOptions): tar.Pack { |
| 25 | + const pack: Pack = tar.pack() // pack is a stream |
| 26 | + |
| 27 | + const manifest: any = { |
| 28 | + // Universal Backup Container spec version |
| 29 | + 'ubc-version': '0.1', |
| 30 | + meta: { |
| 31 | + createdBy: { |
| 32 | + client: { |
| 33 | + // URL to the client that generated this export file |
| 34 | + url: 'https://github.com/interop-alliance/wallet-export-ts' |
| 35 | + } |
| 36 | + } |
| 37 | + }, |
| 38 | + contents: { |
| 39 | + 'manifest.yml': { |
| 40 | + url: 'https://w3id.org/fep/6fcd#manifest-file' |
| 41 | + }, |
| 42 | + // Directory with ActivityPub-relevant exports |
| 43 | + activitypub: { |
| 44 | + contents: {} |
| 45 | + } |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + pack.entry({ name: 'activitypub', type: 'directory' }) |
| 50 | + |
| 51 | + if (actorProfile) { |
| 52 | + // Serialized ActivityPub Actor profile |
| 53 | + manifest.contents.activitypub.contents['actor.json'] = { |
| 54 | + url: 'https://www.w3.org/TR/activitypub/#actor-objects' |
| 55 | + } |
| 56 | + pack.entry({ name: 'activitypub/actor.json' }, JSON.stringify(actorProfile, null, 2)) |
| 57 | + } |
| 58 | + |
| 59 | + if (outbox) { |
| 60 | + // ActivityStreams OrderedCollection representing the contents of the actor's Outbox |
| 61 | + manifest.contents.activitypub.contents['outbox.json'] = { |
| 62 | + url: 'https://www.w3.org/TR/activitystreams-core/#collections' |
| 63 | + } |
| 64 | + pack.entry({ name: 'activitypub/outbox.json' }, JSON.stringify(outbox, null, 2)) |
| 65 | + } |
| 66 | + |
| 67 | + if (followers) { |
| 68 | + // ActivityStreams OrderedCollection representing the actor's Followers |
| 69 | + manifest.contents.activitypub.contents['followers.json'] = { |
| 70 | + url: 'https://www.w3.org/TR/activitystreams-core/#collections' |
| 71 | + } |
| 72 | + pack.entry({ name: 'activitypub/followers.json' }, JSON.stringify(followers, null, 2)) |
| 73 | + } |
| 74 | + |
| 75 | + if (likes) { |
| 76 | + // ActivityStreams OrderedCollection representing Activities and Objects the actor liked |
| 77 | + manifest.contents.activitypub.contents['likes.json'] = { |
| 78 | + url: 'https://www.w3.org/TR/activitystreams-core/#collections' |
| 79 | + } |
| 80 | + pack.entry({ name: 'activitypub/likes.json' }, JSON.stringify(likes, null, 2)) |
| 81 | + } |
| 82 | + |
| 83 | + if (bookmarks) { |
| 84 | + // ActivityStreams OrderedCollection representing the actor's Bookmarks |
| 85 | + manifest.contents.activitypub.contents['bookmarks.json'] = { |
| 86 | + url: 'https://www.w3.org/TR/activitystreams-core/#collections' |
| 87 | + } |
| 88 | + pack.entry({ name: 'activitypub/bookmarks.json' }, JSON.stringify(bookmarks, null, 2)) |
| 89 | + } |
| 90 | + |
| 91 | + if (followingAccounts) { |
| 92 | + // CSV headers: |
| 93 | + // Account address, Show boosts, Notify on new posts, Languages |
| 94 | + manifest.contents.activitypub.contents['following_accounts.csv'] = { |
| 95 | + url: 'https://docs.joinmastodon.org/user/moving/#export' |
| 96 | + } |
| 97 | + pack.entry({ name: 'activitypub/following_accounts.csv' }, followingAccounts) |
| 98 | + } |
| 99 | + |
| 100 | + if (lists) { |
| 101 | + manifest.contents.activitypub.contents['lists.csv'] = { |
| 102 | + url: 'https://docs.joinmastodon.org/user/moving/#export' |
| 103 | + } |
| 104 | + pack.entry({ name: 'activitypub/lists.csv' }, lists) |
| 105 | + } |
| 106 | + |
| 107 | + if (blockedAccounts) { |
| 108 | + manifest.contents.activitypub.contents['blocked_accounts.csv'] = { |
| 109 | + url: 'https://docs.joinmastodon.org/user/moving/#export' |
| 110 | + } |
| 111 | + pack.entry({ name: 'activitypub/blocked_accounts.csv' }, blockedAccounts) |
| 112 | + } |
| 113 | + |
| 114 | + if (blockedDomains) { |
| 115 | + manifest.contents.activitypub.contents['blocked_domains.csv'] = { |
| 116 | + url: 'https://docs.joinmastodon.org/user/moving/#export' |
| 117 | + } |
| 118 | + pack.entry({ name: 'activitypub/blocked_domains.csv' }, blockedDomains) |
| 119 | + } |
| 120 | + |
| 121 | + if (mutedAccounts) { |
| 122 | + manifest.contents.activitypub.contents['muted_accounts.csv'] = { |
| 123 | + url: 'https://docs.joinmastodon.org/user/moving/#export' |
| 124 | + } |
| 125 | + pack.entry({ name: 'activitypub/muted_accounts.csv' }, mutedAccounts) |
| 126 | + } |
| 127 | + |
| 128 | + pack.entry({ name: 'manifest.yaml' }, YAML.stringify(manifest)) |
| 129 | + |
| 130 | + return pack |
| 131 | +} |
| 132 | + |
0 commit comments