X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Factivitypub%2Fprocess%2Fprocess-create.ts;h=df05ee452d318a6be78a0deb04946a00f2f796de;hb=2a8c5d0af13f3ccb9a505e1fbc9d324b9d33ba1f;hp=559a0c23c8fd4623a423ab9c9d3574fae161821b;hpb=d4defe07d26013a75577b30608841fe3f8334308;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/activitypub/process/process-create.ts b/server/lib/activitypub/process/process-create.ts index 559a0c23c..df05ee452 100644 --- a/server/lib/activitypub/process/process-create.ts +++ b/server/lib/activitypub/process/process-create.ts @@ -7,30 +7,29 @@ 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' +import { createOrUpdateCacheFile } from '../cache-file' +import { getVideoDislikeActivityPubUrl } from '../url' -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 }) @@ -67,9 +66,10 @@ async function processCreateDislike (byActor: ActorModel, activity: ActivityCrea videoId: video.id, accountId: byAccount.id } + const [ , created ] = await AccountVideoRateModel.findOrCreate({ where: rate, - defaults: rate, + defaults: Object.assign({}, rate, { url: getVideoDislikeActivityPubUrl(byActor, video) }), transaction: t }) if (created === true) await video.increment('dislikes', { transaction: t }) @@ -92,15 +92,12 @@ async function processCreateView (byActor: ActorModel, activity: ActivityCreate) } const { video } = await getOrCreateVideoAndAccountAndChannel(options) - const actorExists = await ActorModel.isActorUrlExist(view.actor) - if (actorExists === false) throw new Error('Unknown actor ' + view.actor) - 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) } } @@ -109,20 +106,22 @@ async function processCacheFile (byActor: ActorModel, activity: ActivityCreate) const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: cacheFile.object }) - await createCacheFile(cacheFile, video, byActor) + await sequelizeTypescript.transaction(async t => { + return createOrUpdateCacheFile(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({ videoObject: videoAbuseToCreateData.object })