aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-07-24 16:27:45 +0200
committerChocobozzz <me@florianbigard.com>2018-07-24 18:03:38 +0200
commit1194e8b46f53204967271f1c6bfb7428a717a483 (patch)
tree2a89501df534747db4d261f39a6d279ac0e8fba9 /server
parent76dd3e89ae4f0f4a6652083f653a49acc97797fc (diff)
downloadPeerTube-1194e8b46f53204967271f1c6bfb7428a717a483.tar.gz
PeerTube-1194e8b46f53204967271f1c6bfb7428a717a483.tar.zst
PeerTube-1194e8b46f53204967271f1c6bfb7428a717a483.zip
Add max count in pagination
Diffstat (limited to 'server')
-rw-r--r--server/initializers/constants.ts10
-rw-r--r--server/middlewares/pagination.ts6
2 files changed, 11 insertions, 5 deletions
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts
index e8e0da683..85c5335ad 100644
--- a/server/initializers/constants.ts
+++ b/server/initializers/constants.ts
@@ -21,8 +21,12 @@ const LAST_MIGRATION_VERSION = 235
21// API version 21// API version
22const API_VERSION = 'v1' 22const API_VERSION = 'v1'
23 23
24// Number of results by default for the pagination 24const PAGINATION = {
25const PAGINATION_COUNT_DEFAULT = 15 25 COUNT: {
26 DEFAULT: 15,
27 MAX: 100
28 }
29}
26 30
27// Sortable columns per schema 31// Sortable columns per schema
28const SORTABLE_COLUMNS = { 32const SORTABLE_COLUMNS = {
@@ -539,7 +543,7 @@ export {
539 OAUTH_LIFETIME, 543 OAUTH_LIFETIME,
540 CUSTOM_HTML_TAG_COMMENTS, 544 CUSTOM_HTML_TAG_COMMENTS,
541 BROADCAST_CONCURRENCY, 545 BROADCAST_CONCURRENCY,
542 PAGINATION_COUNT_DEFAULT, 546 PAGINATION,
543 ACTOR_FOLLOW_SCORE, 547 ACTOR_FOLLOW_SCORE,
544 PREVIEWS_SIZE, 548 PREVIEWS_SIZE,
545 REMOTE_SCHEME, 549 REMOTE_SCHEME,
diff --git a/server/middlewares/pagination.ts b/server/middlewares/pagination.ts
index 2ea2a6b82..9b497b19e 100644
--- a/server/middlewares/pagination.ts
+++ b/server/middlewares/pagination.ts
@@ -1,15 +1,17 @@
1import 'express-validator' 1import 'express-validator'
2import * as express from 'express' 2import * as express from 'express'
3 3
4import { PAGINATION_COUNT_DEFAULT } from '../initializers' 4import { PAGINATION } from '../initializers'
5 5
6function setDefaultPagination (req: express.Request, res: express.Response, next: express.NextFunction) { 6function setDefaultPagination (req: express.Request, res: express.Response, next: express.NextFunction) {
7 if (!req.query.start) req.query.start = 0 7 if (!req.query.start) req.query.start = 0
8 else req.query.start = parseInt(req.query.start, 10) 8 else req.query.start = parseInt(req.query.start, 10)
9 9
10 if (!req.query.count) req.query.count = PAGINATION_COUNT_DEFAULT 10 if (!req.query.count) req.query.count = PAGINATION.COUNT.DEFAULT
11 else req.query.count = parseInt(req.query.count, 10) 11 else req.query.count = parseInt(req.query.count, 10)
12 12
13 if (req.query.count > PAGINATION.COUNT.MAX) req.query.count = PAGINATION.COUNT.MAX
14
13 return next() 15 return next()
14} 16}
15 17