diff options
Diffstat (limited to 'server/helpers/custom-validators')
-rw-r--r-- | server/helpers/custom-validators/activitypub/videos.ts | 6 | ||||
-rw-r--r-- | server/helpers/custom-validators/videos.ts | 24 |
2 files changed, 22 insertions, 8 deletions
diff --git a/server/helpers/custom-validators/activitypub/videos.ts b/server/helpers/custom-validators/activitypub/videos.ts index 7e1d57c34..37c90a0c8 100644 --- a/server/helpers/custom-validators/activitypub/videos.ts +++ b/server/helpers/custom-validators/activitypub/videos.ts | |||
@@ -6,11 +6,13 @@ import { | |||
6 | isVideoAbuseReasonValid, | 6 | isVideoAbuseReasonValid, |
7 | isVideoDurationValid, | 7 | isVideoDurationValid, |
8 | isVideoNameValid, | 8 | isVideoNameValid, |
9 | isVideoStateValid, | ||
9 | isVideoTagValid, | 10 | isVideoTagValid, |
10 | isVideoTruncatedDescriptionValid, | 11 | isVideoTruncatedDescriptionValid, |
11 | isVideoViewsValid | 12 | isVideoViewsValid |
12 | } from '../videos' | 13 | } from '../videos' |
13 | import { isActivityPubUrlValid, isBaseActivityValid, setValidAttributedTo } from './misc' | 14 | import { isActivityPubUrlValid, isBaseActivityValid, setValidAttributedTo } from './misc' |
15 | import { VideoState } from '../../../../shared/models/videos' | ||
14 | 16 | ||
15 | function sanitizeAndCheckVideoTorrentCreateActivity (activity: any) { | 17 | function sanitizeAndCheckVideoTorrentCreateActivity (activity: any) { |
16 | return isBaseActivityValid(activity, 'Create') && | 18 | return isBaseActivityValid(activity, 'Create') && |
@@ -50,6 +52,10 @@ function sanitizeAndCheckVideoTorrentObject (video: any) { | |||
50 | if (!setRemoteVideoTruncatedContent(video)) return false | 52 | if (!setRemoteVideoTruncatedContent(video)) return false |
51 | if (!setValidAttributedTo(video)) return false | 53 | if (!setValidAttributedTo(video)) return false |
52 | 54 | ||
55 | // Default attributes | ||
56 | if (!isVideoStateValid(video.state)) video.state = VideoState.PUBLISHED | ||
57 | if (!isBooleanValid(video.waitTranscoding)) video.waitTranscoding = false | ||
58 | |||
53 | return isActivityPubUrlValid(video.id) && | 59 | return isActivityPubUrlValid(video.id) && |
54 | isVideoNameValid(video.name) && | 60 | isVideoNameValid(video.name) && |
55 | isActivityPubVideoDurationValid(video.duration) && | 61 | isActivityPubVideoDurationValid(video.duration) && |
diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts index f365df985..8496e679a 100644 --- a/server/helpers/custom-validators/videos.ts +++ b/server/helpers/custom-validators/videos.ts | |||
@@ -10,7 +10,8 @@ import { | |||
10 | VIDEO_LICENCES, | 10 | VIDEO_LICENCES, |
11 | VIDEO_MIMETYPE_EXT, | 11 | VIDEO_MIMETYPE_EXT, |
12 | VIDEO_PRIVACIES, | 12 | VIDEO_PRIVACIES, |
13 | VIDEO_RATE_TYPES | 13 | VIDEO_RATE_TYPES, |
14 | VIDEO_STATES | ||
14 | } from '../../initializers' | 15 | } from '../../initializers' |
15 | import { VideoModel } from '../../models/video/video' | 16 | import { VideoModel } from '../../models/video/video' |
16 | import { exists, isArray, isFileValid } from './misc' | 17 | import { exists, isArray, isFileValid } from './misc' |
@@ -21,11 +22,15 @@ const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS | |||
21 | const VIDEO_ABUSES_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_ABUSES | 22 | const VIDEO_ABUSES_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_ABUSES |
22 | 23 | ||
23 | function isVideoCategoryValid (value: any) { | 24 | function isVideoCategoryValid (value: any) { |
24 | return value === null || VIDEO_CATEGORIES[value] !== undefined | 25 | return value === null || VIDEO_CATEGORIES[ value ] !== undefined |
26 | } | ||
27 | |||
28 | function isVideoStateValid (value: any) { | ||
29 | return exists(value) && VIDEO_STATES[ value ] !== undefined | ||
25 | } | 30 | } |
26 | 31 | ||
27 | function isVideoLicenceValid (value: any) { | 32 | function isVideoLicenceValid (value: any) { |
28 | return value === null || VIDEO_LICENCES[value] !== undefined | 33 | return value === null || VIDEO_LICENCES[ value ] !== undefined |
29 | } | 34 | } |
30 | 35 | ||
31 | function isVideoLanguageValid (value: any) { | 36 | function isVideoLanguageValid (value: any) { |
@@ -79,20 +84,22 @@ function isVideoRatingTypeValid (value: string) { | |||
79 | 84 | ||
80 | const videoFileTypes = Object.keys(VIDEO_MIMETYPE_EXT).map(m => `(${m})`) | 85 | const videoFileTypes = Object.keys(VIDEO_MIMETYPE_EXT).map(m => `(${m})`) |
81 | const videoFileTypesRegex = videoFileTypes.join('|') | 86 | const videoFileTypesRegex = videoFileTypes.join('|') |
87 | |||
82 | function isVideoFile (files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[]) { | 88 | function isVideoFile (files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[]) { |
83 | return isFileValid(files, videoFileTypesRegex, 'videofile') | 89 | return isFileValid(files, videoFileTypesRegex, 'videofile') |
84 | } | 90 | } |
85 | 91 | ||
86 | const videoImageTypes = CONSTRAINTS_FIELDS.VIDEOS.IMAGE.EXTNAME | 92 | const videoImageTypes = CONSTRAINTS_FIELDS.VIDEOS.IMAGE.EXTNAME |
87 | .map(v => v.replace('.', '')) | 93 | .map(v => v.replace('.', '')) |
88 | .join('|') | 94 | .join('|') |
89 | const videoImageTypesRegex = `image/(${videoImageTypes})` | 95 | const videoImageTypesRegex = `image/(${videoImageTypes})` |
96 | |||
90 | function isVideoImage (files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[], field: string) { | 97 | function isVideoImage (files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[], field: string) { |
91 | return isFileValid(files, videoImageTypesRegex, field, true) | 98 | return isFileValid(files, videoImageTypesRegex, field, true) |
92 | } | 99 | } |
93 | 100 | ||
94 | function isVideoPrivacyValid (value: string) { | 101 | function isVideoPrivacyValid (value: string) { |
95 | return validator.isInt(value + '') && VIDEO_PRIVACIES[value] !== undefined | 102 | return validator.isInt(value + '') && VIDEO_PRIVACIES[ value ] !== undefined |
96 | } | 103 | } |
97 | 104 | ||
98 | function isVideoFileInfoHashValid (value: string) { | 105 | function isVideoFileInfoHashValid (value: string) { |
@@ -118,8 +125,8 @@ async function isVideoExist (id: string, res: Response) { | |||
118 | 125 | ||
119 | if (!video) { | 126 | if (!video) { |
120 | res.status(404) | 127 | res.status(404) |
121 | .json({ error: 'Video not found' }) | 128 | .json({ error: 'Video not found' }) |
122 | .end() | 129 | .end() |
123 | 130 | ||
124 | return false | 131 | return false |
125 | } | 132 | } |
@@ -169,6 +176,7 @@ export { | |||
169 | isVideoTagsValid, | 176 | isVideoTagsValid, |
170 | isVideoAbuseReasonValid, | 177 | isVideoAbuseReasonValid, |
171 | isVideoFile, | 178 | isVideoFile, |
179 | isVideoStateValid, | ||
172 | isVideoViewsValid, | 180 | isVideoViewsValid, |
173 | isVideoRatingTypeValid, | 181 | isVideoRatingTypeValid, |
174 | isVideoDurationValid, | 182 | isVideoDurationValid, |