X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Factivitypub%2Fprocess%2Fprocess-undo.ts;h=7a0f90adfc3821d6fab4c364269fb986310f7fad;hb=1198edf4bb06ce5f1668b97cf9ca8fb483fe3f41;hp=ed0177a67f785a0c5a3c260ac79cd1211b5d8764;hpb=88108880bbdba473cfe36ecbebc1c3c4f972e102;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/activitypub/process/process-undo.ts b/server/lib/activitypub/process/process-undo.ts index ed0177a67..7a0f90adf 100644 --- a/server/lib/activitypub/process/process-undo.ts +++ b/server/lib/activitypub/process/process-undo.ts @@ -10,8 +10,10 @@ import { forwardVideoRelatedActivity } from '../send/utils' import { getOrCreateVideoAndAccountAndChannel } from '../videos' import { VideoShareModel } from '../../../models/video/video-share' import { VideoRedundancyModel } from '../../../models/redundancy/video-redundancy' +import { APProcessorOptions } from '../../../typings/activitypub-processor.model' -async function processUndoActivity (activity: ActivityUndo, byActor: ActorModel) { +async function processUndoActivity (options: APProcessorOptions) { + const { activity, byActor } = options const activityToUndo = activity.object if (activityToUndo.type === 'Like') { @@ -59,9 +61,8 @@ async function processUndoLike (byActor: ActorModel, activity: ActivityUndo) { return sequelizeTypescript.transaction(async t => { if (!byActor.Account) throw new Error('Unknown account ' + byActor.url) - let rate = await AccountVideoRateModel.loadByUrl(likeActivity.id, t) - if (!rate) rate = await AccountVideoRateModel.load(byActor.Account.id, video.id, t) - if (!rate) throw new Error(`Unknown rate by account ${byActor.Account.id} for video ${video.id}.`) + const rate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byActor.Account.id, video.id, likeActivity.id, t) + if (!rate || rate.type !== 'like') throw new Error(`Unknown like by account ${byActor.Account.id} for video ${video.id}.`) await rate.destroy({ transaction: t }) await video.decrement('likes', { transaction: t }) @@ -85,9 +86,8 @@ async function processUndoDislike (byActor: ActorModel, activity: ActivityUndo) return sequelizeTypescript.transaction(async t => { if (!byActor.Account) throw new Error('Unknown account ' + byActor.url) - let rate = await AccountVideoRateModel.loadByUrl(dislike.id, t) - if (!rate) rate = await AccountVideoRateModel.load(byActor.Account.id, video.id, t) - if (!rate) throw new Error(`Unknown rate by account ${byActor.Account.id} for video ${video.id}.`) + const rate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byActor.Account.id, video.id, dislike.id, t) + if (!rate || rate.type !== 'dislike') throw new Error(`Unknown dislike by account ${byActor.Account.id} for video ${video.id}.`) await rate.destroy({ transaction: t }) await video.decrement('dislikes', { transaction: t }) @@ -108,7 +108,10 @@ async function processUndoCacheFile (byActor: ActorModel, activity: ActivityUndo return sequelizeTypescript.transaction(async t => { const cacheFile = await VideoRedundancyModel.loadByUrl(cacheFileObject.id) - if (!cacheFile) throw new Error('Unknown video cache ' + cacheFileObject.id) + if (!cacheFile) { + logger.debug('Cannot undo unknown video cache %s.', cacheFileObject.id) + return + } if (cacheFile.actorId !== byActor.id) throw new Error('Cannot delete redundancy ' + cacheFile.url + ' of another actor.')