diff options
Diffstat (limited to 'server/lib/activitypub/process/process-create.ts')
-rw-r--r-- | server/lib/activitypub/process/process-create.ts | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/server/lib/activitypub/process/process-create.ts b/server/lib/activitypub/process/process-create.ts index 16f426e23..32e555acf 100644 --- a/server/lib/activitypub/process/process-create.ts +++ b/server/lib/activitypub/process/process-create.ts | |||
@@ -1,4 +1,4 @@ | |||
1 | import { ActivityCreate, VideoAbuseState, VideoTorrentObject } from '../../../../shared' | 1 | import { ActivityCreate, CacheFileObject, VideoAbuseState, VideoTorrentObject } from '../../../../shared' |
2 | import { DislikeObject, VideoAbuseObject, ViewObject } from '../../../../shared/models/activitypub/objects' | 2 | import { DislikeObject, VideoAbuseObject, ViewObject } from '../../../../shared/models/activitypub/objects' |
3 | import { VideoCommentObject } from '../../../../shared/models/activitypub/objects/video-comment-object' | 3 | import { VideoCommentObject } from '../../../../shared/models/activitypub/objects/video-comment-object' |
4 | import { retryTransactionWrapper } from '../../../helpers/database-utils' | 4 | import { retryTransactionWrapper } from '../../../helpers/database-utils' |
@@ -12,6 +12,7 @@ import { addVideoComment, resolveThread } from '../video-comments' | |||
12 | import { getOrCreateVideoAndAccountAndChannel } from '../videos' | 12 | import { getOrCreateVideoAndAccountAndChannel } from '../videos' |
13 | import { forwardActivity, forwardVideoRelatedActivity } from '../send/utils' | 13 | import { forwardActivity, forwardVideoRelatedActivity } from '../send/utils' |
14 | import { Redis } from '../../redis' | 14 | import { Redis } from '../../redis' |
15 | import { createCacheFile } from '../cache-file' | ||
15 | 16 | ||
16 | async function processCreateActivity (activity: ActivityCreate) { | 17 | async function processCreateActivity (activity: ActivityCreate) { |
17 | const activityObject = activity.object | 18 | const activityObject = activity.object |
@@ -28,6 +29,8 @@ async function processCreateActivity (activity: ActivityCreate) { | |||
28 | return retryTransactionWrapper(processCreateVideoAbuse, actor, activityObject as VideoAbuseObject) | 29 | return retryTransactionWrapper(processCreateVideoAbuse, actor, activityObject as VideoAbuseObject) |
29 | } else if (activityType === 'Note') { | 30 | } else if (activityType === 'Note') { |
30 | return retryTransactionWrapper(processCreateVideoComment, actor, activity) | 31 | return retryTransactionWrapper(processCreateVideoComment, actor, activity) |
32 | } else if (activityType === 'CacheFile') { | ||
33 | return retryTransactionWrapper(processCacheFile, actor, activity) | ||
31 | } | 34 | } |
32 | 35 | ||
33 | logger.warn('Unknown activity object type %s when creating activity.', activityType, { activity: activity.id }) | 36 | logger.warn('Unknown activity object type %s when creating activity.', activityType, { activity: activity.id }) |
@@ -97,6 +100,20 @@ async function processCreateView (byActor: ActorModel, activity: ActivityCreate) | |||
97 | } | 100 | } |
98 | } | 101 | } |
99 | 102 | ||
103 | async function processCacheFile (byActor: ActorModel, activity: ActivityCreate) { | ||
104 | const cacheFile = activity.object as CacheFileObject | ||
105 | |||
106 | const { video } = await getOrCreateVideoAndAccountAndChannel(cacheFile.object) | ||
107 | |||
108 | await createCacheFile(cacheFile, video, byActor) | ||
109 | |||
110 | if (video.isOwned()) { | ||
111 | // Don't resend the activity to the sender | ||
112 | const exceptions = [ byActor ] | ||
113 | await forwardActivity(activity, undefined, exceptions) | ||
114 | } | ||
115 | } | ||
116 | |||
100 | async function processCreateVideoAbuse (actor: ActorModel, videoAbuseToCreateData: VideoAbuseObject) { | 117 | async function processCreateVideoAbuse (actor: ActorModel, videoAbuseToCreateData: VideoAbuseObject) { |
101 | logger.debug('Reporting remote abuse for video %s.', videoAbuseToCreateData.object) | 118 | logger.debug('Reporting remote abuse for video %s.', videoAbuseToCreateData.object) |
102 | 119 | ||
@@ -113,7 +130,7 @@ async function processCreateVideoAbuse (actor: ActorModel, videoAbuseToCreateDat | |||
113 | state: VideoAbuseState.PENDING | 130 | state: VideoAbuseState.PENDING |
114 | } | 131 | } |
115 | 132 | ||
116 | await VideoAbuseModel.create(videoAbuseData) | 133 | await VideoAbuseModel.create(videoAbuseData, { transaction: t }) |
117 | 134 | ||
118 | logger.info('Remote abuse for video uuid %s created', videoAbuseToCreateData.object) | 135 | logger.info('Remote abuse for video uuid %s created', videoAbuseToCreateData.object) |
119 | }) | 136 | }) |