+ if (videoChangeOwnership.status === VideoChangeOwnershipStatus.WAITING) {
+ return next()
+ } else {
+ res.status(403)
+ .json({ error: 'Ownership already accepted or refused' })
+ .end()
+ return
+ }
+ }
+]
+
+const videosAcceptChangeOwnershipValidator = [
+ async (req: express.Request, res: express.Response, next: express.NextFunction) => {
+ const body = req.body as VideoChangeOwnershipAccept
+ if (!await isVideoChannelOfAccountExist(body.channelId, res.locals.oauth.token.User, res)) return
+
+ const user = res.locals.oauth.token.User
+ const videoChangeOwnership = res.locals.videoChangeOwnership as VideoChangeOwnershipModel
+ const isAble = await user.isAbleToUploadVideo(videoChangeOwnership.Video.getOriginalFile())
+ if (isAble === false) {
+ res.status(403)
+ .json({ error: 'The user video quota is exceeded with this video.' })
+ .end()
+ return
+ }
+
+ return next()
+ }
+]
+
+function getCommonVideoAttributes () {
+ return [
+ body('thumbnailfile')
+ .custom((value, { req }) => isVideoImage(req.files, 'thumbnailfile')).withMessage(
+ 'This thumbnail file is not supported or too large. Please, make sure it is of the following type: '
+ + CONSTRAINTS_FIELDS.VIDEOS.IMAGE.EXTNAME.join(', ')
+ ),
+ body('previewfile')
+ .custom((value, { req }) => isVideoImage(req.files, 'previewfile')).withMessage(
+ 'This preview file is not supported or too large. Please, make sure it is of the following type: '
+ + CONSTRAINTS_FIELDS.VIDEOS.IMAGE.EXTNAME.join(', ')
+ ),
+
+ body('category')
+ .optional()
+ .customSanitizer(toIntOrNull)
+ .custom(isVideoCategoryValid).withMessage('Should have a valid category'),
+ body('licence')
+ .optional()
+ .customSanitizer(toIntOrNull)
+ .custom(isVideoLicenceValid).withMessage('Should have a valid licence'),
+ body('language')
+ .optional()
+ .customSanitizer(toValueOrNull)
+ .custom(isVideoLanguageValid).withMessage('Should have a valid language'),
+ body('nsfw')
+ .optional()
+ .toBoolean()
+ .custom(isBooleanValid).withMessage('Should have a valid NSFW attribute'),
+ body('waitTranscoding')
+ .optional()
+ .toBoolean()
+ .custom(isBooleanValid).withMessage('Should have a valid wait transcoding attribute'),
+ body('privacy')
+ .optional()
+ .toInt()
+ .custom(isVideoPrivacyValid).withMessage('Should have correct video privacy'),
+ body('description')
+ .optional()
+ .customSanitizer(toValueOrNull)
+ .custom(isVideoDescriptionValid).withMessage('Should have a valid description'),
+ body('support')
+ .optional()
+ .customSanitizer(toValueOrNull)
+ .custom(isVideoSupportValid).withMessage('Should have a valid support text'),
+ body('tags')
+ .optional()
+ .customSanitizer(toValueOrNull)
+ .custom(isVideoTagsValid).withMessage('Should have correct tags'),
+ body('commentsEnabled')
+ .optional()
+ .toBoolean()
+ .custom(isBooleanValid).withMessage('Should have comments enabled boolean'),
+
+ body('scheduleUpdate')
+ .optional()
+ .customSanitizer(toValueOrNull),
+ body('scheduleUpdate.updateAt')
+ .optional()
+ .custom(isDateValid).withMessage('Should have a valid schedule update date'),
+ body('scheduleUpdate.privacy')
+ .optional()
+ .toInt()
+ .custom(isScheduleVideoUpdatePrivacyValid).withMessage('Should have correct schedule update privacy')
+ ] as (ValidationChain | express.Handler)[]