diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2020-04-16 14:22:27 +0200 |
---|---|---|
committer | Rigel Kent <par@rigelk.eu> | 2020-05-01 16:41:02 +0200 |
commit | 68d19a0ace01cb7a3550da420d27663e2db1b98d (patch) | |
tree | fcdac5341001b9e6d15ddd0ca8239372ec2b3053 /server/helpers/middlewares/video-abuses.ts | |
parent | 165ee2929bc76fc7f9985ae81cc33736820c7865 (diff) | |
download | PeerTube-68d19a0ace01cb7a3550da420d27663e2db1b98d.tar.gz PeerTube-68d19a0ace01cb7a3550da420d27663e2db1b98d.tar.zst PeerTube-68d19a0ace01cb7a3550da420d27663e2db1b98d.zip |
Make sure a report doesn't get deleted upon the deletion of its video
Diffstat (limited to 'server/helpers/middlewares/video-abuses.ts')
-rw-r--r-- | server/helpers/middlewares/video-abuses.ts | 12 |
1 files changed, 10 insertions, 2 deletions
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 @@ | |||
1 | import { Response } from 'express' | 1 | import { Response } from 'express' |
2 | import { VideoAbuseModel } from '../../models/video/video-abuse' | 2 | import { VideoAbuseModel } from '../../models/video/video-abuse' |
3 | import { fetchVideo } from '../video' | ||
3 | 4 | ||
4 | async function doesVideoAbuseExist (abuseIdArg: number | string, videoId: number, res: Response) { | 5 | async function doesVideoAbuseExist (abuseIdArg: number | string, videoUUID: string, res: Response) { |
5 | const abuseId = parseInt(abuseIdArg + '', 10) | 6 | const abuseId = parseInt(abuseIdArg + '', 10) |
6 | const videoAbuse = await VideoAbuseModel.loadByIdAndVideoId(abuseId, videoId) | 7 | let videoAbuse = await VideoAbuseModel.loadByIdAndVideoId(abuseId, null, videoUUID) |
8 | |||
9 | if (!videoAbuse) { | ||
10 | const userId = res.locals.oauth ? res.locals.oauth.token.User.id : undefined | ||
11 | const video = await fetchVideo(videoUUID, 'all', userId) | ||
12 | |||
13 | if (video) videoAbuse = await VideoAbuseModel.loadByIdAndVideoId(abuseId, video.id) | ||
14 | } | ||
7 | 15 | ||
8 | if (videoAbuse === null) { | 16 | if (videoAbuse === null) { |
9 | res.status(404) | 17 | res.status(404) |