diff options
author | Chocobozzz <me@florianbigard.com> | 2020-03-11 14:39:28 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2020-03-11 15:02:20 +0100 |
commit | 764a965778ac89e027fd05dd35697c6763e0dc18 (patch) | |
tree | ecc18834566b940c729a57b5bf0d088e894f03d3 /server/middlewares | |
parent | fab6746354f9d9cb65c35d8bd9352c4b773b4c69 (diff) | |
download | PeerTube-764a965778ac89e027fd05dd35697c6763e0dc18.tar.gz PeerTube-764a965778ac89e027fd05dd35697c6763e0dc18.tar.zst PeerTube-764a965778ac89e027fd05dd35697c6763e0dc18.zip |
Implement pagination for overviews endpoint
Diffstat (limited to 'server/middlewares')
-rw-r--r-- | server/middlewares/validators/videos/videos.ts | 19 |
1 files changed, 17 insertions, 2 deletions
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 { | |||
29 | } from '../../../helpers/custom-validators/videos' | 29 | } from '../../../helpers/custom-validators/videos' |
30 | import { getDurationFromVideoFile } from '../../../helpers/ffmpeg-utils' | 30 | import { getDurationFromVideoFile } from '../../../helpers/ffmpeg-utils' |
31 | import { logger } from '../../../helpers/logger' | 31 | import { logger } from '../../../helpers/logger' |
32 | import { CONSTRAINTS_FIELDS } from '../../../initializers/constants' | 32 | import { CONSTRAINTS_FIELDS, OVERVIEWS } from '../../../initializers/constants' |
33 | import { authenticatePromiseIfNeeded } from '../../oauth' | 33 | import { authenticatePromiseIfNeeded } from '../../oauth' |
34 | import { areValidationErrors } from '../utils' | 34 | import { areValidationErrors } from '../utils' |
35 | import { cleanUpReqFiles } from '../../../helpers/express-utils' | 35 | import { cleanUpReqFiles } from '../../../helpers/express-utils' |
@@ -301,6 +301,19 @@ const videosAcceptChangeOwnershipValidator = [ | |||
301 | } | 301 | } |
302 | ] | 302 | ] |
303 | 303 | ||
304 | const videosOverviewValidator = [ | ||
305 | query('page') | ||
306 | .optional() | ||
307 | .isInt({ min: 1, max: OVERVIEWS.VIDEOS.SAMPLES_COUNT }) | ||
308 | .withMessage('Should have a valid pagination'), | ||
309 | |||
310 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
311 | if (areValidationErrors(req, res)) return | ||
312 | |||
313 | return next() | ||
314 | } | ||
315 | ] | ||
316 | |||
304 | function getCommonVideoEditAttributes () { | 317 | function getCommonVideoEditAttributes () { |
305 | return [ | 318 | return [ |
306 | body('thumbnailfile') | 319 | body('thumbnailfile') |
@@ -442,7 +455,9 @@ export { | |||
442 | 455 | ||
443 | getCommonVideoEditAttributes, | 456 | getCommonVideoEditAttributes, |
444 | 457 | ||
445 | commonVideosFiltersValidator | 458 | commonVideosFiltersValidator, |
459 | |||
460 | videosOverviewValidator | ||
446 | } | 461 | } |
447 | 462 | ||
448 | // --------------------------------------------------------------------------- | 463 | // --------------------------------------------------------------------------- |