diff options
author | Wicklow <123956049+wickloww@users.noreply.github.com> | 2023-04-12 07:32:20 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-12 09:32:20 +0200 |
commit | 2a4c0d8bbe29178ae90e776bb9453f86e6d23bd9 (patch) | |
tree | dfe4b6e1e06f617f8968285ca394e73fedefe6b2 /server/middlewares | |
parent | 0cda019c1d1f77e06e524362880c38e93b1f5c70 (diff) | |
download | PeerTube-2a4c0d8bbe29178ae90e776bb9453f86e6d23bd9.tar.gz PeerTube-2a4c0d8bbe29178ae90e776bb9453f86e6d23bd9.tar.zst PeerTube-2a4c0d8bbe29178ae90e776bb9453f86e6d23bd9.zip |
Feature/filter already watched videos (#5739)
* filter already watched videos
* Updated code based on review comments
Diffstat (limited to 'server/middlewares')
-rw-r--r-- | server/middlewares/validators/videos/videos.ts | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.ts index e29eb4a32..ea6bd0721 100644 --- a/server/middlewares/validators/videos/videos.ts +++ b/server/middlewares/validators/videos/videos.ts | |||
@@ -489,6 +489,10 @@ const commonVideosFiltersValidator = [ | |||
489 | query('search') | 489 | query('search') |
490 | .optional() | 490 | .optional() |
491 | .custom(exists), | 491 | .custom(exists), |
492 | query('excludeAlreadyWatched') | ||
493 | .optional() | ||
494 | .customSanitizer(toBooleanOrNull) | ||
495 | .isBoolean().withMessage('Should be a valid excludeAlreadyWatched boolean'), | ||
492 | 496 | ||
493 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | 497 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
494 | if (areValidationErrors(req, res)) return | 498 | if (areValidationErrors(req, res)) return |
@@ -520,6 +524,13 @@ const commonVideosFiltersValidator = [ | |||
520 | } | 524 | } |
521 | } | 525 | } |
522 | 526 | ||
527 | if (!user && exists(req.query.excludeAlreadyWatched)) { | ||
528 | res.fail({ | ||
529 | status: HttpStatusCode.BAD_REQUEST_400, | ||
530 | message: 'Cannot use excludeAlreadyWatched parameter when auth token is not provided' | ||
531 | }) | ||
532 | return false | ||
533 | } | ||
523 | return next() | 534 | return next() |
524 | } | 535 | } |
525 | ] | 536 | ] |