Add max pagination count
This commit is contained in:
parent
03ecc70491
commit
6ec5a3ec43
|
@ -121,7 +121,10 @@ const SORTABLE_COLUMNS = {
|
|||
PLAYLISTS_SEARCH: [ 'match', 'displayName', 'createdAt' ]
|
||||
}
|
||||
|
||||
const PAGINATION_COUNT_DEFAULT = 20
|
||||
const PAGINATION_COUNT = {
|
||||
DEFAULT: 20,
|
||||
MAX: 500
|
||||
}
|
||||
|
||||
const SCHEDULER_INTERVALS_MS = {
|
||||
indexation: 60000 * 60 * 24 // 24 hours
|
||||
|
@ -174,7 +177,7 @@ export {
|
|||
|
||||
CONFIG,
|
||||
API_VERSION,
|
||||
PAGINATION_COUNT_DEFAULT,
|
||||
PAGINATION_COUNT,
|
||||
SORTABLE_COLUMNS,
|
||||
INDEXER_QUEUE_CONCURRENCY,
|
||||
SCHEDULER_INTERVALS_MS,
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
import 'express-validator'
|
||||
import * as express from 'express'
|
||||
|
||||
import { PAGINATION_COUNT_DEFAULT } from '../initializers/constants'
|
||||
import { PAGINATION_COUNT } from '../initializers/constants'
|
||||
|
||||
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)
|
||||
|
||||
return next()
|
||||
|
|
|
@ -1,10 +1,16 @@
|
|||
import * as express from 'express'
|
||||
import { check } from 'express-validator'
|
||||
import { PAGINATION_COUNT } from 'server/initializers/constants'
|
||||
import { areValidationErrors } from './utils'
|
||||
|
||||
const paginationValidator = [
|
||||
check('start').optional().isInt({ min: 0 }).withMessage('Should have a number start'),
|
||||
check('count').optional().isInt({ min: 0 }).withMessage('Should have a number count'),
|
||||
check('start')
|
||||
.optional()
|
||||
.isInt({ min: 0 }).withMessage('Should have a number start'),
|
||||
|
||||
check('count')
|
||||
.optional()
|
||||
.isInt({ min: 0, max: PAGINATION_COUNT.MAX }).withMessage(`Should have a number count (> 0 and < ${PAGINATION_COUNT.MAX}`),
|
||||
|
||||
(req: express.Request, res: express.Response, next: express.NextFunction) => {
|
||||
if (areValidationErrors(req, res)) return
|
||||
|
|
Loading…
Reference in New Issue