aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators/video-abuses.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/custom-validators/video-abuses.ts')
-rw-r--r--server/helpers/custom-validators/video-abuses.ts56
1 files changed, 0 insertions, 56 deletions
diff --git a/server/helpers/custom-validators/video-abuses.ts b/server/helpers/custom-validators/video-abuses.ts
deleted file mode 100644
index 0c2c34268..000000000
--- a/server/helpers/custom-validators/video-abuses.ts
+++ /dev/null
@@ -1,56 +0,0 @@
1import validator from 'validator'
2
3import { CONSTRAINTS_FIELDS, VIDEO_ABUSE_STATES } from '../../initializers/constants'
4import { exists, isArray } from './misc'
5import { VideoAbuseVideoIs } from '@shared/models/videos/abuse/video-abuse-video-is.type'
6import { VideoAbusePredefinedReasonsString, videoAbusePredefinedReasonsMap } from '@shared/models/videos/abuse/video-abuse-reason.model'
7
8const VIDEO_ABUSES_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_ABUSES
9
10function isVideoAbuseReasonValid (value: string) {
11 return exists(value) && validator.isLength(value, VIDEO_ABUSES_CONSTRAINTS_FIELDS.REASON)
12}
13
14function isVideoAbusePredefinedReasonValid (value: VideoAbusePredefinedReasonsString) {
15 return exists(value) && value in videoAbusePredefinedReasonsMap
16}
17
18function isVideoAbusePredefinedReasonsValid (value: VideoAbusePredefinedReasonsString[]) {
19 return exists(value) && isArray(value) && value.every(v => v in videoAbusePredefinedReasonsMap)
20}
21
22function isVideoAbuseTimestampValid (value: number) {
23 return value === null || (exists(value) && validator.isInt('' + value, { min: 0 }))
24}
25
26function isVideoAbuseTimestampCoherent (endAt: number, { req }) {
27 return exists(req.body.startAt) && endAt > req.body.startAt
28}
29
30function isVideoAbuseModerationCommentValid (value: string) {
31 return exists(value) && validator.isLength(value, VIDEO_ABUSES_CONSTRAINTS_FIELDS.MODERATION_COMMENT)
32}
33
34function isVideoAbuseStateValid (value: string) {
35 return exists(value) && VIDEO_ABUSE_STATES[value] !== undefined
36}
37
38function isAbuseVideoIsValid (value: VideoAbuseVideoIs) {
39 return exists(value) && (
40 value === 'deleted' ||
41 value === 'blacklisted'
42 )
43}
44
45// ---------------------------------------------------------------------------
46
47export {
48 isVideoAbuseReasonValid,
49 isVideoAbusePredefinedReasonValid,
50 isVideoAbusePredefinedReasonsValid,
51 isVideoAbuseTimestampValid,
52 isVideoAbuseTimestampCoherent,
53 isVideoAbuseModerationCommentValid,
54 isVideoAbuseStateValid,
55 isAbuseVideoIsValid
56}