]>
Commit | Line | Data |
---|---|---|
244e76a5 RK |
1 | import * as express from 'express' |
2 | import { param, query } from 'express-validator/check' | |
e0ea4b1d | 3 | import { isAccountIdExist, isAccountNameValid } from '../../helpers/custom-validators/accounts' |
244e76a5 RK |
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' | |
e0ea4b1d | 9 | import { isVideoChannelExist } from '../../helpers/custom-validators/video-channels' |
244e76a5 RK |
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 | ||
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 | ||
31 | export { | |
32 | feedsValidator | |
33 | } |