1 import * as express from 'express'
2 import { param, query } from 'express-validator/check'
3 import { isAccountIdExist, isAccountNameValid } from '../../helpers/custom-validators/accounts'
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'
9 import { isVideoChannelExist } from '../../helpers/custom-validators/video-channels'
10 import { isVideoExist } from '../../helpers/custom-validators/videos'
12 const videoFeedsValidator = [
13 param('format').optional().custom(isValidRSSFeed).withMessage('Should have a valid format (rss, atom, json)'),
14 query('format').optional().custom(isValidRSSFeed).withMessage('Should have a valid format (rss, atom, json)'),
15 query('accountId').optional().custom(isIdOrUUIDValid),
16 query('accountName').optional().custom(isAccountNameValid),
17 query('videoChannelId').optional().custom(isIdOrUUIDValid),
19 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
20 logger.debug('Checking feeds parameters', { parameters: req.query })
22 if (areValidationErrors(req, res)) return
24 if (req.query.accountId && !await isAccountIdExist(req.query.accountId, res)) return
25 if (req.query.videoChannelId && !await isVideoChannelExist(req.query.videoChannelId, res)) return
31 const videoCommentsFeedsValidator = [
32 param('format').optional().custom(isValidRSSFeed).withMessage('Should have a valid format (rss, atom, json)'),
33 query('format').optional().custom(isValidRSSFeed).withMessage('Should have a valid format (rss, atom, json)'),
34 query('videoId').optional().custom(isIdOrUUIDValid),
36 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
37 logger.debug('Checking feeds parameters', { parameters: req.query })
39 if (areValidationErrors(req, res)) return
41 if (req.query.videoId && !await isVideoExist(req.query.videoId, res)) return
47 // ---------------------------------------------------------------------------
51 videoCommentsFeedsValidator