X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmiddlewares%2Fvalidators%2Ffeeds.ts;h=35080ffcab2c2d759276e50a6296f882fdd5d8d0;hb=5beb89f223539f1e415a976ff104f772526b4d20;hp=f34c2b174527085750e48ac5bc11c4e3e549bdae;hpb=4c1def5fd8e9f483238eb38e221f555e2e6bbf07;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/middlewares/validators/feeds.ts b/server/middlewares/validators/feeds.ts index f34c2b174..35080ffca 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,24 @@ const videoFeedsValidator = [ } ] +const videoSubscriptonFeedsValidator = [ + query('accountId').custom(isIdValid), + query('token'), + + 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.accountId && !await doesAccountIdExist(req.query.accountId, res)) 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), @@ -70,6 +89,12 @@ const videoCommentsFeedsValidator = [ if (areValidationErrors(req, res)) return + if (req.query.videoId && (req.query.videoChannelId || req.query.videoChannelName)) { + return res.status(400).send({ + message: 'videoId cannot be mixed with a channel filter' + }).end() + } + if (req.query.videoId && !await doesVideoExist(req.query.videoId, res)) return return next() @@ -82,5 +107,6 @@ export { feedsFormatValidator, setFeedFormatContentType, videoFeedsValidator, + videoSubscriptonFeedsValidator, videoCommentsFeedsValidator }