aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/custom-validators')
-rw-r--r--server/helpers/custom-validators/activitypub/videos.ts2
-rw-r--r--server/helpers/custom-validators/video-abuses.ts43
-rw-r--r--server/helpers/custom-validators/videos.ts7
3 files changed, 46 insertions, 6 deletions
diff --git a/server/helpers/custom-validators/activitypub/videos.ts b/server/helpers/custom-validators/activitypub/videos.ts
index b8075f3c7..702c09842 100644
--- a/server/helpers/custom-validators/activitypub/videos.ts
+++ b/server/helpers/custom-validators/activitypub/videos.ts
@@ -3,7 +3,6 @@ import { ACTIVITY_PUB, CONSTRAINTS_FIELDS } from '../../../initializers'
3import { peertubeTruncate } from '../../core-utils' 3import { peertubeTruncate } from '../../core-utils'
4import { exists, isBooleanValid, isDateValid, isUUIDValid } from '../misc' 4import { exists, isBooleanValid, isDateValid, isUUIDValid } from '../misc'
5import { 5import {
6 isVideoAbuseReasonValid,
7 isVideoDurationValid, 6 isVideoDurationValid,
8 isVideoNameValid, 7 isVideoNameValid,
9 isVideoStateValid, 8 isVideoStateValid,
@@ -13,6 +12,7 @@ import {
13} from '../videos' 12} from '../videos'
14import { isActivityPubUrlValid, isBaseActivityValid, setValidAttributedTo } from './misc' 13import { isActivityPubUrlValid, isBaseActivityValid, setValidAttributedTo } from './misc'
15import { VideoState } from '../../../../shared/models/videos' 14import { VideoState } from '../../../../shared/models/videos'
15import { isVideoAbuseReasonValid } from '../video-abuses'
16 16
17function sanitizeAndCheckVideoTorrentCreateActivity (activity: any) { 17function sanitizeAndCheckVideoTorrentCreateActivity (activity: any) {
18 return isBaseActivityValid(activity, 'Create') && 18 return isBaseActivityValid(activity, 'Create') &&
diff --git a/server/helpers/custom-validators/video-abuses.ts b/server/helpers/custom-validators/video-abuses.ts
new file mode 100644
index 000000000..290efb149
--- /dev/null
+++ b/server/helpers/custom-validators/video-abuses.ts
@@ -0,0 +1,43 @@
1import { Response } from 'express'
2import * as validator from 'validator'
3import { CONSTRAINTS_FIELDS, VIDEO_ABUSE_STATES } from '../../initializers'
4import { exists } from './misc'
5import { VideoAbuseModel } from '../../models/video/video-abuse'
6
7const VIDEO_ABUSES_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_ABUSES
8
9function isVideoAbuseReasonValid (value: string) {
10 return exists(value) && validator.isLength(value, VIDEO_ABUSES_CONSTRAINTS_FIELDS.REASON)
11}
12
13function isVideoAbuseModerationCommentValid (value: string) {
14 return exists(value) && validator.isLength(value, VIDEO_ABUSES_CONSTRAINTS_FIELDS.MODERATION_COMMENT)
15}
16
17function isVideoAbuseStateValid (value: string) {
18 return exists(value) && VIDEO_ABUSE_STATES[ value ] !== undefined
19}
20
21async function isVideoAbuseExist (abuseId: number, videoId: number, res: Response) {
22 const videoAbuse = await VideoAbuseModel.loadByIdAndVideoId(abuseId, videoId)
23
24 if (videoAbuse === null) {
25 res.status(404)
26 .json({ error: 'Video abuse not found' })
27 .end()
28
29 return false
30 }
31
32 res.locals.videoAbuse = videoAbuse
33 return true
34}
35
36// ---------------------------------------------------------------------------
37
38export {
39 isVideoAbuseExist,
40 isVideoAbuseStateValid,
41 isVideoAbuseReasonValid,
42 isVideoAbuseModerationCommentValid
43}
diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts
index f4c1c8b07..5e6cfe217 100644
--- a/server/helpers/custom-validators/videos.ts
+++ b/server/helpers/custom-validators/videos.ts
@@ -6,6 +6,7 @@ import * as validator from 'validator'
6import { UserRight, VideoPrivacy, VideoRateType } from '../../../shared' 6import { UserRight, VideoPrivacy, VideoRateType } from '../../../shared'
7import { 7import {
8 CONSTRAINTS_FIELDS, 8 CONSTRAINTS_FIELDS,
9 VIDEO_ABUSE_STATES,
9 VIDEO_CATEGORIES, 10 VIDEO_CATEGORIES,
10 VIDEO_LICENCES, 11 VIDEO_LICENCES,
11 VIDEO_MIMETYPE_EXT, 12 VIDEO_MIMETYPE_EXT,
@@ -18,6 +19,7 @@ import { exists, isArray, isFileValid } from './misc'
18import { VideoChannelModel } from '../../models/video/video-channel' 19import { VideoChannelModel } from '../../models/video/video-channel'
19import { UserModel } from '../../models/account/user' 20import { UserModel } from '../../models/account/user'
20import * as magnetUtil from 'magnet-uri' 21import * as magnetUtil from 'magnet-uri'
22import { VideoAbuseModel } from '../../models/video/video-abuse'
21 23
22const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS 24const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS
23const VIDEO_ABUSES_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_ABUSES 25const VIDEO_ABUSES_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_ABUSES
@@ -71,10 +73,6 @@ function isVideoTagsValid (tags: string[]) {
71 ) 73 )
72} 74}
73 75
74function isVideoAbuseReasonValid (value: string) {
75 return exists(value) && validator.isLength(value, VIDEO_ABUSES_CONSTRAINTS_FIELDS.REASON)
76}
77
78function isVideoViewsValid (value: string) { 76function isVideoViewsValid (value: string) {
79 return exists(value) && validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.VIEWS) 77 return exists(value) && validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.VIEWS)
80} 78}
@@ -220,7 +218,6 @@ export {
220 isVideoTagsValid, 218 isVideoTagsValid,
221 isVideoFPSResolutionValid, 219 isVideoFPSResolutionValid,
222 isScheduleVideoUpdatePrivacyValid, 220 isScheduleVideoUpdatePrivacyValid,
223 isVideoAbuseReasonValid,
224 isVideoFile, 221 isVideoFile,
225 isVideoMagnetUriValid, 222 isVideoMagnetUriValid,
226 isVideoStateValid, 223 isVideoStateValid,