]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/validators/pagination.ts
Support studio transcoding in peertube runner
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / pagination.ts
CommitLineData
41fb13c3 1import express from 'express'
c8861d5d 2import { query } from 'express-validator'
e0b56b74 3import { PAGINATION } from '@server/initializers/constants'
10363c74 4import { areValidationErrors } from './shared'
fbf1134e 5
18b24b2d 6const paginationValidator = paginationValidatorBuilder()
fbf1134e 7
18b24b2d
C
8function paginationValidatorBuilder (tags: string[] = []) {
9 return [
10 query('start')
11 .optional()
396f6f01 12 .isInt({ min: 0 }),
18b24b2d
C
13 query('count')
14 .optional()
15 .isInt({ min: 0, max: PAGINATION.GLOBAL.COUNT.MAX }).withMessage(`Should have a number count (max: ${PAGINATION.GLOBAL.COUNT.MAX})`),
fbf1134e 16
18b24b2d 17 (req: express.Request, res: express.Response, next: express.NextFunction) => {
a85d5303 18 if (areValidationErrors(req, res, { tags })) return
18b24b2d
C
19
20 return next()
21 }
22 ]
23}
fbf1134e
C
24
25// ---------------------------------------------------------------------------
26
65fcc311 27export {
18b24b2d
C
28 paginationValidator,
29 paginationValidatorBuilder
65fcc311 30}