]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/validators/pagination.ts
Merge branch 'release/3.2.0' into develop
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / pagination.ts
CommitLineData
69818c93 1import * as express from 'express'
c8861d5d 2import { query } from 'express-validator'
da854ddd 3import { logger } from '../../helpers/logger'
a2431b7d 4import { areValidationErrors } from './utils'
e0b56b74 5import { PAGINATION } from '@server/initializers/constants'
fbf1134e 6
18b24b2d 7const paginationValidator = paginationValidatorBuilder()
fbf1134e 8
18b24b2d
C
9function paginationValidatorBuilder (tags: string[] = []) {
10 return [
11 query('start')
12 .optional()
13 .isInt({ min: 0 }).withMessage('Should have a number start'),
14 query('count')
15 .optional()
16 .isInt({ min: 0, max: PAGINATION.GLOBAL.COUNT.MAX }).withMessage(`Should have a number count (max: ${PAGINATION.GLOBAL.COUNT.MAX})`),
fbf1134e 17
18b24b2d
C
18 (req: express.Request, res: express.Response, next: express.NextFunction) => {
19 logger.debug('Checking pagination parameters', { parameters: req.query, tags })
a2431b7d 20
18b24b2d
C
21 if (areValidationErrors(req, res)) return
22
23 return next()
24 }
25 ]
26}
fbf1134e
C
27
28// ---------------------------------------------------------------------------
29
65fcc311 30export {
18b24b2d
C
31 paginationValidator,
32 paginationValidatorBuilder
65fcc311 33}