diff options
Diffstat (limited to 'server/helpers/custom-validators/abuses.ts')
-rw-r--r-- | server/helpers/custom-validators/abuses.ts | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/server/helpers/custom-validators/abuses.ts b/server/helpers/custom-validators/abuses.ts index a6a895c65..c21468caa 100644 --- a/server/helpers/custom-validators/abuses.ts +++ b/server/helpers/custom-validators/abuses.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import validator from 'validator' | 1 | import validator from 'validator' |
2 | import { abusePredefinedReasonsMap, AbusePredefinedReasonsString, AbuseVideoIs } from '@shared/models' | 2 | import { AbuseFilter, abusePredefinedReasonsMap, AbusePredefinedReasonsString, AbuseVideoIs, AbuseCreate } from '@shared/models' |
3 | import { CONSTRAINTS_FIELDS, ABUSE_STATES } from '../../initializers/constants' | 3 | import { ABUSE_STATES, CONSTRAINTS_FIELDS } from '../../initializers/constants' |
4 | import { exists, isArray } from './misc' | 4 | import { exists, isArray } from './misc' |
5 | 5 | ||
6 | const VIDEO_ABUSES_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.ABUSES | 6 | const VIDEO_ABUSES_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.ABUSES |
@@ -13,7 +13,11 @@ function isAbusePredefinedReasonValid (value: AbusePredefinedReasonsString) { | |||
13 | return exists(value) && value in abusePredefinedReasonsMap | 13 | return exists(value) && value in abusePredefinedReasonsMap |
14 | } | 14 | } |
15 | 15 | ||
16 | function isAbusePredefinedReasonsValid (value: AbusePredefinedReasonsString[]) { | 16 | function isAbuseFilterValid (value: AbuseFilter) { |
17 | return value === 'video' || value === 'comment' || value === 'account' | ||
18 | } | ||
19 | |||
20 | function areAbusePredefinedReasonsValid (value: AbusePredefinedReasonsString[]) { | ||
17 | return exists(value) && isArray(value) && value.every(v => v in abusePredefinedReasonsMap) | 21 | return exists(value) && isArray(value) && value.every(v => v in abusePredefinedReasonsMap) |
18 | } | 22 | } |
19 | 23 | ||
@@ -22,7 +26,9 @@ function isAbuseTimestampValid (value: number) { | |||
22 | } | 26 | } |
23 | 27 | ||
24 | function isAbuseTimestampCoherent (endAt: number, { req }) { | 28 | function isAbuseTimestampCoherent (endAt: number, { req }) { |
25 | return exists(req.body.startAt) && endAt > req.body.startAt | 29 | const startAt = (req.body as AbuseCreate).video.startAt |
30 | |||
31 | return exists(startAt) && endAt > startAt | ||
26 | } | 32 | } |
27 | 33 | ||
28 | function isAbuseModerationCommentValid (value: string) { | 34 | function isAbuseModerationCommentValid (value: string) { |
@@ -44,8 +50,9 @@ function isAbuseVideoIsValid (value: AbuseVideoIs) { | |||
44 | 50 | ||
45 | export { | 51 | export { |
46 | isAbuseReasonValid, | 52 | isAbuseReasonValid, |
53 | isAbuseFilterValid, | ||
47 | isAbusePredefinedReasonValid, | 54 | isAbusePredefinedReasonValid, |
48 | isAbusePredefinedReasonsValid, | 55 | areAbusePredefinedReasonsValid as isAbusePredefinedReasonsValid, |
49 | isAbuseTimestampValid, | 56 | isAbuseTimestampValid, |
50 | isAbuseTimestampCoherent, | 57 | isAbuseTimestampCoherent, |
51 | isAbuseModerationCommentValid, | 58 | isAbuseModerationCommentValid, |