aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/process/process-update.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/activitypub/process/process-update.ts')
-rw-r--r--server/lib/activitypub/process/process-update.ts34
1 files changed, 30 insertions, 4 deletions
diff --git a/server/lib/activitypub/process/process-update.ts b/server/lib/activitypub/process/process-update.ts
index d2ad738a2..d3af1a181 100644
--- a/server/lib/activitypub/process/process-update.ts
+++ b/server/lib/activitypub/process/process-update.ts
@@ -1,4 +1,4 @@
1import { ActivityUpdate, VideoTorrentObject } from '../../../../shared/models/activitypub' 1import { ActivityUpdate, CacheFileObject, VideoTorrentObject } from '../../../../shared/models/activitypub'
2import { ActivityPubActor } from '../../../../shared/models/activitypub/activitypub-actor' 2import { ActivityPubActor } from '../../../../shared/models/activitypub/activitypub-actor'
3import { resetSequelizeInstance, retryTransactionWrapper } from '../../../helpers/database-utils' 3import { resetSequelizeInstance, retryTransactionWrapper } from '../../../helpers/database-utils'
4import { logger } from '../../../helpers/logger' 4import { logger } from '../../../helpers/logger'
@@ -7,8 +7,11 @@ import { AccountModel } from '../../../models/account/account'
7import { ActorModel } from '../../../models/activitypub/actor' 7import { ActorModel } from '../../../models/activitypub/actor'
8import { VideoChannelModel } from '../../../models/video/video-channel' 8import { VideoChannelModel } from '../../../models/video/video-channel'
9import { fetchAvatarIfExists, getOrCreateActorAndServerAndModel, updateActorAvatarInstance, updateActorInstance } from '../actor' 9import { fetchAvatarIfExists, getOrCreateActorAndServerAndModel, updateActorAvatarInstance, updateActorInstance } from '../actor'
10import { getOrCreateVideoAndAccountAndChannel, getOrCreateVideoChannelFromVideoObject, updateVideoFromAP } from '../videos' 10import { getOrCreateVideoAndAccountAndChannel, updateVideoFromAP, getOrCreateVideoChannelFromVideoObject } from '../videos'
11import { sanitizeAndCheckVideoTorrentObject } from '../../../helpers/custom-validators/activitypub/videos' 11import { sanitizeAndCheckVideoTorrentObject } from '../../../helpers/custom-validators/activitypub/videos'
12import { isCacheFileObjectValid } from '../../../helpers/custom-validators/activitypub/cache-file'
13import { VideoRedundancyModel } from '../../../models/redundancy/video-redundancy'
14import { createCacheFile, updateCacheFile } from '../cache-file'
12 15
13async function processUpdateActivity (activity: ActivityUpdate) { 16async function processUpdateActivity (activity: ActivityUpdate) {
14 const actor = await getOrCreateActorAndServerAndModel(activity.actor) 17 const actor = await getOrCreateActorAndServerAndModel(activity.actor)
@@ -16,10 +19,16 @@ async function processUpdateActivity (activity: ActivityUpdate) {
16 19
17 if (objectType === 'Video') { 20 if (objectType === 'Video') {
18 return retryTransactionWrapper(processUpdateVideo, actor, activity) 21 return retryTransactionWrapper(processUpdateVideo, actor, activity)
19 } else if (objectType === 'Person' || objectType === 'Application' || objectType === 'Group') { 22 }
23
24 if (objectType === 'Person' || objectType === 'Application' || objectType === 'Group') {
20 return retryTransactionWrapper(processUpdateActor, actor, activity) 25 return retryTransactionWrapper(processUpdateActor, actor, activity)
21 } 26 }
22 27
28 if (objectType === 'CacheFile') {
29 return retryTransactionWrapper(processUpdateCacheFile, actor, activity)
30 }
31
23 return undefined 32 return undefined
24} 33}
25 34
@@ -42,7 +51,24 @@ async function processUpdateVideo (actor: ActorModel, activity: ActivityUpdate)
42 const { video } = await getOrCreateVideoAndAccountAndChannel(videoObject.id) 51 const { video } = await getOrCreateVideoAndAccountAndChannel(videoObject.id)
43 const channelActor = await getOrCreateVideoChannelFromVideoObject(videoObject) 52 const channelActor = await getOrCreateVideoChannelFromVideoObject(videoObject)
44 53
45 return updateVideoFromAP(video, videoObject, actor, channelActor, activity.to) 54 return updateVideoFromAP(video, videoObject, actor.Account, channelActor.VideoChannel, activity.to)
55}
56
57async function processUpdateCacheFile (byActor: ActorModel, activity: ActivityUpdate) {
58 const cacheFileObject = activity.object as CacheFileObject
59
60 if (!isCacheFileObjectValid(cacheFileObject) === false) {
61 logger.debug('Cahe file object sent by update is not valid.', { cacheFileObject })
62 return undefined
63 }
64
65 const redundancyModel = await VideoRedundancyModel.loadByUrl(cacheFileObject.id)
66 if (!redundancyModel) {
67 const { video } = await getOrCreateVideoAndAccountAndChannel(cacheFileObject.id)
68 return createCacheFile(cacheFileObject, video, byActor)
69 }
70
71 return updateCacheFile(cacheFileObject, redundancyModel, byActor)
46} 72}
47 73
48async function processUpdateActor (actor: ActorModel, activity: ActivityUpdate) { 74async function processUpdateActor (actor: ActorModel, activity: ActivityUpdate) {