]>
Commit | Line | Data |
---|---|---|
244e76a5 RK |
1 | import * as express from 'express' |
2 | import { param, query } from 'express-validator/check' | |
57cfff78 C |
3 | import { doesAccountIdExist, doesAccountNameWithHostExist } from '../../helpers/custom-validators/accounts' |
4 | import { isIdOrUUIDValid, isIdValid } from '../../helpers/custom-validators/misc' | |
244e76a5 RK |
5 | import { logger } from '../../helpers/logger' |
6 | import { areValidationErrors } from './utils' | |
7 | import { isValidRSSFeed } from '../../helpers/custom-validators/feeds' | |
0f6acda1 C |
8 | import { doesVideoChannelIdExist, doesVideoChannelNameWithHostExist } from '../../helpers/custom-validators/video-channels' |
9 | import { doesVideoExist } from '../../helpers/custom-validators/videos' | |
244e76a5 | 10 | |
fe3a55b0 | 11 | const videoFeedsValidator = [ |
244e76a5 RK |
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)'), | |
57cfff78 C |
14 | query('accountId').optional().custom(isIdValid), |
15 | query('accountName').optional(), | |
16 | query('videoChannelId').optional().custom(isIdValid), | |
17 | query('videoChannelName').optional(), | |
244e76a5 RK |
18 | |
19 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
20 | logger.debug('Checking feeds parameters', { parameters: req.query }) | |
21 | ||
22 | if (areValidationErrors(req, res)) return | |
23 | ||
0f6acda1 C |
24 | if (req.query.accountId && !await doesAccountIdExist(req.query.accountId, res)) return |
25 | if (req.query.videoChannelId && !await doesVideoChannelIdExist(req.query.videoChannelId, res)) return | |
26 | if (req.query.accountName && !await doesAccountNameWithHostExist(req.query.accountName, res)) return | |
27 | if (req.query.videoChannelName && !await doesVideoChannelNameWithHostExist(req.query.videoChannelName, res)) return | |
244e76a5 RK |
28 | |
29 | return next() | |
30 | } | |
31 | ] | |
32 | ||
fe3a55b0 C |
33 | const videoCommentsFeedsValidator = [ |
34 | param('format').optional().custom(isValidRSSFeed).withMessage('Should have a valid format (rss, atom, json)'), | |
35 | query('format').optional().custom(isValidRSSFeed).withMessage('Should have a valid format (rss, atom, json)'), | |
36 | query('videoId').optional().custom(isIdOrUUIDValid), | |
37 | ||
38 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
39 | logger.debug('Checking feeds parameters', { parameters: req.query }) | |
40 | ||
41 | if (areValidationErrors(req, res)) return | |
42 | ||
0f6acda1 | 43 | if (req.query.videoId && !await doesVideoExist(req.query.videoId, res)) return |
fe3a55b0 C |
44 | |
45 | return next() | |
46 | } | |
47 | ] | |
48 | ||
244e76a5 RK |
49 | // --------------------------------------------------------------------------- |
50 | ||
51 | export { | |
fe3a55b0 C |
52 | videoFeedsValidator, |
53 | videoCommentsFeedsValidator | |
244e76a5 | 54 | } |