const videosAddValidator = getCommonVideoEditAttributes().concat([
body('videofile')
.custom((value, { req }) => isVideoFile(req.files)).withMessage(
- 'This file is not supported or too large. Please, make sure it is of the following type: '
- + CONSTRAINTS_FIELDS.VIDEOS.EXTNAME.join(', ')
+ 'This file is not supported or too large. Please, make sure it is of the following type: ' +
+ CONSTRAINTS_FIELDS.VIDEOS.EXTNAME.join(', ')
),
body('name').custom(isVideoNameValid).withMessage('Should have a valid name'),
body('channelId')
duration = await getDurationFromVideoFile(videoFile.path)
} catch (err) {
logger.error('Invalid input file in videosAddValidator.', { err })
- res.status(422)
+ res.status(400)
.json({ error: 'Invalid input file.' })
return cleanUpReqFiles(req)
})
}
-const videosCustomGetValidator = (fetchType: 'all' | 'only-video' | 'only-video-with-rights', authenticateInQuery = false) => {
+const videosCustomGetValidator = (
+ fetchType: 'all' | 'only-video' | 'only-video-with-rights' | 'only-immutable-attributes',
+ authenticateInQuery = false
+) => {
return [
param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
if (areValidationErrors(req, res)) return
if (!await doesVideoExist(req.params.id, res, fetchType)) return
+ // Controllers does not need to check video rights
+ if (fetchType === 'only-immutable-attributes') return next()
+
const video = getVideoWithAttributes(res)
const videoAll = video as MVideoFullLight
// Check if the user who did the request is able to change the ownership of the video
if (!checkUserCanTerminateOwnershipChange(res.locals.oauth.token.User, res.locals.videoChangeOwnership, res)) return
- return next()
- },
- async (req: express.Request, res: express.Response, next: express.NextFunction) => {
const videoChangeOwnership = res.locals.videoChangeOwnership
- if (videoChangeOwnership.status === VideoChangeOwnershipStatus.WAITING) {
- return next()
- } else {
+ if (videoChangeOwnership.status !== VideoChangeOwnershipStatus.WAITING) {
res.status(403)
- .json({ error: 'Ownership already accepted or refused' })
-
+ .json({ error: 'Ownership already accepted or refused' })
return
}
+
+ return next()
}
]
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(', ')
- ),
+ '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(', ')
- ),
+ '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()