PeerTube/server/middlewares/validators/pagination.ts

29 lines
876 B
TypeScript
Raw Normal View History

2017-06-10 20:15:25 +00:00
import * as express from 'express'
2019-07-25 14:23:44 +00:00
import { query } from 'express-validator'
2017-12-28 10:16:08 +00:00
import { logger } from '../../helpers/logger'
2017-11-27 16:30:46 +00:00
import { areValidationErrors } from './utils'
import { PAGINATION } from '@server/initializers/constants'
2017-09-15 10:17:08 +00:00
const paginationValidator = [
query('start')
.optional()
.isInt({ min: 0 }).withMessage('Should have a number start'),
query('count')
.optional()
.isInt({ min: 0, max: PAGINATION.GLOBAL.COUNT.MAX }).withMessage(`Should have a number count (max: ${PAGINATION.GLOBAL.COUNT.MAX})`),
2017-09-15 10:17:08 +00:00
(req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking pagination parameters', { parameters: req.query })
2017-11-27 16:30:46 +00:00
if (areValidationErrors(req, res)) return
return next()
2017-09-15 10:17:08 +00:00
}
]
// ---------------------------------------------------------------------------
2017-05-15 20:22:03 +00:00
export {
paginationValidator
}