]>
Commit | Line | Data |
---|---|---|
1 | import validator from 'validator' | |
2 | ||
3 | import { CONSTRAINTS_FIELDS, VIDEO_ABUSE_STATES } from '../../initializers/constants' | |
4 | import { exists, isArray } from './misc' | |
5 | import { VideoAbuseVideoIs } from '@shared/models/videos/abuse/video-abuse-video-is.type' | |
6 | import { VideoAbusePredefinedReasonsString, videoAbusePredefinedReasonsMap } from '@shared/models/videos/abuse/video-abuse-reason.model' | |
7 | ||
8 | const VIDEO_ABUSES_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_ABUSES | |
9 | ||
10 | function isVideoAbuseReasonValid (value: string) { | |
11 | return exists(value) && validator.isLength(value, VIDEO_ABUSES_CONSTRAINTS_FIELDS.REASON) | |
12 | } | |
13 | ||
14 | function isVideoAbusePredefinedReasonValid (value: VideoAbusePredefinedReasonsString) { | |
15 | return exists(value) && value in videoAbusePredefinedReasonsMap | |
16 | } | |
17 | ||
18 | function isVideoAbusePredefinedReasonsValid (value: VideoAbusePredefinedReasonsString[]) { | |
19 | return exists(value) && isArray(value) && value.every(v => v in videoAbusePredefinedReasonsMap) | |
20 | } | |
21 | ||
22 | function isVideoAbuseTimestampValid (value: number) { | |
23 | return value === null || (exists(value) && validator.isInt('' + value, { min: 0 })) | |
24 | } | |
25 | ||
26 | function isVideoAbuseTimestampCoherent (endAt: number, { req }) { | |
27 | return exists(req.body.startAt) && endAt > req.body.startAt | |
28 | } | |
29 | ||
30 | function isVideoAbuseModerationCommentValid (value: string) { | |
31 | return exists(value) && validator.isLength(value, VIDEO_ABUSES_CONSTRAINTS_FIELDS.MODERATION_COMMENT) | |
32 | } | |
33 | ||
34 | function isVideoAbuseStateValid (value: string) { | |
35 | return exists(value) && VIDEO_ABUSE_STATES[value] !== undefined | |
36 | } | |
37 | ||
38 | function isAbuseVideoIsValid (value: VideoAbuseVideoIs) { | |
39 | return exists(value) && ( | |
40 | value === 'deleted' || | |
41 | value === 'blacklisted' | |
42 | ) | |
43 | } | |
44 | ||
45 | // --------------------------------------------------------------------------- | |
46 | ||
47 | export { | |
48 | isVideoAbuseReasonValid, | |
49 | isVideoAbusePredefinedReasonValid, | |
50 | isVideoAbusePredefinedReasonsValid, | |
51 | isVideoAbuseTimestampValid, | |
52 | isVideoAbuseTimestampCoherent, | |
53 | isVideoAbuseModerationCommentValid, | |
54 | isVideoAbuseStateValid, | |
55 | isAbuseVideoIsValid | |
56 | } |