1 import * as express from 'express'
2 import { param, query } from 'express-validator'
3 import { isIdOrUUIDValid, isIdValid } from '../../helpers/custom-validators/misc'
4 import { logger } from '../../helpers/logger'
5 import { areValidationErrors } from './utils'
6 import { isValidRSSFeed } from '../../helpers/custom-validators/feeds'
7 import { doesVideoExist } from '../../helpers/middlewares/videos'
10 doesAccountNameWithHostExist,
11 doesVideoChannelIdExist,
12 doesVideoChannelNameWithHostExist
13 } from '../../helpers/middlewares'
15 const videoFeedsValidator = [
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)'),
18 query('accountId').optional().custom(isIdValid),
19 query('accountName').optional(),
20 query('videoChannelId').optional().custom(isIdValid),
21 query('videoChannelName').optional(),
23 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
24 logger.debug('Checking feeds parameters', { parameters: req.query })
26 if (areValidationErrors(req, res)) return
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
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),
42 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
43 logger.debug('Checking feeds parameters', { parameters: req.query })
45 if (areValidationErrors(req, res)) return
47 if (req.query.videoId && !await doesVideoExist(req.query.videoId, res)) return
53 // ---------------------------------------------------------------------------
57 videoCommentsFeedsValidator