aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/middlewares/abuses.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/middlewares/abuses.ts')
-rw-r--r--server/helpers/middlewares/abuses.ts47
1 files changed, 47 insertions, 0 deletions
diff --git a/server/helpers/middlewares/abuses.ts b/server/helpers/middlewares/abuses.ts
new file mode 100644
index 000000000..be8c8b449
--- /dev/null
+++ b/server/helpers/middlewares/abuses.ts
@@ -0,0 +1,47 @@
1import { Response } from 'express'
2import { AbuseModel } from '../../models/abuse/abuse'
3import { fetchVideo } from '../video'
4
5// FIXME: deprecated in 2.3. Remove this function
6async function doesVideoAbuseExist (abuseIdArg: number | string, videoUUID: string, res: Response) {
7 const abuseId = parseInt(abuseIdArg + '', 10)
8 let abuse = await AbuseModel.loadByIdAndVideoId(abuseId, null, videoUUID)
9
10 if (!abuse) {
11 const userId = res.locals.oauth?.token.User.id
12 const video = await fetchVideo(videoUUID, 'all', userId)
13
14 if (video) abuse = await AbuseModel.loadByIdAndVideoId(abuseId, video.id)
15 }
16
17 if (abuse === null) {
18 res.status(404)
19 .json({ error: 'Video abuse not found' })
20
21 return false
22 }
23
24 res.locals.abuse = abuse
25 return true
26}
27
28async function doesAbuseExist (abuseId: number | string, res: Response) {
29 const abuse = await AbuseModel.loadById(parseInt(abuseId + '', 10))
30
31 if (!abuse) {
32 res.status(404)
33 .json({ error: 'Abuse not found' })
34
35 return false
36 }
37
38 res.locals.abuse = abuse
39 return true
40}
41
42// ---------------------------------------------------------------------------
43
44export {
45 doesAbuseExist,
46 doesVideoAbuseExist
47}