From afff310e50f2fa8419bb4242470cbde46ab54463 Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Thu, 13 Aug 2020 15:07:23 +0200 Subject: allow private syndication feeds via a user feedToken --- server/middlewares/validators/feeds.ts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'server/middlewares/validators/feeds.ts') diff --git a/server/middlewares/validators/feeds.ts b/server/middlewares/validators/feeds.ts index c3de0f5fe..5c76a679f 100644 --- a/server/middlewares/validators/feeds.ts +++ b/server/middlewares/validators/feeds.ts @@ -9,7 +9,8 @@ import { doesAccountIdExist, doesAccountNameWithHostExist, doesVideoChannelIdExist, - doesVideoChannelNameWithHostExist + doesVideoChannelNameWithHostExist, + doesUserFeedTokenCorrespond } from '../../helpers/middlewares' const feedsFormatValidator = [ @@ -62,6 +63,23 @@ const videoFeedsValidator = [ } ] +const videoSubscriptonFeedsValidator = [ + query('accountId').optional().custom(isIdValid), + query('token').optional(), + + async (req: express.Request, res: express.Response, next: express.NextFunction) => { + logger.debug('Checking feeds parameters', { parameters: req.query }) + + if (areValidationErrors(req, res)) return + + // a token alone is erroneous + if (req.query.token && !req.query.accountId) return + if (req.query.token && !await doesUserFeedTokenCorrespond(res.locals.account.userId, req.query.token, res)) return + + return next() + } +] + const videoCommentsFeedsValidator = [ query('videoId').optional().custom(isIdOrUUIDValid), @@ -88,5 +106,6 @@ export { feedsFormatValidator, setFeedFormatContentType, videoFeedsValidator, + videoSubscriptonFeedsValidator, videoCommentsFeedsValidator } -- cgit v1.2.3