diff options
author | Chocobozzz <me@florianbigard.com> | 2018-05-11 15:10:13 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-05-11 15:25:51 +0200 |
commit | 0f320037e689b2778959c12ddd4ce790f6e4ae4f (patch) | |
tree | 425acaa4345442388901c833275bb76b42a8a268 /server/lib/activitypub/process | |
parent | 9675333decd0b89b73a4fc67b39272f7296bfe3f (diff) | |
download | PeerTube-0f320037e689b2778959c12ddd4ce790f6e4ae4f.tar.gz PeerTube-0f320037e689b2778959c12ddd4ce790f6e4ae4f.tar.zst PeerTube-0f320037e689b2778959c12ddd4ce790f6e4ae4f.zip |
Add ability to update a video channel
Diffstat (limited to 'server/lib/activitypub/process')
-rw-r--r-- | server/lib/activitypub/process/process-undo.ts | 25 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-update.ts | 10 |
2 files changed, 32 insertions, 3 deletions
diff --git a/server/lib/activitypub/process/process-undo.ts b/server/lib/activitypub/process/process-undo.ts index 565e70289..9b024d15f 100644 --- a/server/lib/activitypub/process/process-undo.ts +++ b/server/lib/activitypub/process/process-undo.ts | |||
@@ -1,4 +1,4 @@ | |||
1 | import { ActivityFollow, ActivityLike, ActivityUndo } from '../../../../shared/models/activitypub' | 1 | import { ActivityAnnounce, ActivityFollow, ActivityLike, ActivityUndo } from '../../../../shared/models/activitypub' |
2 | import { DislikeObject } from '../../../../shared/models/activitypub/objects' | 2 | import { DislikeObject } from '../../../../shared/models/activitypub/objects' |
3 | import { getActorUrl } from '../../../helpers/activitypub' | 3 | import { getActorUrl } from '../../../helpers/activitypub' |
4 | import { retryTransactionWrapper } from '../../../helpers/database-utils' | 4 | import { retryTransactionWrapper } from '../../../helpers/database-utils' |
@@ -10,6 +10,7 @@ import { ActorModel } from '../../../models/activitypub/actor' | |||
10 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' | 10 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' |
11 | import { forwardActivity } from '../send/misc' | 11 | import { forwardActivity } from '../send/misc' |
12 | import { getOrCreateAccountAndVideoAndChannel } from '../videos' | 12 | import { getOrCreateAccountAndVideoAndChannel } from '../videos' |
13 | import { VideoShareModel } from '../../../models/video/video-share' | ||
13 | 14 | ||
14 | async function processUndoActivity (activity: ActivityUndo) { | 15 | async function processUndoActivity (activity: ActivityUndo) { |
15 | const activityToUndo = activity.object | 16 | const activityToUndo = activity.object |
@@ -22,6 +23,8 @@ async function processUndoActivity (activity: ActivityUndo) { | |||
22 | return processUndoDislike(actorUrl, activity) | 23 | return processUndoDislike(actorUrl, activity) |
23 | } else if (activityToUndo.type === 'Follow') { | 24 | } else if (activityToUndo.type === 'Follow') { |
24 | return processUndoFollow(actorUrl, activityToUndo) | 25 | return processUndoFollow(actorUrl, activityToUndo) |
26 | } else if (activityToUndo.type === 'Announce') { | ||
27 | return processUndoAnnounce(actorUrl, activityToUndo) | ||
25 | } | 28 | } |
26 | 29 | ||
27 | logger.warn('Unknown activity object type %s -> %s when undo activity.', activityToUndo.type, { activity: activity.id }) | 30 | logger.warn('Unknown activity object type %s -> %s when undo activity.', activityToUndo.type, { activity: activity.id }) |
@@ -123,3 +126,23 @@ function undoFollow (actorUrl: string, followActivity: ActivityFollow) { | |||
123 | return undefined | 126 | return undefined |
124 | }) | 127 | }) |
125 | } | 128 | } |
129 | |||
130 | function processUndoAnnounce (actorUrl: string, announceActivity: ActivityAnnounce) { | ||
131 | const options = { | ||
132 | arguments: [ actorUrl, announceActivity ], | ||
133 | errorMessage: 'Cannot undo announce with many retries.' | ||
134 | } | ||
135 | |||
136 | return retryTransactionWrapper(undoAnnounce, options) | ||
137 | } | ||
138 | |||
139 | function undoAnnounce (actorUrl: string, announceActivity: ActivityAnnounce) { | ||
140 | return sequelizeTypescript.transaction(async t => { | ||
141 | const share = await VideoShareModel.loadByUrl(announceActivity.id, t) | ||
142 | if (!share) throw new Error(`'Unknown video share ${announceActivity.id}.`) | ||
143 | |||
144 | await share.destroy({ transaction: t }) | ||
145 | |||
146 | return undefined | ||
147 | }) | ||
148 | } | ||
diff --git a/server/lib/activitypub/process/process-update.ts b/server/lib/activitypub/process/process-update.ts index 51e3cc4e3..0dd657c2b 100644 --- a/server/lib/activitypub/process/process-update.ts +++ b/server/lib/activitypub/process/process-update.ts | |||
@@ -14,7 +14,7 @@ import { VideoFileModel } from '../../../models/video/video-file' | |||
14 | import { fetchAvatarIfExists, getOrCreateActorAndServerAndModel, updateActorAvatarInstance, updateActorInstance } from '../actor' | 14 | import { fetchAvatarIfExists, getOrCreateActorAndServerAndModel, updateActorAvatarInstance, updateActorInstance } from '../actor' |
15 | import { | 15 | import { |
16 | generateThumbnailFromUrl, | 16 | generateThumbnailFromUrl, |
17 | getOrCreateAccountAndVideoAndChannel, | 17 | getOrCreateAccountAndVideoAndChannel, getOrCreateVideoChannel, |
18 | videoActivityObjectToDBAttributes, | 18 | videoActivityObjectToDBAttributes, |
19 | videoFileActivityUrlToDBAttributes | 19 | videoFileActivityUrlToDBAttributes |
20 | } from '../videos' | 20 | } from '../videos' |
@@ -54,6 +54,10 @@ async function updateRemoteVideo (actor: ActorModel, activity: ActivityUpdate) { | |||
54 | 54 | ||
55 | const res = await getOrCreateAccountAndVideoAndChannel(videoAttributesToUpdate.id) | 55 | const res = await getOrCreateAccountAndVideoAndChannel(videoAttributesToUpdate.id) |
56 | 56 | ||
57 | // Fetch video channel outside the transaction | ||
58 | const newVideoChannelActor = await getOrCreateVideoChannel(videoAttributesToUpdate) | ||
59 | const newVideoChannel = newVideoChannelActor.VideoChannel | ||
60 | |||
57 | logger.debug('Updating remote video "%s".', videoAttributesToUpdate.uuid) | 61 | logger.debug('Updating remote video "%s".', videoAttributesToUpdate.uuid) |
58 | let videoInstance = res.video | 62 | let videoInstance = res.video |
59 | let videoFieldsSave: any | 63 | let videoFieldsSave: any |
@@ -66,12 +70,13 @@ async function updateRemoteVideo (actor: ActorModel, activity: ActivityUpdate) { | |||
66 | 70 | ||
67 | videoFieldsSave = videoInstance.toJSON() | 71 | videoFieldsSave = videoInstance.toJSON() |
68 | 72 | ||
73 | // Check actor has the right to update the video | ||
69 | const videoChannel = videoInstance.VideoChannel | 74 | const videoChannel = videoInstance.VideoChannel |
70 | if (videoChannel.Account.Actor.id !== actor.id) { | 75 | if (videoChannel.Account.Actor.id !== actor.id) { |
71 | throw new Error('Account ' + actor.url + ' does not own video channel ' + videoChannel.Actor.url) | 76 | throw new Error('Account ' + actor.url + ' does not own video channel ' + videoChannel.Actor.url) |
72 | } | 77 | } |
73 | 78 | ||
74 | const videoData = await videoActivityObjectToDBAttributes(videoChannel, videoAttributesToUpdate, activity.to) | 79 | const videoData = await videoActivityObjectToDBAttributes(newVideoChannel, videoAttributesToUpdate, activity.to) |
75 | videoInstance.set('name', videoData.name) | 80 | videoInstance.set('name', videoData.name) |
76 | videoInstance.set('uuid', videoData.uuid) | 81 | videoInstance.set('uuid', videoData.uuid) |
77 | videoInstance.set('url', videoData.url) | 82 | videoInstance.set('url', videoData.url) |
@@ -87,6 +92,7 @@ async function updateRemoteVideo (actor: ActorModel, activity: ActivityUpdate) { | |||
87 | videoInstance.set('updatedAt', videoData.updatedAt) | 92 | videoInstance.set('updatedAt', videoData.updatedAt) |
88 | videoInstance.set('views', videoData.views) | 93 | videoInstance.set('views', videoData.views) |
89 | videoInstance.set('privacy', videoData.privacy) | 94 | videoInstance.set('privacy', videoData.privacy) |
95 | videoInstance.set('channelId', videoData.channelId) | ||
90 | 96 | ||
91 | await videoInstance.save(sequelizeOptions) | 97 | await videoInstance.save(sequelizeOptions) |
92 | 98 | ||