X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmiddlewares%2Fvalidators%2Fvideos%2Fvideo-comments.ts;h=55fb60b98e10cbcf3490003c54309e9041d81a5b;hb=0f8d00e3144060270d7fe603865fccaf18649c47;hp=77f5c6ff3c5dd5bf41c51951308dc8e8fefda410;hpb=dc13623baa244e13c33cc803de808818ef1e95a4;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/middlewares/validators/videos/video-comments.ts b/server/middlewares/validators/videos/video-comments.ts index 77f5c6ff3..55fb60b98 100644 --- a/server/middlewares/validators/videos/video-comments.ts +++ b/server/middlewares/validators/videos/video-comments.ts @@ -1,8 +1,8 @@ import * as express from 'express' -import { body, param } from 'express-validator' +import { body, param, query } from 'express-validator' import { MUserAccountUrl } from '@server/types/models' import { UserRight } from '../../../../shared' -import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' +import { exists, isBooleanValid, isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' import { doesVideoCommentExist, doesVideoCommentThreadExist, @@ -15,6 +15,33 @@ import { Hooks } from '../../../lib/plugins/hooks' import { MCommentOwnerVideoReply, MVideo, MVideoFullLight } from '../../../types/models/video' import { areValidationErrors } from '../utils' +const listVideoCommentsValidator = [ + query('isLocal') + .optional() + .custom(isBooleanValid) + .withMessage('Should have a valid is local boolean'), + + query('search') + .optional() + .custom(exists).withMessage('Should have a valid search'), + + query('searchAccount') + .optional() + .custom(exists).withMessage('Should have a valid account search'), + + query('searchVideo') + .optional() + .custom(exists).withMessage('Should have a valid video search'), + + (req: express.Request, res: express.Response, next: express.NextFunction) => { + logger.debug('Checking listVideoCommentsValidator parameters.', { parameters: req.query }) + + if (areValidationErrors(req, res)) return + + return next() + } +] + const listVideoCommentThreadsValidator = [ param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), @@ -116,6 +143,7 @@ export { listVideoCommentThreadsValidator, listVideoThreadCommentsValidator, addVideoCommentThreadValidator, + listVideoCommentsValidator, addVideoCommentReplyValidator, videoCommentGetValidator, removeVideoCommentValidator