diff options
Diffstat (limited to 'server/lib/activitypub/process/process-update.ts')
-rw-r--r-- | server/lib/activitypub/process/process-update.ts | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/server/lib/activitypub/process/process-update.ts b/server/lib/activitypub/process/process-update.ts index ed3489ebf..e092a6729 100644 --- a/server/lib/activitypub/process/process-update.ts +++ b/server/lib/activitypub/process/process-update.ts | |||
@@ -12,6 +12,7 @@ import { sanitizeAndCheckVideoTorrentObject } from '../../../helpers/custom-vali | |||
12 | import { isCacheFileObjectValid } from '../../../helpers/custom-validators/activitypub/cache-file' | 12 | import { isCacheFileObjectValid } from '../../../helpers/custom-validators/activitypub/cache-file' |
13 | import { VideoRedundancyModel } from '../../../models/redundancy/video-redundancy' | 13 | import { VideoRedundancyModel } from '../../../models/redundancy/video-redundancy' |
14 | import { createCacheFile, updateCacheFile } from '../cache-file' | 14 | import { createCacheFile, updateCacheFile } from '../cache-file' |
15 | import { forwardVideoRelatedActivity } from '../send/utils' | ||
15 | 16 | ||
16 | async function processUpdateActivity (activity: ActivityUpdate, byActor: ActorModel) { | 17 | async function processUpdateActivity (activity: ActivityUpdate, byActor: ActorModel) { |
17 | const objectType = activity.object.type | 18 | const objectType = activity.object.type |
@@ -68,18 +69,29 @@ async function processUpdateVideo (actor: ActorModel, activity: ActivityUpdate) | |||
68 | async function processUpdateCacheFile (byActor: ActorModel, activity: ActivityUpdate) { | 69 | async function processUpdateCacheFile (byActor: ActorModel, activity: ActivityUpdate) { |
69 | const cacheFileObject = activity.object as CacheFileObject | 70 | const cacheFileObject = activity.object as CacheFileObject |
70 | 71 | ||
71 | if (!isCacheFileObjectValid(cacheFileObject) === false) { | 72 | if (!isCacheFileObjectValid(cacheFileObject)) { |
72 | logger.debug('Cahe file object sent by update is not valid.', { cacheFileObject }) | 73 | logger.debug('Cache file object sent by update is not valid.', { cacheFileObject }) |
73 | return undefined | 74 | return undefined |
74 | } | 75 | } |
75 | 76 | ||
76 | const redundancyModel = await VideoRedundancyModel.loadByUrl(cacheFileObject.id) | 77 | const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: cacheFileObject.object }) |
77 | if (!redundancyModel) { | 78 | |
78 | const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: cacheFileObject.id }) | 79 | await sequelizeTypescript.transaction(async t => { |
79 | return createCacheFile(cacheFileObject, video, byActor) | 80 | const redundancyModel = await VideoRedundancyModel.loadByUrl(cacheFileObject.id, t) |
80 | } | 81 | |
82 | if (!redundancyModel) { | ||
83 | await createCacheFile(cacheFileObject, video, byActor, t) | ||
84 | } else { | ||
85 | await updateCacheFile(cacheFileObject, redundancyModel, video, byActor, t) | ||
86 | } | ||
87 | }) | ||
88 | |||
89 | if (video.isOwned()) { | ||
90 | // Don't resend the activity to the sender | ||
91 | const exceptions = [ byActor ] | ||
81 | 92 | ||
82 | return updateCacheFile(cacheFileObject, redundancyModel, byActor) | 93 | await forwardVideoRelatedActivity(activity, undefined, exceptions, video) |
94 | } | ||
83 | } | 95 | } |
84 | 96 | ||
85 | async function processUpdateActor (actor: ActorModel, activity: ActivityUpdate) { | 97 | async function processUpdateActor (actor: ActorModel, activity: ActivityUpdate) { |