]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/validators/feeds.ts
Add patch for angular cli 6
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / feeds.ts
CommitLineData
244e76a5
RK
1import * as express from 'express'
2import { param, query } from 'express-validator/check'
e0ea4b1d 3import { isAccountIdExist, isAccountNameValid } from '../../helpers/custom-validators/accounts'
244e76a5
RK
4import { join } from 'path'
5import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc'
6import { logger } from '../../helpers/logger'
7import { areValidationErrors } from './utils'
8import { isValidRSSFeed } from '../../helpers/custom-validators/feeds'
e0ea4b1d 9import { isVideoChannelExist } from '../../helpers/custom-validators/video-channels'
244e76a5
RK
10
11const 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
e0ea4b1d
C
22 if (req.query.accountId && !await isAccountIdExist(req.query.accountId, res)) return
23 if (req.query.videoChannelId && !await isVideoChannelExist(req.query.videoChannelId, res)) return
244e76a5
RK
24
25 return next()
26 }
27]
28
29// ---------------------------------------------------------------------------
30
31export {
32 feedsValidator
33}