aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/actors/get.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-12-09 11:48:29 +0100
committerChocobozzz <me@florianbigard.com>2021-12-13 16:03:16 +0100
commitb5e1cd9a3088884e080765e98621faf5ee34d852 (patch)
treed266d992d3d1dbc6f72382263205780932f63260 /server/lib/activitypub/actors/get.ts
parente81193b04b5d146345c560abff642c125111de7b (diff)
downloadPeerTube-b5e1cd9a3088884e080765e98621faf5ee34d852.tar.gz
PeerTube-b5e1cd9a3088884e080765e98621faf5ee34d852.tar.zst
PeerTube-b5e1cd9a3088884e080765e98621faf5ee34d852.zip
Handle channel owner update of remote server
Diffstat (limited to 'server/lib/activitypub/actors/get.ts')
-rw-r--r--server/lib/activitypub/actors/get.ts37
1 files changed, 19 insertions, 18 deletions
diff --git a/server/lib/activitypub/actors/get.ts b/server/lib/activitypub/actors/get.ts
index 8681ea02a..4200ddb4d 100644
--- a/server/lib/activitypub/actors/get.ts
+++ b/server/lib/activitypub/actors/get.ts
@@ -68,9 +68,28 @@ async function getOrCreateAPActor (
68 return actorRefreshed 68 return actorRefreshed
69} 69}
70 70
71function getOrCreateAPOwner (actorObject: ActivityPubActor, actorUrl: string) {
72 const accountAttributedTo = actorObject.attributedTo.find(a => a.type === 'Person')
73 if (!accountAttributedTo) throw new Error('Cannot find account attributed to video channel ' + actorUrl)
74
75 if (checkUrlsSameHost(accountAttributedTo.id, actorUrl) !== true) {
76 throw new Error(`Account attributed to ${accountAttributedTo.id} does not have the same host than actor url ${actorUrl}`)
77 }
78
79 try {
80 // Don't recurse another time
81 const recurseIfNeeded = false
82 return getOrCreateAPActor(accountAttributedTo.id, 'all', recurseIfNeeded)
83 } catch (err) {
84 logger.error('Cannot get or create account attributed to video channel ' + actorUrl)
85 throw new Error(err)
86 }
87}
88
71// --------------------------------------------------------------------------- 89// ---------------------------------------------------------------------------
72 90
73export { 91export {
92 getOrCreateAPOwner,
74 getOrCreateAPActor 93 getOrCreateAPActor
75} 94}
76 95
@@ -88,24 +107,6 @@ async function loadActorFromDB (actorUrl: string, fetchType: ActorLoadByUrlType)
88 return actor 107 return actor
89} 108}
90 109
91function getOrCreateAPOwner (actorObject: ActivityPubActor, actorUrl: string) {
92 const accountAttributedTo = actorObject.attributedTo.find(a => a.type === 'Person')
93 if (!accountAttributedTo) throw new Error('Cannot find account attributed to video channel ' + actorUrl)
94
95 if (checkUrlsSameHost(accountAttributedTo.id, actorUrl) !== true) {
96 throw new Error(`Account attributed to ${accountAttributedTo.id} does not have the same host than actor url ${actorUrl}`)
97 }
98
99 try {
100 // Don't recurse another time
101 const recurseIfNeeded = false
102 return getOrCreateAPActor(accountAttributedTo.id, 'all', recurseIfNeeded)
103 } catch (err) {
104 logger.error('Cannot get or create account attributed to video channel ' + actorUrl)
105 throw new Error(err)
106 }
107}
108
109async function scheduleOutboxFetchIfNeeded (actor: MActor, created: boolean, refreshed: boolean, updateCollections: boolean) { 110async function scheduleOutboxFetchIfNeeded (actor: MActor, created: boolean, refreshed: boolean, updateCollections: boolean) {
110 if ((created === true || refreshed === true) && updateCollections === true) { 111 if ((created === true || refreshed === true) && updateCollections === true) {
111 const payload = { uri: actor.outboxUrl, type: 'activity' as 'activity' } 112 const payload = { uri: actor.outboxUrl, type: 'activity' as 'activity' }