]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/helpers/middlewares/abuses.ts
Use 3 tables to represent abuses
[github/Chocobozzz/PeerTube.git] / server / helpers / middlewares / abuses.ts
CommitLineData
453e83ea 1import { Response } from 'express'
d95d1559 2import { AbuseModel } from '../../models/abuse/abuse'
68d19a0a 3import { fetchVideo } from '../video'
3e753302 4
d95d1559 5// FIXME: deprecated in 2.3. Remove this function
68d19a0a 6async function doesVideoAbuseExist (abuseIdArg: number | string, videoUUID: string, res: Response) {
d5d9b6d7 7 const abuseId = parseInt(abuseIdArg + '', 10)
d95d1559 8 let abuse = await AbuseModel.loadByIdAndVideoId(abuseId, null, videoUUID)
68d19a0a 9
d95d1559 10 if (!abuse) {
0251197e 11 const userId = res.locals.oauth?.token.User.id
68d19a0a
RK
12 const video = await fetchVideo(videoUUID, 'all', userId)
13
d95d1559 14 if (video) abuse = await AbuseModel.loadByIdAndVideoId(abuseId, video.id)
68d19a0a 15 }
3e753302 16
d95d1559 17 if (abuse === null) {
3e753302 18 res.status(404)
453e83ea 19 .json({ error: 'Video abuse not found' })
3e753302
C
20 .end()
21
22 return false
23 }
24
d95d1559 25 res.locals.abuse = abuse
3e753302
C
26 return true
27}
453e83ea 28
d95d1559
C
29async function doesAbuseExist (abuseIdArg: number | string, videoUUID: string, res: Response) {
30
31}
32
453e83ea
C
33// ---------------------------------------------------------------------------
34
35export {
d95d1559 36 doesAbuseExist,
453e83ea
C
37 doesVideoAbuseExist
38}