X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmiddlewares%2Fpagination.ts;h=9b497b19e78dfe778a0cf8f2276e3beec49b027c;hb=590fb5069038e69898123bb795f789683216d837;hp=8fe9f9082b343886ceb063878018f004c7e7ae0f;hpb=65fcc3119c334b75dd13bcfdebf186afdc580a8f;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/middlewares/pagination.ts b/server/middlewares/pagination.ts index 8fe9f9082..9b497b19e 100644 --- a/server/middlewares/pagination.ts +++ b/server/middlewares/pagination.ts @@ -1,17 +1,22 @@ -const constants = require('../initializers/constants') +import 'express-validator' +import * as express from 'express' -function setPagination (req, res, next) { +import { PAGINATION } from '../initializers' + +function setDefaultPagination (req: express.Request, res: express.Response, next: express.NextFunction) { if (!req.query.start) req.query.start = 0 else req.query.start = parseInt(req.query.start, 10) - if (!req.query.count) req.query.count = constants.PAGINATION_COUNT_DEFAULT + if (!req.query.count) req.query.count = PAGINATION.COUNT.DEFAULT else req.query.count = parseInt(req.query.count, 10) + if (req.query.count > PAGINATION.COUNT.MAX) req.query.count = PAGINATION.COUNT.MAX + return next() } // --------------------------------------------------------------------------- export { - setPagination + setDefaultPagination }