X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Factivitypub%2Fprocess%2Fprocess-create.ts;h=df05ee452d318a6be78a0deb04946a00f2f796de;hb=2a8c5d0af13f3ccb9a505e1fbc9d324b9d33ba1f;hp=5197dac73455bef70c8d2cff984775c88404e713;hpb=e587e0ecee5bec43a225995948faaa4bc97f080a;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/activitypub/process/process-create.ts b/server/lib/activitypub/process/process-create.ts index 5197dac73..df05ee452 100644 --- a/server/lib/activitypub/process/process-create.ts +++ b/server/lib/activitypub/process/process-create.ts @@ -9,9 +9,10 @@ import { ActorModel } from '../../../models/activitypub/actor' import { VideoAbuseModel } from '../../../models/video/video-abuse' 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, byActor: ActorModel) { const activityObject = activity.object @@ -65,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 }) @@ -90,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) } } @@ -107,12 +106,14 @@ 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) } }