Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Add max count in pagination

Chocobozzz1194e8b46f53
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts
index e8e0da683f..85c5335ad3 100644
--- a/server/initializers/constants.ts
+++ b/server/initializers/constants.ts
@@ -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,
diff --git a/server/middlewares/pagination.ts b/server/middlewares/pagination.ts
index 2ea2a6b82c..9b497b19e7 100644
--- a/server/middlewares/pagination.ts
+++ b/server/middlewares/pagination.ts
@@ -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()
}