From fe3a55b071c99b346e9e9ab786f5d219e5a064cd Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 8 Jun 2018 20:34:37 +0200 Subject: Add video comments RSS --- server/middlewares/validators/feeds.ts | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'server/middlewares/validators/feeds.ts') 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 } -- cgit v1.2.3