X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Factivitypub%2Fprocess%2Fprocess-create.ts;h=c2160872f34bf2d12d6c6081dfb4d893671a3955;hb=cfaf819c38dc0de996c9844e5ef0ee364944d41f;hp=32e555acf6cb209f47529bf4754cf09610c33480;hpb=c48e82b5e0478434de30626d14594a97f2402e7c;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/activitypub/process/process-create.ts b/server/lib/activitypub/process/process-create.ts index 32e555acf..c2160872f 100644 --- a/server/lib/activitypub/process/process-create.ts +++ b/server/lib/activitypub/process/process-create.ts @@ -7,30 +7,28 @@ import { sequelizeTypescript } from '../../../initializers' import { AccountVideoRateModel } from '../../../models/account/account-video-rate' import { ActorModel } from '../../../models/activitypub/actor' import { VideoAbuseModel } from '../../../models/video/video-abuse' -import { getOrCreateActorAndServerAndModel } from '../actor' import { addVideoComment, resolveThread } from '../video-comments' import { getOrCreateVideoAndAccountAndChannel } from '../videos' -import { forwardActivity, forwardVideoRelatedActivity } from '../send/utils' +import { forwardVideoRelatedActivity } from '../send/utils' import { Redis } from '../../redis' import { createCacheFile } from '../cache-file' -async function processCreateActivity (activity: ActivityCreate) { +async function processCreateActivity (activity: ActivityCreate, byActor: ActorModel) { const activityObject = activity.object const activityType = activityObject.type - const actor = await getOrCreateActorAndServerAndModel(activity.actor) if (activityType === 'View') { - return processCreateView(actor, activity) + return processCreateView(byActor, activity) } else if (activityType === 'Dislike') { - return retryTransactionWrapper(processCreateDislike, actor, activity) + return retryTransactionWrapper(processCreateDislike, byActor, activity) } else if (activityType === 'Video') { return processCreateVideo(activity) } else if (activityType === 'Flag') { - return retryTransactionWrapper(processCreateVideoAbuse, actor, activityObject as VideoAbuseObject) + return retryTransactionWrapper(processCreateVideoAbuse, byActor, activityObject as VideoAbuseObject) } else if (activityType === 'Note') { - return retryTransactionWrapper(processCreateVideoComment, actor, activity) + return retryTransactionWrapper(processCreateVideoComment, byActor, activity) } else if (activityType === 'CacheFile') { - return retryTransactionWrapper(processCacheFile, actor, activity) + return retryTransactionWrapper(processCacheFile, byActor, activity) } logger.warn('Unknown activity object type %s when creating activity.', activityType, { activity: activity.id }) @@ -48,7 +46,7 @@ export { async function processCreateVideo (activity: ActivityCreate) { const videoToCreateData = activity.object as VideoTorrentObject - const { video } = await getOrCreateVideoAndAccountAndChannel(videoToCreateData) + const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: videoToCreateData }) return video } @@ -59,7 +57,7 @@ async function processCreateDislike (byActor: ActorModel, activity: ActivityCrea if (!byAccount) throw new Error('Cannot create dislike with the non account actor ' + byActor.url) - const { video } = await getOrCreateVideoAndAccountAndChannel(dislike.object) + const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: dislike.object }) return sequelizeTypescript.transaction(async t => { const rate = { @@ -86,41 +84,44 @@ async function processCreateDislike (byActor: ActorModel, activity: ActivityCrea async function processCreateView (byActor: ActorModel, activity: ActivityCreate) { const view = activity.object as ViewObject - const { video } = await getOrCreateVideoAndAccountAndChannel(view.object) - - const actor = await ActorModel.loadByUrl(view.actor) - if (!actor) throw new Error('Unknown actor ' + view.actor) + const options = { + videoObject: view.object, + fetchType: 'only-video' as 'only-video' + } + const { video } = await getOrCreateVideoAndAccountAndChannel(options) await Redis.Instance.addVideoView(video.id) if (video.isOwned()) { // Don't resend the activity to the sender const exceptions = [ byActor ] - await forwardActivity(activity, undefined, exceptions) + await forwardVideoRelatedActivity(activity, undefined, exceptions, video) } } async function processCacheFile (byActor: ActorModel, activity: ActivityCreate) { const cacheFile = activity.object as CacheFileObject - const { video } = await getOrCreateVideoAndAccountAndChannel(cacheFile.object) + const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: cacheFile.object }) - await createCacheFile(cacheFile, video, byActor) + await sequelizeTypescript.transaction(async t => { + return createCacheFile(cacheFile, video, byActor, t) + }) if (video.isOwned()) { // Don't resend the activity to the sender const exceptions = [ byActor ] - await forwardActivity(activity, undefined, exceptions) + await forwardVideoRelatedActivity(activity, undefined, exceptions, video) } } -async function processCreateVideoAbuse (actor: ActorModel, videoAbuseToCreateData: VideoAbuseObject) { +async function processCreateVideoAbuse (byActor: ActorModel, videoAbuseToCreateData: VideoAbuseObject) { logger.debug('Reporting remote abuse for video %s.', videoAbuseToCreateData.object) - const account = actor.Account - if (!account) throw new Error('Cannot create dislike with the non account actor ' + actor.url) + const account = byActor.Account + if (!account) throw new Error('Cannot create dislike with the non account actor ' + byActor.url) - const { video } = await getOrCreateVideoAndAccountAndChannel(videoAbuseToCreateData.object) + const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: videoAbuseToCreateData.object }) return sequelizeTypescript.transaction(async t => { const videoAbuseData = {