diff options
Diffstat (limited to 'server/middlewares/validators/videos')
-rw-r--r-- | server/middlewares/validators/videos/videos.ts | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.ts index 9834f714b..8bc37b0ab 100644 --- a/server/middlewares/validators/videos/videos.ts +++ b/server/middlewares/validators/videos/videos.ts | |||
@@ -8,6 +8,7 @@ import { VideoChangeOwnershipAccept } from '../../../../shared/models/videos/vid | |||
8 | import { | 8 | import { |
9 | isBooleanValid, | 9 | isBooleanValid, |
10 | isDateValid, | 10 | isDateValid, |
11 | isFileFieldValid, | ||
11 | isIdOrUUIDValid, | 12 | isIdOrUUIDValid, |
12 | isIdValid, | 13 | isIdValid, |
13 | isUUIDValid, | 14 | isUUIDValid, |
@@ -22,7 +23,8 @@ import { | |||
22 | isScheduleVideoUpdatePrivacyValid, | 23 | isScheduleVideoUpdatePrivacyValid, |
23 | isVideoCategoryValid, | 24 | isVideoCategoryValid, |
24 | isVideoDescriptionValid, | 25 | isVideoDescriptionValid, |
25 | isVideoFile, | 26 | isVideoFileMimeTypeValid, |
27 | isVideoFileSizeValid, | ||
26 | isVideoFilterValid, | 28 | isVideoFilterValid, |
27 | isVideoImage, | 29 | isVideoImage, |
28 | isVideoLanguageValid, | 30 | isVideoLanguageValid, |
@@ -55,11 +57,11 @@ import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-c | |||
55 | 57 | ||
56 | const videosAddValidator = getCommonVideoEditAttributes().concat([ | 58 | const videosAddValidator = getCommonVideoEditAttributes().concat([ |
57 | body('videofile') | 59 | body('videofile') |
58 | .custom((value, { req }) => isVideoFile(req.files)).withMessage( | 60 | .custom((value, { req }) => isFileFieldValid(req.files, 'videofile')) |
59 | 'This file is not supported or too large. Please, make sure it is of the following type: ' + | 61 | .withMessage('Should have a file'), |
60 | CONSTRAINTS_FIELDS.VIDEOS.EXTNAME.join(', ') | 62 | body('name') |
61 | ), | 63 | .custom(isVideoNameValid) |
62 | body('name').custom(isVideoNameValid).withMessage('Should have a valid name'), | 64 | .withMessage('Should have a valid name'), |
63 | body('channelId') | 65 | body('channelId') |
64 | .customSanitizer(toIntOrNull) | 66 | .customSanitizer(toIntOrNull) |
65 | .custom(isIdValid).withMessage('Should have correct video channel id'), | 67 | .custom(isIdValid).withMessage('Should have correct video channel id'), |
@@ -75,8 +77,27 @@ const videosAddValidator = getCommonVideoEditAttributes().concat([ | |||
75 | 77 | ||
76 | if (!await doesVideoChannelOfAccountExist(req.body.channelId, user, res)) return cleanUpReqFiles(req) | 78 | if (!await doesVideoChannelOfAccountExist(req.body.channelId, user, res)) return cleanUpReqFiles(req) |
77 | 79 | ||
80 | if (!isVideoFileMimeTypeValid(req.files)) { | ||
81 | res.status(HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415) | ||
82 | .json({ | ||
83 | error: 'This file is not supported. Please, make sure it is of the following type: ' + | ||
84 | CONSTRAINTS_FIELDS.VIDEOS.EXTNAME.join(', ') | ||
85 | }) | ||
86 | |||
87 | return cleanUpReqFiles(req) | ||
88 | } | ||
89 | |||
90 | if (!isVideoFileSizeValid(videoFile.size.toString())) { | ||
91 | res.status(HttpStatusCode.PAYLOAD_TOO_LARGE_413) | ||
92 | .json({ | ||
93 | error: 'This file is too large.' | ||
94 | }) | ||
95 | |||
96 | return cleanUpReqFiles(req) | ||
97 | } | ||
98 | |||
78 | if (await isAbleToUploadVideo(user.id, videoFile.size) === false) { | 99 | if (await isAbleToUploadVideo(user.id, videoFile.size) === false) { |
79 | res.status(HttpStatusCode.FORBIDDEN_403) | 100 | res.status(HttpStatusCode.PAYLOAD_TOO_LARGE_413) |
80 | .json({ error: 'The user video quota is exceeded with this video.' }) | 101 | .json({ error: 'The user video quota is exceeded with this video.' }) |
81 | 102 | ||
82 | return cleanUpReqFiles(req) | 103 | return cleanUpReqFiles(req) |
@@ -88,8 +109,8 @@ const videosAddValidator = getCommonVideoEditAttributes().concat([ | |||
88 | duration = await getDurationFromVideoFile(videoFile.path) | 109 | duration = await getDurationFromVideoFile(videoFile.path) |
89 | } catch (err) { | 110 | } catch (err) { |
90 | logger.error('Invalid input file in videosAddValidator.', { err }) | 111 | logger.error('Invalid input file in videosAddValidator.', { err }) |
91 | res.status(HttpStatusCode.BAD_REQUEST_400) | 112 | res.status(HttpStatusCode.UNPROCESSABLE_ENTITY_422) |
92 | .json({ error: 'Invalid input file.' }) | 113 | .json({ error: 'Video file unreadable.' }) |
93 | 114 | ||
94 | return cleanUpReqFiles(req) | 115 | return cleanUpReqFiles(req) |
95 | } | 116 | } |
@@ -295,7 +316,7 @@ const videosAcceptChangeOwnershipValidator = [ | |||
295 | const videoChangeOwnership = res.locals.videoChangeOwnership | 316 | const videoChangeOwnership = res.locals.videoChangeOwnership |
296 | const isAble = await isAbleToUploadVideo(user.id, videoChangeOwnership.Video.getMaxQualityFile().size) | 317 | const isAble = await isAbleToUploadVideo(user.id, videoChangeOwnership.Video.getMaxQualityFile().size) |
297 | if (isAble === false) { | 318 | if (isAble === false) { |
298 | res.status(HttpStatusCode.FORBIDDEN_403) | 319 | res.status(HttpStatusCode.PAYLOAD_TOO_LARGE_413) |
299 | .json({ error: 'The user video quota is exceeded with this video.' }) | 320 | .json({ error: 'The user video quota is exceeded with this video.' }) |
300 | 321 | ||
301 | return | 322 | return |