diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2020-01-09 00:43:52 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-01-09 09:21:35 +0100 |
commit | fbc77eb648bda9add4634c08dbb6af48c3670b5d (patch) | |
tree | cb2c32e33031490027210cf7e29cc98b519b2f83 /server/middlewares/validators | |
parent | c08579e14fe712cb2264a25daea956e682574335 (diff) | |
download | PeerTube-fbc77eb648bda9add4634c08dbb6af48c3670b5d.tar.gz PeerTube-fbc77eb648bda9add4634c08dbb6af48c3670b5d.tar.zst PeerTube-fbc77eb648bda9add4634c08dbb6af48c3670b5d.zip |
Add outbox page size parameter
Diffstat (limited to 'server/middlewares/validators')
-rw-r--r-- | server/middlewares/validators/activitypub/index.ts | 1 | ||||
-rw-r--r-- | server/middlewares/validators/activitypub/pagination.ts | 23 |
2 files changed, 24 insertions, 0 deletions
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 @@ | |||
1 | export * from './activity' | 1 | export * from './activity' |
2 | export * from './signature' | 2 | export * from './signature' |
3 | 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 @@ | |||
1 | import * as express from 'express' | ||
2 | import { query } from 'express-validator' | ||
3 | import { logger } from '../../../helpers/logger' | ||
4 | import { areValidationErrors } from '../utils' | ||
5 | |||
6 | const apPaginationValidator = [ | ||
7 | query('page').optional().isInt({ min: 1 }).withMessage('Should have a valid page number'), | ||
8 | query('size').optional().isInt({ max: 50 }).withMessage('Should have a valid page size (max: 50)'), | ||
9 | |||
10 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
11 | logger.debug('Checking pagination parameters', { parameters: req.query }) | ||
12 | |||
13 | if (areValidationErrors(req, res)) return | ||
14 | |||
15 | return next() | ||
16 | } | ||
17 | ] | ||
18 | |||
19 | // --------------------------------------------------------------------------- | ||
20 | |||
21 | export { | ||
22 | apPaginationValidator | ||
23 | } | ||