X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmiddlewares%2Fvalidators%2Fvideos%2Fvideos.ts;h=a027c4840ef3861643b20ae6355170075fc3d197;hb=943e5193905908dd1f2800d8810c635d86e3b28f;hp=00ee375cb7f549970df88c4788edf456c777987d;hpb=cf59a2a0c367683ba35758419499bf6087c192ec;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.ts index 00ee375cb..a027c4840 100644 --- a/server/middlewares/validators/videos/videos.ts +++ b/server/middlewares/validators/videos/videos.ts @@ -49,8 +49,8 @@ import { getVideoWithAttributes } from '../../../helpers/video' 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') @@ -81,7 +81,7 @@ const videosAddValidator = getCommonVideoEditAttributes().concat([ 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) @@ -147,7 +147,10 @@ async function checkVideoFollowConstraints (req: express.Request, res: express.R }) } -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'), @@ -157,6 +160,9 @@ const videosCustomGetValidator = (fetchType: 'all' | 'only-video' | 'only-video- 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 @@ -245,19 +251,15 @@ const videosTerminateChangeOwnershipValidator = [ // 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() } ] @@ -284,14 +286,14 @@ function getCommonVideoEditAttributes () { 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()