aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators/videos.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/custom-validators/videos.ts')
-rw-r--r--server/helpers/custom-validators/videos.ts39
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'
12import { isUserUsernameValid } from './users' 13import { isUserUsernameValid } from './users'
13import { isArray, exists } from './misc' 14import { 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
56function isVideoExtnameValid (value: string) {
57 return VIDEOS_CONSTRAINTS_FIELDS.EXTNAME.indexOf(value) !== -1
58}
59
60function isVideoInfoHashValid (value: string) {
61 return exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.INFO_HASH)
62}
63
64function isVideoNameValid (value: string) { 57function 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
124function isVideoFileSizeValid (value: string) {
125 return exists(value) && validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.FILE_SIZE)
126}
127
128function isVideoFileResolutionValid (value: string) {
129 return VIDEO_FILE_RESOLUTIONS[value] !== undefined
130}
131
132function isVideoFileExtnameValid (value: string) {
133 return VIDEOS_CONSTRAINTS_FIELDS.EXTNAME.indexOf(value) !== -1
134}
135
136function isVideoFileInfoHashValid (value: string) {
137 return exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.INFO_HASH)
138}
139
131// --------------------------------------------------------------------------- 140// ---------------------------------------------------------------------------
132 141
133export { 142export {
@@ -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
160declare global { 171declare 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}