diff options
Diffstat (limited to 'server/helpers/custom-validators/videos.ts')
-rw-r--r-- | server/helpers/custom-validators/videos.ts | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts index 62132acb1..139fa760f 100644 --- a/server/helpers/custom-validators/videos.ts +++ b/server/helpers/custom-validators/videos.ts | |||
@@ -7,7 +7,8 @@ import { | |||
7 | VIDEO_CATEGORIES, | 7 | VIDEO_CATEGORIES, |
8 | VIDEO_LICENCES, | 8 | VIDEO_LICENCES, |
9 | VIDEO_LANGUAGES, | 9 | VIDEO_LANGUAGES, |
10 | VIDEO_RATE_TYPES | 10 | VIDEO_RATE_TYPES, |
11 | VIDEO_FILE_RESOLUTIONS | ||
11 | } from '../../initializers' | 12 | } from '../../initializers' |
12 | import { isUserUsernameValid } from './users' | 13 | import { isUserUsernameValid } from './users' |
13 | import { isArray, exists } from './misc' | 14 | import { isArray, exists } from './misc' |
@@ -53,14 +54,6 @@ function isVideoDurationValid (value: string) { | |||
53 | return exists(value) && validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.DURATION) | 54 | return exists(value) && validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.DURATION) |
54 | } | 55 | } |
55 | 56 | ||
56 | function isVideoExtnameValid (value: string) { | ||
57 | return VIDEOS_CONSTRAINTS_FIELDS.EXTNAME.indexOf(value) !== -1 | ||
58 | } | ||
59 | |||
60 | function isVideoInfoHashValid (value: string) { | ||
61 | return exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.INFO_HASH) | ||
62 | } | ||
63 | |||
64 | function isVideoNameValid (value: string) { | 57 | function isVideoNameValid (value: string) { |
65 | return exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.NAME) | 58 | return exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.NAME) |
66 | } | 59 | } |
@@ -128,6 +121,22 @@ function isVideoFile (value: string, files: { [ fieldname: string ]: Express.Mul | |||
128 | return new RegExp('^video/(webm|mp4|ogg)$', 'i').test(file.mimetype) | 121 | return new RegExp('^video/(webm|mp4|ogg)$', 'i').test(file.mimetype) |
129 | } | 122 | } |
130 | 123 | ||
124 | function isVideoFileSizeValid (value: string) { | ||
125 | return exists(value) && validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.FILE_SIZE) | ||
126 | } | ||
127 | |||
128 | function isVideoFileResolutionValid (value: string) { | ||
129 | return VIDEO_FILE_RESOLUTIONS[value] !== undefined | ||
130 | } | ||
131 | |||
132 | function isVideoFileExtnameValid (value: string) { | ||
133 | return VIDEOS_CONSTRAINTS_FIELDS.EXTNAME.indexOf(value) !== -1 | ||
134 | } | ||
135 | |||
136 | function isVideoFileInfoHashValid (value: string) { | ||
137 | return exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.INFO_HASH) | ||
138 | } | ||
139 | |||
131 | // --------------------------------------------------------------------------- | 140 | // --------------------------------------------------------------------------- |
132 | 141 | ||
133 | export { | 142 | export { |
@@ -140,12 +149,12 @@ export { | |||
140 | isVideoNSFWValid, | 149 | isVideoNSFWValid, |
141 | isVideoDescriptionValid, | 150 | isVideoDescriptionValid, |
142 | isVideoDurationValid, | 151 | isVideoDurationValid, |
143 | isVideoInfoHashValid, | 152 | isVideoFileInfoHashValid, |
144 | isVideoNameValid, | 153 | isVideoNameValid, |
145 | isVideoTagsValid, | 154 | isVideoTagsValid, |
146 | isVideoThumbnailValid, | 155 | isVideoThumbnailValid, |
147 | isVideoThumbnailDataValid, | 156 | isVideoThumbnailDataValid, |
148 | isVideoExtnameValid, | 157 | isVideoFileExtnameValid, |
149 | isVideoUUIDValid, | 158 | isVideoUUIDValid, |
150 | isVideoAbuseReasonValid, | 159 | isVideoAbuseReasonValid, |
151 | isVideoAbuseReporterUsernameValid, | 160 | isVideoAbuseReporterUsernameValid, |
@@ -154,7 +163,9 @@ export { | |||
154 | isVideoLikesValid, | 163 | isVideoLikesValid, |
155 | isVideoRatingTypeValid, | 164 | isVideoRatingTypeValid, |
156 | isVideoDislikesValid, | 165 | isVideoDislikesValid, |
157 | isVideoEventCountValid | 166 | isVideoEventCountValid, |
167 | isVideoFileSizeValid, | ||
168 | isVideoFileResolutionValid | ||
158 | } | 169 | } |
159 | 170 | ||
160 | declare global { | 171 | declare global { |
@@ -183,7 +194,9 @@ declare global { | |||
183 | isVideoLikesValid, | 194 | isVideoLikesValid, |
184 | isVideoRatingTypeValid, | 195 | isVideoRatingTypeValid, |
185 | isVideoDislikesValid, | 196 | isVideoDislikesValid, |
186 | isVideoEventCountValid | 197 | isVideoEventCountValid, |
198 | isVideoFileSizeValid, | ||
199 | isVideoFileResolutionValid | ||
187 | } | 200 | } |
188 | } | 201 | } |
189 | } | 202 | } |