X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmiddlewares%2Fvalidators%2Fvideos%2Fvideo-blacklist.ts;h=f065f101ccf87af7bdbae42f463d02a823d20ee5;hb=396f6f0140b0f76162e2378fd5a61e2f888673ed;hp=88c788a4309d6d9ea9c891288e0ef69ee6db66be;hpb=2d53be0267acc49cda46707b885096193a1f4e9c;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/middlewares/validators/videos/video-blacklist.ts b/server/middlewares/validators/videos/video-blacklist.ts index 88c788a43..f065f101c 100644 --- a/server/middlewares/validators/videos/video-blacklist.ts +++ b/server/middlewares/validators/videos/video-blacklist.ts @@ -1,14 +1,13 @@ -import * as express from 'express' -import { body, param, query } from 'express-validator' -import { isBooleanValid, isIdOrUUIDValid, toBooleanOrNull, toIntOrNull } from '../../../helpers/custom-validators/misc' +import express from 'express' +import { body, query } from 'express-validator' +import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' +import { isBooleanValid, 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' +import { areValidationErrors, doesVideoBlacklistExist, doesVideoExist, isValidVideoIdParam } from '../shared' const videosBlacklistRemoveValidator = [ - param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), + isValidVideoIdParam('videoId'), async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking blacklistRemove parameters.', { parameters: req.params }) @@ -22,14 +21,15 @@ const videosBlacklistRemoveValidator = [ ] const videosBlacklistAddValidator = [ - param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), + isValidVideoIdParam('videoId'), + body('unfederate') .optional() .customSanitizer(toBooleanOrNull) .custom(isBooleanValid).withMessage('Should have a valid unfederate boolean'), body('reason') .optional() - .custom(isVideoBlacklistReasonValid).withMessage('Should have a valid reason'), + .custom(isVideoBlacklistReasonValid), async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking videosBlacklistAdd parameters', { parameters: req.params }) @@ -39,10 +39,10 @@ const videosBlacklistAddValidator = [ const video = res.locals.videoAll if (req.body.unfederate === true && video.remote === true) { - return res - .status(HttpStatusCode.CONFLICT_409) - .send({ error: 'You cannot unfederate a remote video.' }) - .end() + return res.fail({ + status: HttpStatusCode.CONFLICT_409, + message: 'You cannot unfederate a remote video.' + }) } return next() @@ -50,7 +50,8 @@ const videosBlacklistAddValidator = [ ] const videosBlacklistUpdateValidator = [ - param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), + isValidVideoIdParam('videoId'), + body('reason') .optional() .custom(isVideoBlacklistReasonValid).withMessage('Should have a valid reason'),