PeerTube/server/middlewares/validators/activitypub/pagination.ts

26 lines
711 B
TypeScript
Raw Normal View History

2021-08-27 14:32:44 +02:00
import express from 'express'
2020-01-09 00:43:52 +01:00
import { query } from 'express-validator'
import { PAGINATION } from '@server/initializers/constants'
import { areValidationErrors } from '../shared'
2020-01-09 00:43:52 +01:00
const apPaginationValidator = [
query('page')
.optional()
.isInt({ min: 1 }),
query('size')
.optional()
.isInt({ min: 0, max: PAGINATION.OUTBOX.COUNT.MAX }).withMessage(`Should have a valid page size (max: ${PAGINATION.OUTBOX.COUNT.MAX})`),
2020-01-09 00:43:52 +01:00
(req: express.Request, res: express.Response, next: express.NextFunction) => {
if (areValidationErrors(req, res)) return
return next()
}
]
// ---------------------------------------------------------------------------
export {
apPaginationValidator
}