diff options
Diffstat (limited to 'server/lib/activitypub/process/process-update.ts')
-rw-r--r-- | server/lib/activitypub/process/process-update.ts | 34 |
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 @@ | |||
1 | import { ActivityUpdate, VideoTorrentObject } from '../../../../shared/models/activitypub' | 1 | import { ActivityUpdate, CacheFileObject, VideoTorrentObject } from '../../../../shared/models/activitypub' |
2 | import { ActivityPubActor } from '../../../../shared/models/activitypub/activitypub-actor' | 2 | import { ActivityPubActor } from '../../../../shared/models/activitypub/activitypub-actor' |
3 | import { resetSequelizeInstance, retryTransactionWrapper } from '../../../helpers/database-utils' | 3 | import { resetSequelizeInstance, retryTransactionWrapper } from '../../../helpers/database-utils' |
4 | import { logger } from '../../../helpers/logger' | 4 | import { logger } from '../../../helpers/logger' |
@@ -7,8 +7,11 @@ import { AccountModel } from '../../../models/account/account' | |||
7 | import { ActorModel } from '../../../models/activitypub/actor' | 7 | import { ActorModel } from '../../../models/activitypub/actor' |
8 | import { VideoChannelModel } from '../../../models/video/video-channel' | 8 | import { VideoChannelModel } from '../../../models/video/video-channel' |
9 | import { fetchAvatarIfExists, getOrCreateActorAndServerAndModel, updateActorAvatarInstance, updateActorInstance } from '../actor' | 9 | import { fetchAvatarIfExists, getOrCreateActorAndServerAndModel, updateActorAvatarInstance, updateActorInstance } from '../actor' |
10 | import { getOrCreateVideoAndAccountAndChannel, getOrCreateVideoChannelFromVideoObject, updateVideoFromAP } from '../videos' | 10 | import { getOrCreateVideoAndAccountAndChannel, updateVideoFromAP, getOrCreateVideoChannelFromVideoObject } from '../videos' |
11 | import { sanitizeAndCheckVideoTorrentObject } from '../../../helpers/custom-validators/activitypub/videos' | 11 | import { sanitizeAndCheckVideoTorrentObject } from '../../../helpers/custom-validators/activitypub/videos' |
12 | import { isCacheFileObjectValid } from '../../../helpers/custom-validators/activitypub/cache-file' | ||
13 | import { VideoRedundancyModel } from '../../../models/redundancy/video-redundancy' | ||
14 | import { createCacheFile, updateCacheFile } from '../cache-file' | ||
12 | 15 | ||
13 | async function processUpdateActivity (activity: ActivityUpdate) { | 16 | async 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 | |||
57 | async 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 | ||
48 | async function processUpdateActor (actor: ActorModel, activity: ActivityUpdate) { | 74 | async function processUpdateActor (actor: ActorModel, activity: ActivityUpdate) { |