]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/middlewares/validators/feeds.ts
Cache AP video route for 5 seconds
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / feeds.ts
1 import * as express from 'express'
2 import { param, query } from 'express-validator/check'
3 import { isAccountIdExist, isAccountNameValid } from '../../helpers/custom-validators/accounts'
4 import { join } from 'path'
5 import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc'
6 import { logger } from '../../helpers/logger'
7 import { areValidationErrors } from './utils'
8 import { isValidRSSFeed } from '../../helpers/custom-validators/feeds'
9 import { isVideoChannelExist } from '../../helpers/custom-validators/video-channels'
10
11 const feedsValidator = [
12 param('format').optional().custom(isValidRSSFeed).withMessage('Should have a valid format (rss, atom, json)'),
13 query('format').optional().custom(isValidRSSFeed).withMessage('Should have a valid format (rss, atom, json)'),
14 query('accountId').optional().custom(isIdOrUUIDValid),
15 query('accountName').optional().custom(isAccountNameValid),
16
17 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
18 logger.debug('Checking feeds parameters', { parameters: req.query })
19
20 if (areValidationErrors(req, res)) return
21
22 if (req.query.accountId && !await isAccountIdExist(req.query.accountId, res)) return
23 if (req.query.videoChannelId && !await isVideoChannelExist(req.query.videoChannelId, res)) return
24
25 return next()
26 }
27 ]
28
29 // ---------------------------------------------------------------------------
30
31 export {
32 feedsValidator
33 }