-function videosUpdateValidator (req: express.Request, res: express.Response, next: express.NextFunction) {
- req.checkParams('id', 'Should have a valid id').notEmpty().isVideoIdOrUUIDValid()
- req.checkBody('name', 'Should have a valid name').optional().isVideoNameValid()
- req.checkBody('category', 'Should have a valid category').optional().isVideoCategoryValid()
- req.checkBody('licence', 'Should have a valid licence').optional().isVideoLicenceValid()
- req.checkBody('language', 'Should have a valid language').optional().isVideoLanguageValid()
- req.checkBody('nsfw', 'Should have a valid NSFW attribute').optional().isVideoNSFWValid()
- req.checkBody('description', 'Should have a valid description').optional().isVideoDescriptionValid()
- req.checkBody('tags', 'Should have correct tags').optional().isVideoTagsValid()
-
- logger.debug('Checking videosUpdate parameters', { parameters: req.body })
-
- checkErrors(req, res, () => {
- checkVideoExists(req.params.id, res, () => {
- // We need to make additional checks
- if (res.locals.video.isOwned() === false) {
- return res.status(403)
- .json({ error: 'Cannot update video of another pod' })
- .end()
- }
+ return
+ }
+
+ res.locals.videoChannel = videoChannel
+
+ const isAble = await user.isAbleToUploadVideo(videoFile)
+ if (isAble === false) {
+ res.status(403)
+ .json({ error: 'The user video quota is exceeded with this video.' })
+ .end()
+
+ return
+ }
+
+ let duration: number
+
+ try {
+ duration = await getDurationFromVideoFile(videoFile.path)
+ } catch (err) {
+ logger.error('Invalid input file in videosAddValidator.', err)
+ res.status(400)
+ .json({ error: 'Invalid input file.' })
+ .end()
+
+ return
+ }
+
+ videoFile['duration'] = duration
+
+ return next()
+ }
+]
+
+const videosUpdateValidator = [
+ param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
+ body('name').optional().custom(isVideoNameValid).withMessage('Should have a valid name'),
+ body('category').optional().custom(isVideoCategoryValid).withMessage('Should have a valid category'),
+ body('licence').optional().custom(isVideoLicenceValid).withMessage('Should have a valid licence'),
+ body('language').optional().custom(isVideoLanguageValid).withMessage('Should have a valid language'),
+ body('nsfw').optional().custom(isVideoNSFWValid).withMessage('Should have a valid NSFW attribute'),
+ body('privacy').optional().custom(isVideoPrivacyValid).withMessage('Should have correct video privacy'),
+ body('description').optional().custom(isVideoDescriptionValid).withMessage('Should have a valid description'),
+ body('tags').optional().custom(isVideoTagsValid).withMessage('Should have correct tags'),
+
+ async (req: express.Request, res: express.Response, next: express.NextFunction) => {
+ logger.debug('Checking videosUpdate parameters', { parameters: req.body })
+
+ if (areValidationErrors(req, res)) return
+ if (!await isVideoExist(req.params.id, res)) return
+
+ const video = res.locals.video
+
+ // We need to make additional checks
+ if (video.isOwned() === false) {
+ return res.status(403)
+ .json({ error: 'Cannot update video of another server' })
+ .end()
+ }
+
+ if (video.VideoChannel.Account.userId !== res.locals.oauth.token.User.id) {
+ return res.status(403)
+ .json({ error: 'Cannot update video of another user' })
+ .end()
+ }
+
+ if (video.privacy !== VideoPrivacy.PRIVATE && req.body.privacy === VideoPrivacy.PRIVATE) {
+ return res.status(409)
+ .json({ error: 'Cannot set "private" a video that was not private anymore.' })
+ .end()
+ }
+
+ return next()
+ }
+]
+
+const videosGetValidator = [
+ param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),