X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmiddlewares%2Fvalidators%2Fpagination.ts;h=79ddbbf184d42c0c36be7c538a36f7ae3dc7f44a;hb=8ca52bcc2c37d457e8b19a237c66b8dd1c00b6b9;hp=80ae57c0bba7d790130cf7f31d406be29a2c92e1;hpb=c8861d5dc0436ef4342ce517241e3591fa256a13;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/middlewares/validators/pagination.ts b/server/middlewares/validators/pagination.ts index 80ae57c0b..79ddbbf18 100644 --- a/server/middlewares/validators/pagination.ts +++ b/server/middlewares/validators/pagination.ts @@ -1,23 +1,30 @@ -import * as express from 'express' +import express from 'express' import { query } from 'express-validator' -import { logger } from '../../helpers/logger' -import { areValidationErrors } from './utils' +import { PAGINATION } from '@server/initializers/constants' +import { areValidationErrors } from './shared' -const paginationValidator = [ - query('start').optional().isInt({ min: 0 }).withMessage('Should have a number start'), - query('count').optional().isInt({ min: 0 }).withMessage('Should have a number count'), +const paginationValidator = paginationValidatorBuilder() - (req: express.Request, res: express.Response, next: express.NextFunction) => { - logger.debug('Checking pagination parameters', { parameters: req.query }) +function paginationValidatorBuilder (tags: string[] = []) { + return [ + query('start') + .optional() + .isInt({ min: 0 }), + query('count') + .optional() + .isInt({ min: 0, max: PAGINATION.GLOBAL.COUNT.MAX }).withMessage(`Should have a number count (max: ${PAGINATION.GLOBAL.COUNT.MAX})`), - if (areValidationErrors(req, res)) return + (req: express.Request, res: express.Response, next: express.NextFunction) => { + if (areValidationErrors(req, res, { tags })) return - return next() - } -] + return next() + } + ] +} // --------------------------------------------------------------------------- export { - paginationValidator + paginationValidator, + paginationValidatorBuilder }