diff options
author | Chocobozzz <me@florianbigard.com> | 2021-12-09 11:48:29 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-12-13 16:03:16 +0100 |
commit | b5e1cd9a3088884e080765e98621faf5ee34d852 (patch) | |
tree | d266d992d3d1dbc6f72382263205780932f63260 /server/lib/activitypub | |
parent | e81193b04b5d146345c560abff642c125111de7b (diff) | |
download | PeerTube-b5e1cd9a3088884e080765e98621faf5ee34d852.tar.gz PeerTube-b5e1cd9a3088884e080765e98621faf5ee34d852.tar.zst PeerTube-b5e1cd9a3088884e080765e98621faf5ee34d852.zip |
Handle channel owner update of remote server
Diffstat (limited to 'server/lib/activitypub')
-rw-r--r-- | server/lib/activitypub/actors/get.ts | 37 | ||||
-rw-r--r-- | server/lib/activitypub/actors/updater.ts | 10 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-create.ts | 2 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-update.ts | 2 |
4 files changed, 30 insertions, 21 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 | ||
71 | function 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 | ||
73 | export { | 91 | export { |
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 | ||
91 | function 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 | |||
109 | async function scheduleOutboxFetchIfNeeded (actor: MActor, created: boolean, refreshed: boolean, updateCollections: boolean) { | 110 | async 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' } |
diff --git a/server/lib/activitypub/actors/updater.ts b/server/lib/activitypub/actors/updater.ts index de5e03eee..042438d9c 100644 --- a/server/lib/activitypub/actors/updater.ts +++ b/server/lib/activitypub/actors/updater.ts | |||
@@ -1,8 +1,10 @@ | |||
1 | import { resetSequelizeInstance, runInReadCommittedTransaction } from '@server/helpers/database-utils' | 1 | import { resetSequelizeInstance, runInReadCommittedTransaction } from '@server/helpers/database-utils' |
2 | import { logger } from '@server/helpers/logger' | 2 | import { logger } from '@server/helpers/logger' |
3 | import { AccountModel } from '@server/models/account/account' | ||
3 | import { VideoChannelModel } from '@server/models/video/video-channel' | 4 | import { VideoChannelModel } from '@server/models/video/video-channel' |
4 | import { MAccount, MActor, MActorFull, MChannel } from '@server/types/models' | 5 | import { MAccount, MActor, MActorFull, MChannel } from '@server/types/models' |
5 | import { ActivityPubActor, ActorImageType } from '@shared/models' | 6 | import { ActivityPubActor, ActorImageType } from '@shared/models' |
7 | import { getOrCreateAPOwner } from './get' | ||
6 | import { updateActorImageInstance } from './image' | 8 | import { updateActorImageInstance } from './image' |
7 | import { fetchActorFollowsCount } from './shared' | 9 | import { fetchActorFollowsCount } from './shared' |
8 | import { getImageInfoFromObject } from './shared/object-to-model-attributes' | 10 | import { getImageInfoFromObject } from './shared/object-to-model-attributes' |
@@ -36,7 +38,13 @@ export class APActorUpdater { | |||
36 | this.accountOrChannel.name = this.actorObject.name || this.actorObject.preferredUsername | 38 | this.accountOrChannel.name = this.actorObject.name || this.actorObject.preferredUsername |
37 | this.accountOrChannel.description = this.actorObject.summary | 39 | this.accountOrChannel.description = this.actorObject.summary |
38 | 40 | ||
39 | if (this.accountOrChannel instanceof VideoChannelModel) this.accountOrChannel.support = this.actorObject.support | 41 | if (this.accountOrChannel instanceof VideoChannelModel) { |
42 | const owner = await getOrCreateAPOwner(this.actorObject, this.actorObject.url) | ||
43 | this.accountOrChannel.accountId = owner.Account.id | ||
44 | this.accountOrChannel.Account = owner.Account as AccountModel | ||
45 | |||
46 | this.accountOrChannel.support = this.actorObject.support | ||
47 | } | ||
40 | 48 | ||
41 | await runInReadCommittedTransaction(async t => { | 49 | await runInReadCommittedTransaction(async t => { |
42 | await updateActorImageInstance(this.actor, ActorImageType.AVATAR, avatarInfo, t) | 50 | await updateActorImageInstance(this.actor, ActorImageType.AVATAR, avatarInfo, t) |
diff --git a/server/lib/activitypub/send/send-create.ts b/server/lib/activitypub/send/send-create.ts index baded642a..f46317163 100644 --- a/server/lib/activitypub/send/send-create.ts +++ b/server/lib/activitypub/send/send-create.ts | |||
@@ -116,7 +116,7 @@ function buildCreateActivity (url: string, byActor: MActorLight, object: any, au | |||
116 | type: 'Create' as 'Create', | 116 | type: 'Create' as 'Create', |
117 | id: url + '/activity', | 117 | id: url + '/activity', |
118 | actor: byActor.url, | 118 | actor: byActor.url, |
119 | object: audiencify(object, audience) | 119 | object |
120 | }, | 120 | }, |
121 | audience | 121 | audience |
122 | ) | 122 | ) |
diff --git a/server/lib/activitypub/send/send-update.ts b/server/lib/activitypub/send/send-update.ts index bcf6e1569..3c65e19ed 100644 --- a/server/lib/activitypub/send/send-update.ts +++ b/server/lib/activitypub/send/send-update.ts | |||
@@ -134,7 +134,7 @@ function buildUpdateActivity (url: string, byActor: MActorLight, object: any, au | |||
134 | type: 'Update' as 'Update', | 134 | type: 'Update' as 'Update', |
135 | id: url, | 135 | id: url, |
136 | actor: byActor.url, | 136 | actor: byActor.url, |
137 | object: audiencify(object, audience) | 137 | object |
138 | }, | 138 | }, |
139 | audience | 139 | audience |
140 | ) | 140 | ) |