aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators/abuses.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/custom-validators/abuses.ts')
-rw-r--r--server/helpers/custom-validators/abuses.ts68
1 files changed, 0 insertions, 68 deletions
diff --git a/server/helpers/custom-validators/abuses.ts b/server/helpers/custom-validators/abuses.ts
deleted file mode 100644
index 94719641a..000000000
--- a/server/helpers/custom-validators/abuses.ts
+++ /dev/null
@@ -1,68 +0,0 @@
1import validator from 'validator'
2import { abusePredefinedReasonsMap } from '@shared/core-utils/abuse'
3import { AbuseCreate, AbuseFilter, AbusePredefinedReasonsString, AbuseVideoIs } from '@shared/models'
4import { ABUSE_STATES, CONSTRAINTS_FIELDS } from '../../initializers/constants'
5import { exists, isArray } from './misc'
6
7const ABUSES_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.ABUSES
8const ABUSE_MESSAGES_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.ABUSE_MESSAGES
9
10function isAbuseReasonValid (value: string) {
11 return exists(value) && validator.isLength(value, ABUSES_CONSTRAINTS_FIELDS.REASON)
12}
13
14function isAbusePredefinedReasonValid (value: AbusePredefinedReasonsString) {
15 return exists(value) && value in abusePredefinedReasonsMap
16}
17
18function isAbuseFilterValid (value: AbuseFilter) {
19 return value === 'video' || value === 'comment' || value === 'account'
20}
21
22function areAbusePredefinedReasonsValid (value: AbusePredefinedReasonsString[]) {
23 return exists(value) && isArray(value) && value.every(v => v in abusePredefinedReasonsMap)
24}
25
26function isAbuseTimestampValid (value: number) {
27 return value === null || (exists(value) && validator.isInt('' + value, { min: 0 }))
28}
29
30function isAbuseTimestampCoherent (endAt: number, { req }) {
31 const startAt = (req.body as AbuseCreate).video.startAt
32
33 return exists(startAt) && endAt > startAt
34}
35
36function isAbuseModerationCommentValid (value: string) {
37 return exists(value) && validator.isLength(value, ABUSES_CONSTRAINTS_FIELDS.MODERATION_COMMENT)
38}
39
40function isAbuseStateValid (value: string) {
41 return exists(value) && ABUSE_STATES[value] !== undefined
42}
43
44function isAbuseVideoIsValid (value: AbuseVideoIs) {
45 return exists(value) && (
46 value === 'deleted' ||
47 value === 'blacklisted'
48 )
49}
50
51function isAbuseMessageValid (value: string) {
52 return exists(value) && validator.isLength(value, ABUSE_MESSAGES_CONSTRAINTS_FIELDS.MESSAGE)
53}
54
55// ---------------------------------------------------------------------------
56
57export {
58 isAbuseReasonValid,
59 isAbuseFilterValid,
60 isAbusePredefinedReasonValid,
61 isAbuseMessageValid,
62 areAbusePredefinedReasonsValid,
63 isAbuseTimestampValid,
64 isAbuseTimestampCoherent,
65 isAbuseModerationCommentValid,
66 isAbuseStateValid,
67 isAbuseVideoIsValid
68}