diff options
author | Chocobozzz <me@florianbigard.com> | 2021-02-26 11:50:18 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-02-26 11:50:18 +0100 |
commit | 92315d979c3f424d81f8fca3c8831d81e4e2a6d6 (patch) | |
tree | fab1a460dba5efc217a5be91e0ed7303cd5d3633 /server/lib/activitypub | |
parent | 23ac334389a6b11ba0656a18ff760fb45f7bec57 (diff) | |
download | PeerTube-92315d979c3f424d81f8fca3c8831d81e4e2a6d6.tar.gz PeerTube-92315d979c3f424d81f8fca3c8831d81e4e2a6d6.tar.zst PeerTube-92315d979c3f424d81f8fca3c8831d81e4e2a6d6.zip |
More robust channel change federation
Diffstat (limited to 'server/lib/activitypub')
-rw-r--r-- | server/lib/activitypub/process/process-update.ts | 10 | ||||
-rw-r--r-- | server/lib/activitypub/videos.ts | 13 |
2 files changed, 18 insertions, 5 deletions
diff --git a/server/lib/activitypub/process/process-update.ts b/server/lib/activitypub/process/process-update.ts index 6d2fff3fe..849f70b94 100644 --- a/server/lib/activitypub/process/process-update.ts +++ b/server/lib/activitypub/process/process-update.ts | |||
@@ -62,7 +62,15 @@ async function processUpdateVideo (actor: MActorSignature, activity: ActivityUpd | |||
62 | return undefined | 62 | return undefined |
63 | } | 63 | } |
64 | 64 | ||
65 | const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: videoObject.id, allowRefresh: false, fetchType: 'all' }) | 65 | const { video, created } = await getOrCreateVideoAndAccountAndChannel({ |
66 | videoObject: videoObject.id, | ||
67 | allowRefresh: false, | ||
68 | fetchType: 'all' | ||
69 | }) | ||
70 | // We did not have this video, it has been created so no need to update | ||
71 | if (created) return | ||
72 | |||
73 | // Load new channel | ||
66 | const channelActor = await getOrCreateVideoChannelFromVideoObject(videoObject) | 74 | const channelActor = await getOrCreateVideoChannelFromVideoObject(videoObject) |
67 | 75 | ||
68 | const account = actor.Account as MAccountIdActor | 76 | const account = actor.Account as MAccountIdActor |
diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts index c38edad56..c29bcc528 100644 --- a/server/lib/activitypub/videos.ts +++ b/server/lib/activitypub/videos.ts | |||
@@ -336,10 +336,15 @@ async function updateVideoFromAP (options: { | |||
336 | 336 | ||
337 | videoFieldsSave = video.toJSON() | 337 | videoFieldsSave = video.toJSON() |
338 | 338 | ||
339 | // Check actor has the right to update the video | 339 | // Check we can update the channel: we trust the remote server |
340 | const videoChannel = video.VideoChannel | 340 | const oldVideoChannel = video.VideoChannel |
341 | if (videoChannel.Account.id !== account.id) { | 341 | |
342 | throw new Error('Account ' + account.Actor.url + ' does not own video channel ' + videoChannel.Actor.url) | 342 | if (!oldVideoChannel.Actor.serverId || !channel.Actor.serverId) { |
343 | throw new Error('Cannot check old channel/new channel validity because `serverId` is null') | ||
344 | } | ||
345 | |||
346 | if (oldVideoChannel.Actor.serverId !== channel.Actor.serverId) { | ||
347 | throw new Error('New channel ' + channel.Actor.url + ' is not on the same server than new channel ' + oldVideoChannel.Actor.url) | ||
343 | } | 348 | } |
344 | 349 | ||
345 | const to = overrideTo || videoObject.to | 350 | const to = overrideTo || videoObject.to |