X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmiddlewares%2Fvalidators%2Fvideos%2Fvideo-blacklist.ts;h=88c788a4309d6d9ea9c891288e0ef69ee6db66be;hb=4d7ce9218a3f695bf3d013cbdce1c5c6a5221927;hp=1d7ddb2e398603e9d160b96995c8852de46181ce;hpb=97567dd81f508dd6295ac4d73d849aa2ce0a6549;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/middlewares/validators/videos/video-blacklist.ts b/server/middlewares/validators/videos/video-blacklist.ts index 1d7ddb2e3..88c788a43 100644 --- a/server/middlewares/validators/videos/video-blacklist.ts +++ b/server/middlewares/validators/videos/video-blacklist.ts @@ -1,14 +1,11 @@ import * as express from 'express' -import { body, param, query } from 'express-validator/check' -import { isBooleanValid, isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' -import { doesVideoExist } from '../../../helpers/custom-validators/videos' +import { body, param, query } from 'express-validator' +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 { - doesVideoBlacklistExist, - isVideoBlacklistReasonValid, - isVideoBlacklistTypeValid -} from '../../../helpers/custom-validators/video-blacklist' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' const videosBlacklistRemoveValidator = [ param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), @@ -18,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() } @@ -28,7 +25,7 @@ const videosBlacklistAddValidator = [ param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), body('unfederate') .optional() - .toBoolean() + .customSanitizer(toBooleanOrNull) .custom(isBooleanValid).withMessage('Should have a valid unfederate boolean'), body('reason') .optional() @@ -40,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() } @@ -63,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() } @@ -71,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 })