]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/middlewares/validators/feeds.ts
Add video comments RSS
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / feeds.ts
index b55190559c239c07fc3967e199f7150424f5feca..3c8532bd93355d6e7910959518cfbf94ce867820 100644 (file)
@@ -7,12 +7,14 @@ import { logger } from '../../helpers/logger'
 import { areValidationErrors } from './utils'
 import { isValidRSSFeed } from '../../helpers/custom-validators/feeds'
 import { isVideoChannelExist } from '../../helpers/custom-validators/video-channels'
+import { isVideoExist } from '../../helpers/custom-validators/videos'
 
-const feedsValidator = [
+const videoFeedsValidator = [
   param('format').optional().custom(isValidRSSFeed).withMessage('Should have a valid format (rss, atom, json)'),
   query('format').optional().custom(isValidRSSFeed).withMessage('Should have a valid format (rss, atom, json)'),
   query('accountId').optional().custom(isIdOrUUIDValid),
   query('accountName').optional().custom(isAccountNameValid),
+  query('videoChannelId').optional().custom(isIdOrUUIDValid),
 
   async (req: express.Request, res: express.Response, next: express.NextFunction) => {
     logger.debug('Checking feeds parameters', { parameters: req.query })
@@ -26,8 +28,25 @@ const feedsValidator = [
   }
 ]
 
+const videoCommentsFeedsValidator = [
+  param('format').optional().custom(isValidRSSFeed).withMessage('Should have a valid format (rss, atom, json)'),
+  query('format').optional().custom(isValidRSSFeed).withMessage('Should have a valid format (rss, atom, json)'),
+  query('videoId').optional().custom(isIdOrUUIDValid),
+
+  async (req: express.Request, res: express.Response, next: express.NextFunction) => {
+    logger.debug('Checking feeds parameters', { parameters: req.query })
+
+    if (areValidationErrors(req, res)) return
+
+    if (req.query.videoId && !await isVideoExist(req.query.videoId, res)) return
+
+    return next()
+  }
+]
+
 // ---------------------------------------------------------------------------
 
 export {
-  feedsValidator
+  videoFeedsValidator,
+  videoCommentsFeedsValidator
 }