Add max count in pagination
This commit is contained in:
parent
76dd3e89ae
commit
1194e8b46f
|
@ -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,
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue