]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/middlewares/validators/videos/videos.ts
Feature/filter already watched videos (#5739)
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / videos / videos.ts
index e29eb4a323966373b5203471c767d024197102d9..ea6bd0721ab7c0c19596431a9f4b5368c5afa9e0 100644 (file)
@@ -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()
   }
 ]