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