+ 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'),
+
+ async (req: express.Request, res: express.Response, next: express.NextFunction) => {
+ logger.debug('Checking videosGet parameters', { parameters: req.params })
+
+ if (areValidationErrors(req, res)) return
+ if (!await isVideoExist(req.params.id, res)) return
+
+ const video = res.locals.video
+
+ // Video is not private, anyone can access it
+ if (video.privacy !== VideoPrivacy.PRIVATE) return next()
+
+ authenticate(req, res, () => {
+ if (video.VideoChannel.Account.userId !== res.locals.oauth.token.User.id) {
+ return res.status(403)
+ .json({ error: 'Cannot get this private video of another user' })
+ .end()