X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmiddlewares%2Fvalidators%2Fvideos%2Fvideo-blacklist.ts;h=88c788a4309d6d9ea9c891288e0ef69ee6db66be;hb=4d7ce9218a3f695bf3d013cbdce1c5c6a5221927;hp=3e8c5b30c96942b4f0de830b0a906206dd0456d8;hpb=c8861d5dc0436ef4342ce517241e3591fa256a13;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/middlewares/validators/videos/video-blacklist.ts b/server/middlewares/validators/videos/video-blacklist.ts index 3e8c5b30c..88c788a43 100644 --- a/server/middlewares/validators/videos/video-blacklist.ts +++ b/server/middlewares/validators/videos/video-blacklist.ts @@ -1,10 +1,11 @@ import * as express from 'express' import { body, param, query } from 'express-validator' -import { isBooleanValid, isIdOrUUIDValid, toBooleanOrNull } from '../../../helpers/custom-validators/misc' -import { logger } from '../../../helpers/logger' -import { areValidationErrors } from '../utils' +import { isBooleanValid, isIdOrUUIDValid, toBooleanOrNull, toIntOrNull } from '../../../helpers/custom-validators/misc' import { isVideoBlacklistReasonValid, isVideoBlacklistTypeValid } from '../../../helpers/custom-validators/video-blacklist' +import { logger } from '../../../helpers/logger' import { doesVideoBlacklistExist, doesVideoExist } from '../../../helpers/middlewares' +import { areValidationErrors } from '../utils' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' const videosBlacklistRemoveValidator = [ param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), @@ -14,7 +15,7 @@ const videosBlacklistRemoveValidator = [ if (areValidationErrors(req, res)) return if (!await doesVideoExist(req.params.videoId, res)) return - if (!await doesVideoBlacklistExist(res.locals.video.id, res)) return + if (!await doesVideoBlacklistExist(res.locals.videoAll.id, res)) return return next() } @@ -36,10 +37,10 @@ const videosBlacklistAddValidator = [ if (areValidationErrors(req, res)) return if (!await doesVideoExist(req.params.videoId, res)) return - const video = res.locals.video + const video = res.locals.videoAll if (req.body.unfederate === true && video.remote === true) { return res - .status(409) + .status(HttpStatusCode.CONFLICT_409) .send({ error: 'You cannot unfederate a remote video.' }) .end() } @@ -59,7 +60,7 @@ const videosBlacklistUpdateValidator = [ if (areValidationErrors(req, res)) return if (!await doesVideoExist(req.params.videoId, res)) return - if (!await doesVideoBlacklistExist(res.locals.video.id, res)) return + if (!await doesVideoBlacklistExist(res.locals.videoAll.id, res)) return return next() } @@ -67,8 +68,13 @@ const videosBlacklistUpdateValidator = [ const videosBlacklistFiltersValidator = [ query('type') - .optional() + .optional() + .customSanitizer(toIntOrNull) .custom(isVideoBlacklistTypeValid).withMessage('Should have a valid video blacklist type attribute'), + query('search') + .optional() + .not() + .isEmpty().withMessage('Should have a valid search'), (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking videos blacklist filters query', { parameters: req.query })