allow limiting video-comments rss feeds to an account or video channel
[oweals/peertube.git] / server / middlewares / validators / pagination.ts
1 import * as express from 'express'
2 import { query } from 'express-validator'
3 import { logger } from '../../helpers/logger'
4 import { areValidationErrors } from './utils'
5 import { PAGINATION } from '@server/initializers/constants'
6
7 const paginationValidator = [
8   query('start')
9     .optional()
10     .isInt({ min: 0 }).withMessage('Should have a number start'),
11   query('count')
12     .optional()
13     .isInt({ min: 0, max: PAGINATION.GLOBAL.COUNT.MAX }).withMessage(`Should have a number count (max: ${PAGINATION.GLOBAL.COUNT.MAX})`),
14
15   (req: express.Request, res: express.Response, next: express.NextFunction) => {
16     logger.debug('Checking pagination parameters', { parameters: req.query })
17
18     if (areValidationErrors(req, res)) return
19
20     return next()
21   }
22 ]
23
24 // ---------------------------------------------------------------------------
25
26 export {
27   paginationValidator
28 }