X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fmiddlewares%2Fvideo-abuses.ts;h=97a5724b6dd69afd69ad3c57051896ff1af310a9;hb=610d0be13b3d01f653ef269271dd667a57c85ef2;hp=8a1d3d618296e38dece030bcf18282e2a9e21c1e;hpb=d5d9b6d7bfb7e9426b6462f7fdf285df39eea820;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/middlewares/video-abuses.ts b/server/helpers/middlewares/video-abuses.ts index 8a1d3d618..97a5724b6 100644 --- a/server/helpers/middlewares/video-abuses.ts +++ b/server/helpers/middlewares/video-abuses.ts @@ -1,9 +1,17 @@ import { Response } from 'express' import { VideoAbuseModel } from '../../models/video/video-abuse' +import { fetchVideo } from '../video' -async function doesVideoAbuseExist (abuseIdArg: number | string, videoId: number, res: Response) { +async function doesVideoAbuseExist (abuseIdArg: number | string, videoUUID: string, res: Response) { const abuseId = parseInt(abuseIdArg + '', 10) - const videoAbuse = await VideoAbuseModel.loadByIdAndVideoId(abuseId, videoId) + 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)