]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/validators/pagination.ts
Split ffmpeg utils with ffprobe utils
[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
b60e5f38 7const paginationValidator = [
e0b56b74
C
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})`),
fbf1134e 14
b60e5f38
C
15 (req: express.Request, res: express.Response, next: express.NextFunction) => {
16 logger.debug('Checking pagination parameters', { parameters: req.query })
fbf1134e 17
a2431b7d
C
18 if (areValidationErrors(req, res)) return
19
20 return next()
b60e5f38
C
21 }
22]
fbf1134e
C
23
24// ---------------------------------------------------------------------------
25
65fcc311
C
26export {
27 paginationValidator
28}