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.ts17
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 @@
1import validator from 'validator' 1import validator from 'validator'
2import { abusePredefinedReasonsMap, AbusePredefinedReasonsString, AbuseVideoIs } from '@shared/models' 2import { AbuseFilter, abusePredefinedReasonsMap, AbusePredefinedReasonsString, AbuseVideoIs, AbuseCreate } from '@shared/models'
3import { CONSTRAINTS_FIELDS, ABUSE_STATES } from '../../initializers/constants' 3import { ABUSE_STATES, CONSTRAINTS_FIELDS } from '../../initializers/constants'
4import { exists, isArray } from './misc' 4import { exists, isArray } from './misc'
5 5
6const VIDEO_ABUSES_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.ABUSES 6const 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
16function isAbusePredefinedReasonsValid (value: AbusePredefinedReasonsString[]) { 16function isAbuseFilterValid (value: AbuseFilter) {
17 return value === 'video' || value === 'comment' || value === 'account'
18}
19
20function 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
24function isAbuseTimestampCoherent (endAt: number, { req }) { 28function 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
28function isAbuseModerationCommentValid (value: string) { 34function isAbuseModerationCommentValid (value: string) {
@@ -44,8 +50,9 @@ function isAbuseVideoIsValid (value: AbuseVideoIs) {
44 50
45export { 51export {
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,