]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/middlewares/pagination.ts
Move controller in dedicated functions
[github/Chocobozzz/PeerTube.git] / server / middlewares / pagination.ts
1 import * as express from 'express'
2 import { PAGINATION } from '../initializers/constants'
3
4 function setDefaultPagination (req: express.Request, res: express.Response, next: express.NextFunction) {
5 if (!req.query.start) req.query.start = 0
6 else req.query.start = parseInt(req.query.start, 10)
7
8 if (!req.query.count) req.query.count = PAGINATION.COUNT.DEFAULT
9 else req.query.count = parseInt(req.query.count, 10)
10
11 if (req.query.count > PAGINATION.COUNT.MAX) req.query.count = PAGINATION.COUNT.MAX
12
13 return next()
14 }
15
16 // ---------------------------------------------------------------------------
17
18 export {
19 setDefaultPagination
20 }