X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmiddlewares%2Fpagination.ts;h=043869303f72f0139de9dcbd377a83fbdc89e276;hb=66a36740044242568ae7868842eb36a920b21544;hp=8fe9f9082b343886ceb063878018f004c7e7ae0f;hpb=65fcc3119c334b75dd13bcfdebf186afdc580a8f;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/middlewares/pagination.ts b/server/middlewares/pagination.ts index 8fe9f9082..043869303 100644 --- a/server/middlewares/pagination.ts +++ b/server/middlewares/pagination.ts @@ -1,17 +1,20 @@ -const constants = require('../initializers/constants') +import * as express from 'express' +import { PAGINATION } from '../initializers/constants' -function setPagination (req, res, next) { +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 }