aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators/video-abuses.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-08-10 16:54:01 +0200
committerChocobozzz <me@florianbigard.com>2018-08-10 16:54:01 +0200
commit268eebed921ac13a9ce0f4717f4923aa24190657 (patch)
tree52f8436968c8dcc686663ef5db8dffd7ed191d34 /server/helpers/custom-validators/video-abuses.ts
parent904a463c7792837f0a468a522a28448323e48593 (diff)
downloadPeerTube-268eebed921ac13a9ce0f4717f4923aa24190657.tar.gz
PeerTube-268eebed921ac13a9ce0f4717f4923aa24190657.tar.zst
PeerTube-268eebed921ac13a9ce0f4717f4923aa24190657.zip
Add state and moderationComment for abuses on server side
Diffstat (limited to 'server/helpers/custom-validators/video-abuses.ts')
-rw-r--r--server/helpers/custom-validators/video-abuses.ts43
1 files changed, 43 insertions, 0 deletions
diff --git a/server/helpers/custom-validators/video-abuses.ts b/server/helpers/custom-validators/video-abuses.ts
new file mode 100644
index 000000000..290efb149
--- /dev/null
+++ b/server/helpers/custom-validators/video-abuses.ts
@@ -0,0 +1,43 @@
1import { Response } from 'express'
2import * as validator from 'validator'
3import { CONSTRAINTS_FIELDS, VIDEO_ABUSE_STATES } from '../../initializers'
4import { exists } from './misc'
5import { VideoAbuseModel } from '../../models/video/video-abuse'
6
7const VIDEO_ABUSES_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_ABUSES
8
9function isVideoAbuseReasonValid (value: string) {
10 return exists(value) && validator.isLength(value, VIDEO_ABUSES_CONSTRAINTS_FIELDS.REASON)
11}
12
13function isVideoAbuseModerationCommentValid (value: string) {
14 return exists(value) && validator.isLength(value, VIDEO_ABUSES_CONSTRAINTS_FIELDS.MODERATION_COMMENT)
15}
16
17function isVideoAbuseStateValid (value: string) {
18 return exists(value) && VIDEO_ABUSE_STATES[ value ] !== undefined
19}
20
21async function isVideoAbuseExist (abuseId: number, videoId: number, res: Response) {
22 const videoAbuse = await VideoAbuseModel.loadByIdAndVideoId(abuseId, videoId)
23
24 if (videoAbuse === null) {
25 res.status(404)
26 .json({ error: 'Video abuse not found' })
27 .end()
28
29 return false
30 }
31
32 res.locals.videoAbuse = videoAbuse
33 return true
34}
35
36// ---------------------------------------------------------------------------
37
38export {
39 isVideoAbuseExist,
40 isVideoAbuseStateValid,
41 isVideoAbuseReasonValid,
42 isVideoAbuseModerationCommentValid
43}