X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmiddlewares%2Fvalidators%2Fvideos%2Fvideo-rates.ts;h=275634d5bdf02ddf8431d8520f98b52602983e26;hb=cb0eda5602a21d1626a7face32de6153ed07b5f9;hp=923bf3eaf9fe02da1ede9e845015a9a71f020afd;hpb=6ea9295b8f5dd7cc254202a79aad61c666cc4259;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/middlewares/validators/videos/video-rates.ts b/server/middlewares/validators/videos/video-rates.ts index 923bf3eaf..275634d5b 100644 --- a/server/middlewares/validators/videos/video-rates.ts +++ b/server/middlewares/validators/videos/video-rates.ts @@ -6,27 +6,20 @@ import { isAccountNameValid } from '../../../helpers/custom-validators/accounts' import { isIdValid } from '../../../helpers/custom-validators/misc' import { isRatingValid } from '../../../helpers/custom-validators/video-rates' import { isVideoRatingTypeValid } from '../../../helpers/custom-validators/videos' -import { logger } from '../../../helpers/logger' import { AccountVideoRateModel } from '../../../models/account/account-video-rate' -import { areValidationErrors, checkCanSeeVideoIfPrivate, doesVideoExist, isValidVideoIdParam } from '../shared' +import { areValidationErrors, checkCanSeeVideo, doesVideoExist, isValidVideoIdParam } from '../shared' const videoUpdateRateValidator = [ isValidVideoIdParam('id'), - body('rating').custom(isVideoRatingTypeValid).withMessage('Should have a valid rate type'), + body('rating') + .custom(isVideoRatingTypeValid), async (req: express.Request, res: express.Response, next: express.NextFunction) => { - logger.debug('Checking videoRate parameters', { parameters: req.body }) - if (areValidationErrors(req, res)) return if (!await doesVideoExist(req.params.id, res)) return - if (!await checkCanSeeVideoIfPrivate(req, res, res.locals.videoAll)) { - return res.fail({ - status: HttpStatusCode.FORBIDDEN_403, - message: 'Cannot access to this ressource' - }) - } + if (!await checkCanSeeVideo({ req, res, paramId: req.params.id, video: res.locals.videoAll })) return return next() } @@ -34,12 +27,12 @@ const videoUpdateRateValidator = [ const getAccountVideoRateValidatorFactory = function (rateType: VideoRateType) { return [ - param('name').custom(isAccountNameValid).withMessage('Should have a valid account name'), - param('videoId').custom(isIdValid).not().isEmpty().withMessage('Should have a valid videoId'), + param('name') + .custom(isAccountNameValid), + param('videoId') + .custom(isIdValid), async (req: express.Request, res: express.Response, next: express.NextFunction) => { - logger.debug('Checking videoCommentGetValidator parameters.', { parameters: req.params }) - if (areValidationErrors(req, res)) return const rate = await AccountVideoRateModel.loadLocalAndPopulateVideo(rateType, req.params.name, +req.params.videoId) @@ -58,11 +51,11 @@ const getAccountVideoRateValidatorFactory = function (rateType: VideoRateType) { } const videoRatingValidator = [ - query('rating').optional().custom(isRatingValid).withMessage('Value must be one of "like" or "dislike"'), + query('rating') + .optional() + .custom(isRatingValid).withMessage('Value must be one of "like" or "dislike"'), (req: express.Request, res: express.Response, next: express.NextFunction) => { - logger.debug('Checking rating parameter', { parameters: req.params }) - if (areValidationErrors(req, res)) return return next()