From 764a965778ac89e027fd05dd35697c6763e0dc18 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 11 Mar 2020 14:39:28 +0100 Subject: Implement pagination for overviews endpoint --- server/middlewares/validators/videos/videos.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'server/middlewares/validators') diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.ts index 96e0d6600..3a7869354 100644 --- a/server/middlewares/validators/videos/videos.ts +++ b/server/middlewares/validators/videos/videos.ts @@ -29,7 +29,7 @@ import { } from '../../../helpers/custom-validators/videos' import { getDurationFromVideoFile } from '../../../helpers/ffmpeg-utils' import { logger } from '../../../helpers/logger' -import { CONSTRAINTS_FIELDS } from '../../../initializers/constants' +import { CONSTRAINTS_FIELDS, OVERVIEWS } from '../../../initializers/constants' import { authenticatePromiseIfNeeded } from '../../oauth' import { areValidationErrors } from '../utils' import { cleanUpReqFiles } from '../../../helpers/express-utils' @@ -301,6 +301,19 @@ const videosAcceptChangeOwnershipValidator = [ } ] +const videosOverviewValidator = [ + query('page') + .optional() + .isInt({ min: 1, max: OVERVIEWS.VIDEOS.SAMPLES_COUNT }) + .withMessage('Should have a valid pagination'), + + (req: express.Request, res: express.Response, next: express.NextFunction) => { + if (areValidationErrors(req, res)) return + + return next() + } +] + function getCommonVideoEditAttributes () { return [ body('thumbnailfile') @@ -442,7 +455,9 @@ export { getCommonVideoEditAttributes, - commonVideosFiltersValidator + commonVideosFiltersValidator, + + videosOverviewValidator } // --------------------------------------------------------------------------- -- cgit v1.2.3