Add max count in pagination
authorChocobozzz <me@florianbigard.com>
Tue, 24 Jul 2018 14:27:45 +0000 (16:27 +0200)
committerChocobozzz <me@florianbigard.com>
Tue, 24 Jul 2018 16:03:38 +0000 (18:03 +0200)
server/initializers/constants.ts
server/middlewares/pagination.ts

index e8e0da683f6dff072db3d5304dc7e4a104f08d4d..85c5335ad303d2b8c7ec2db81a6a015b15c713d0 100644 (file)
@@ -21,8 +21,12 @@ const LAST_MIGRATION_VERSION = 235
 // API version
 const API_VERSION = 'v1'
 
-// Number of results by default for the pagination
-const PAGINATION_COUNT_DEFAULT = 15
+const PAGINATION = {
+  COUNT: {
+    DEFAULT: 15,
+    MAX: 100
+  }
+}
 
 // Sortable columns per schema
 const SORTABLE_COLUMNS = {
@@ -539,7 +543,7 @@ export {
   OAUTH_LIFETIME,
   CUSTOM_HTML_TAG_COMMENTS,
   BROADCAST_CONCURRENCY,
-  PAGINATION_COUNT_DEFAULT,
+  PAGINATION,
   ACTOR_FOLLOW_SCORE,
   PREVIEWS_SIZE,
   REMOTE_SCHEME,
index 2ea2a6b82c6b675c453056199639c1c61387ec3e..9b497b19e78dfe778a0cf8f2276e3beec49b027c 100644 (file)
@@ -1,15 +1,17 @@
 import 'express-validator'
 import * as express from 'express'
 
-import { PAGINATION_COUNT_DEFAULT } from '../initializers'
+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 = 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()
 }