diff options
Diffstat (limited to 'server/helpers/custom-validators/videos.ts')
-rw-r--r-- | server/helpers/custom-validators/videos.ts | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts index e526c4284..ca5f70fdc 100644 --- a/server/helpers/custom-validators/videos.ts +++ b/server/helpers/custom-validators/videos.ts | |||
@@ -13,7 +13,7 @@ import { | |||
13 | VIDEO_RATE_TYPES, | 13 | VIDEO_RATE_TYPES, |
14 | VIDEO_STATES | 14 | VIDEO_STATES |
15 | } from '../../initializers/constants' | 15 | } from '../../initializers/constants' |
16 | import { exists, isArray, isDateValid, isFileMimeTypeValid, isFileValid } from './misc' | 16 | import { exists, isArray, isDateValid, isFileValid } from './misc' |
17 | 17 | ||
18 | const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS | 18 | const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS |
19 | 19 | ||
@@ -66,7 +66,7 @@ function isVideoTagValid (tag: string) { | |||
66 | return exists(tag) && validator.isLength(tag, VIDEOS_CONSTRAINTS_FIELDS.TAG) | 66 | return exists(tag) && validator.isLength(tag, VIDEOS_CONSTRAINTS_FIELDS.TAG) |
67 | } | 67 | } |
68 | 68 | ||
69 | function isVideoTagsValid (tags: string[]) { | 69 | function areVideoTagsValid (tags: string[]) { |
70 | return tags === null || ( | 70 | return tags === null || ( |
71 | isArray(tags) && | 71 | isArray(tags) && |
72 | validator.isInt(tags.length.toString(), VIDEOS_CONSTRAINTS_FIELDS.TAGS) && | 72 | validator.isInt(tags.length.toString(), VIDEOS_CONSTRAINTS_FIELDS.TAGS) && |
@@ -86,8 +86,13 @@ function isVideoFileExtnameValid (value: string) { | |||
86 | return exists(value) && (value === VIDEO_LIVE.EXTENSION || MIMETYPES.VIDEO.EXT_MIMETYPE[value] !== undefined) | 86 | return exists(value) && (value === VIDEO_LIVE.EXTENSION || MIMETYPES.VIDEO.EXT_MIMETYPE[value] !== undefined) |
87 | } | 87 | } |
88 | 88 | ||
89 | function isVideoFileMimeTypeValid (files: UploadFilesForCheck) { | 89 | function isVideoFileMimeTypeValid (files: UploadFilesForCheck, field = 'videofile') { |
90 | return isFileMimeTypeValid(files, MIMETYPES.VIDEO.MIMETYPES_REGEX, 'videofile') | 90 | return isFileValid({ |
91 | files, | ||
92 | mimeTypeRegex: MIMETYPES.VIDEO.MIMETYPES_REGEX, | ||
93 | field, | ||
94 | maxSize: null | ||
95 | }) | ||
91 | } | 96 | } |
92 | 97 | ||
93 | const videoImageTypes = CONSTRAINTS_FIELDS.VIDEOS.IMAGE.EXTNAME | 98 | const videoImageTypes = CONSTRAINTS_FIELDS.VIDEOS.IMAGE.EXTNAME |
@@ -95,8 +100,14 @@ const videoImageTypes = CONSTRAINTS_FIELDS.VIDEOS.IMAGE.EXTNAME | |||
95 | .join('|') | 100 | .join('|') |
96 | const videoImageTypesRegex = `image/(${videoImageTypes})` | 101 | const videoImageTypesRegex = `image/(${videoImageTypes})` |
97 | 102 | ||
98 | function isVideoImage (files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[], field: string) { | 103 | function isVideoImageValid (files: UploadFilesForCheck, field: string, optional = true) { |
99 | return isFileValid(files, videoImageTypesRegex, field, CONSTRAINTS_FIELDS.VIDEOS.IMAGE.FILE_SIZE.max, true) | 104 | return isFileValid({ |
105 | files, | ||
106 | mimeTypeRegex: videoImageTypesRegex, | ||
107 | field, | ||
108 | maxSize: CONSTRAINTS_FIELDS.VIDEOS.IMAGE.FILE_SIZE.max, | ||
109 | optional | ||
110 | }) | ||
100 | } | 111 | } |
101 | 112 | ||
102 | function isVideoPrivacyValid (value: number) { | 113 | function isVideoPrivacyValid (value: number) { |
@@ -144,7 +155,7 @@ export { | |||
144 | isVideoDescriptionValid, | 155 | isVideoDescriptionValid, |
145 | isVideoFileInfoHashValid, | 156 | isVideoFileInfoHashValid, |
146 | isVideoNameValid, | 157 | isVideoNameValid, |
147 | isVideoTagsValid, | 158 | areVideoTagsValid, |
148 | isVideoFPSResolutionValid, | 159 | isVideoFPSResolutionValid, |
149 | isScheduleVideoUpdatePrivacyValid, | 160 | isScheduleVideoUpdatePrivacyValid, |
150 | isVideoOriginallyPublishedAtValid, | 161 | isVideoOriginallyPublishedAtValid, |
@@ -160,7 +171,7 @@ export { | |||
160 | isVideoPrivacyValid, | 171 | isVideoPrivacyValid, |
161 | isVideoFileResolutionValid, | 172 | isVideoFileResolutionValid, |
162 | isVideoFileSizeValid, | 173 | isVideoFileSizeValid, |
163 | isVideoImage, | 174 | isVideoImageValid, |
164 | isVideoSupportValid, | 175 | isVideoSupportValid, |
165 | isVideoFilterValid | 176 | isVideoFilterValid |
166 | } | 177 | } |