X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fmiddlewares%2Fvideo-abuses.ts;h=97a5724b6dd69afd69ad3c57051896ff1af310a9;hb=610d0be13b3d01f653ef269271dd667a57c85ef2;hp=1b573ca37e7ae2bf0dff4956af95ecb76ac9b2d6;hpb=d5c8932a601c1854db0a2e399ccaf26e17385f1a;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/middlewares/video-abuses.ts b/server/helpers/middlewares/video-abuses.ts index 1b573ca37..97a5724b6 100644 --- a/server/helpers/middlewares/video-abuses.ts +++ b/server/helpers/middlewares/video-abuses.ts @@ -1,8 +1,17 @@ import { Response } from 'express' import { VideoAbuseModel } from '../../models/video/video-abuse' +import { fetchVideo } from '../video' -async function doesVideoAbuseExist (abuseId: number, videoId: number, res: Response) { - const videoAbuse = await VideoAbuseModel.loadByIdAndVideoId(abuseId, videoId) +async function doesVideoAbuseExist (abuseIdArg: number | string, videoUUID: string, res: Response) { + const abuseId = parseInt(abuseIdArg + '', 10) + let videoAbuse = await VideoAbuseModel.loadByIdAndVideoId(abuseId, null, videoUUID) + + if (!videoAbuse) { + const userId = res.locals.oauth?.token.User.id + const video = await fetchVideo(videoUUID, 'all', userId) + + if (video) videoAbuse = await VideoAbuseModel.loadByIdAndVideoId(abuseId, video.id) + } if (videoAbuse === null) { res.status(404)