From fbc77eb648bda9add4634c08dbb6af48c3670b5d Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Thu, 9 Jan 2020 00:43:52 +0100 Subject: Add outbox page size parameter --- server/middlewares/validators/activitypub/index.ts | 1 + .../validators/activitypub/pagination.ts | 23 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 server/middlewares/validators/activitypub/pagination.ts (limited to 'server/middlewares') diff --git a/server/middlewares/validators/activitypub/index.ts b/server/middlewares/validators/activitypub/index.ts index 84d1107fc..159338d26 100644 --- a/server/middlewares/validators/activitypub/index.ts +++ b/server/middlewares/validators/activitypub/index.ts @@ -1,2 +1,3 @@ export * from './activity' export * from './signature' +export * from './pagination' diff --git a/server/middlewares/validators/activitypub/pagination.ts b/server/middlewares/validators/activitypub/pagination.ts new file mode 100644 index 000000000..8b32d3415 --- /dev/null +++ b/server/middlewares/validators/activitypub/pagination.ts @@ -0,0 +1,23 @@ +import * as express from 'express' +import { query } from 'express-validator' +import { logger } from '../../../helpers/logger' +import { areValidationErrors } from '../utils' + +const apPaginationValidator = [ + query('page').optional().isInt({ min: 1 }).withMessage('Should have a valid page number'), + query('size').optional().isInt({ max: 50 }).withMessage('Should have a valid page size (max: 50)'), + + (req: express.Request, res: express.Response, next: express.NextFunction) => { + logger.debug('Checking pagination parameters', { parameters: req.query }) + + if (areValidationErrors(req, res)) return + + return next() + } +] + +// --------------------------------------------------------------------------- + +export { + apPaginationValidator +} -- cgit v1.2.3