From 68d19a0ace01cb7a3550da420d27663e2db1b98d Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Thu, 16 Apr 2020 14:22:27 +0200 Subject: Make sure a report doesn't get deleted upon the deletion of its video --- server/helpers/middlewares/video-abuses.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'server/helpers') diff --git a/server/helpers/middlewares/video-abuses.ts b/server/helpers/middlewares/video-abuses.ts index 8a1d3d618..7553a5eb3 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 ? res.locals.oauth.token.User.id : undefined + const video = await fetchVideo(videoUUID, 'all', userId) + + if (video) videoAbuse = await VideoAbuseModel.loadByIdAndVideoId(abuseId, video.id) + } if (videoAbuse === null) { res.status(404) -- cgit v1.2.3