X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmiddlewares%2Fvalidators%2Ffeeds.ts;h=3c8532bd93355d6e7910959518cfbf94ce867820;hb=fe3a55b071c99b346e9e9ab786f5d219e5a064cd;hp=b55190559c239c07fc3967e199f7150424f5feca;hpb=4a7591e1a8ec5ffdff85580c6be4b18d8b85b4d4;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/middlewares/validators/feeds.ts b/server/middlewares/validators/feeds.ts index b55190559..3c8532bd9 100644 --- a/server/middlewares/validators/feeds.ts +++ b/server/middlewares/validators/feeds.ts @@ -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 }