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