diff options
Diffstat (limited to 'server/helpers/custom-validators/videos.ts')
-rw-r--r-- | server/helpers/custom-validators/videos.ts | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts index 0e8a2aab2..8ef3a3c64 100644 --- a/server/helpers/custom-validators/videos.ts +++ b/server/helpers/custom-validators/videos.ts | |||
@@ -8,12 +8,12 @@ import { | |||
8 | CONSTRAINTS_FIELDS, | 8 | CONSTRAINTS_FIELDS, |
9 | VIDEO_CATEGORIES, | 9 | VIDEO_CATEGORIES, |
10 | VIDEO_LANGUAGES, | 10 | VIDEO_LANGUAGES, |
11 | VIDEO_LICENCES, | 11 | VIDEO_LICENCES, VIDEO_MIMETYPE_EXT, |
12 | VIDEO_PRIVACIES, | 12 | VIDEO_PRIVACIES, |
13 | VIDEO_RATE_TYPES | 13 | VIDEO_RATE_TYPES |
14 | } from '../../initializers' | 14 | } from '../../initializers' |
15 | import { VideoModel } from '../../models/video/video' | 15 | import { VideoModel } from '../../models/video/video' |
16 | import { exists, isArray } from './misc' | 16 | import { exists, isArray, isFileValid } from './misc' |
17 | 17 | ||
18 | const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS | 18 | const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS |
19 | const VIDEO_ABUSES_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_ABUSES | 19 | const VIDEO_ABUSES_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_ABUSES |
@@ -68,20 +68,18 @@ function isVideoRatingTypeValid (value: string) { | |||
68 | return value === 'none' || values(VIDEO_RATE_TYPES).indexOf(value as VideoRateType) !== -1 | 68 | return value === 'none' || values(VIDEO_RATE_TYPES).indexOf(value as VideoRateType) !== -1 |
69 | } | 69 | } |
70 | 70 | ||
71 | const videoFileTypes = Object.keys(VIDEO_MIMETYPE_EXT).map(m => `(${m})`) | ||
72 | const videoFileTypesRegex = videoFileTypes.join('|') | ||
71 | function isVideoFile (files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[]) { | 73 | function isVideoFile (files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[]) { |
72 | // Should have files | 74 | return isFileValid(files, videoFileTypesRegex, 'videofile') |
73 | if (!files) return false | 75 | } |
74 | if (isArray(files)) return false | ||
75 | |||
76 | // Should have videofile file | ||
77 | const videofile = files['videofile'] | ||
78 | if (!videofile || videofile.length === 0) return false | ||
79 | |||
80 | // The file should exist | ||
81 | const file = videofile[0] | ||
82 | if (!file || !file.originalname) return false | ||
83 | 76 | ||
84 | return new RegExp('^video/(webm|mp4|ogg)$', 'i').test(file.mimetype) | 77 | const videoImageTypes = CONSTRAINTS_FIELDS.VIDEOS.IMAGE.EXTNAME |
78 | .map(v => v.replace('.', '')) | ||
79 | .join('|') | ||
80 | const videoImageTypesRegex = `image/(${videoImageTypes})` | ||
81 | function isVideoImage (files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[], field: string) { | ||
82 | return isFileValid(files, videoImageTypesRegex, field, true) | ||
85 | } | 83 | } |
86 | 84 | ||
87 | function isVideoPrivacyValid (value: string) { | 85 | function isVideoPrivacyValid (value: string) { |
@@ -141,5 +139,6 @@ export { | |||
141 | isVideoPrivacyValid, | 139 | isVideoPrivacyValid, |
142 | isVideoFileResolutionValid, | 140 | isVideoFileResolutionValid, |
143 | isVideoFileSizeValid, | 141 | isVideoFileSizeValid, |
144 | isVideoExist | 142 | isVideoExist, |
143 | isVideoImage | ||
145 | } | 144 | } |