From 2a4c0d8bbe29178ae90e776bb9453f86e6d23bd9 Mon Sep 17 00:00:00 2001 From: Wicklow <123956049+wickloww@users.noreply.github.com> Date: Wed, 12 Apr 2023 07:32:20 +0000 Subject: Feature/filter already watched videos (#5739) * filter already watched videos * Updated code based on review comments --- server/middlewares/validators/videos/videos.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'server/middlewares') 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 = [ query('search') .optional() .custom(exists), + query('excludeAlreadyWatched') + .optional() + .customSanitizer(toBooleanOrNull) + .isBoolean().withMessage('Should be a valid excludeAlreadyWatched boolean'), (req: express.Request, res: express.Response, next: express.NextFunction) => { if (areValidationErrors(req, res)) return @@ -520,6 +524,13 @@ const commonVideosFiltersValidator = [ } } + if (!user && exists(req.query.excludeAlreadyWatched)) { + res.fail({ + status: HttpStatusCode.BAD_REQUEST_400, + message: 'Cannot use excludeAlreadyWatched parameter when auth token is not provided' + }) + return false + } return next() } ] -- cgit v1.2.3