]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/validators/feeds.ts
Add import.video.torrent configuration
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / feeds.ts
CommitLineData
244e76a5
RK
1import * as express from 'express'
2import { param, query } from 'express-validator/check'
e0ea4b1d 3import { isAccountIdExist, isAccountNameValid } from '../../helpers/custom-validators/accounts'
244e76a5
RK
4import { join } from 'path'
5import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc'
6import { logger } from '../../helpers/logger'
7import { areValidationErrors } from './utils'
8import { isValidRSSFeed } from '../../helpers/custom-validators/feeds'
e0ea4b1d 9import { isVideoChannelExist } from '../../helpers/custom-validators/video-channels'
fe3a55b0 10import { isVideoExist } from '../../helpers/custom-validators/videos'
244e76a5 11
fe3a55b0 12const videoFeedsValidator = [
244e76a5
RK
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),
fe3a55b0 17 query('videoChannelId').optional().custom(isIdOrUUIDValid),
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
e0ea4b1d
C
24 if (req.query.accountId && !await isAccountIdExist(req.query.accountId, res)) return
25 if (req.query.videoChannelId && !await isVideoChannelExist(req.query.videoChannelId, res)) return
244e76a5
RK
26
27 return next()
28 }
29]
30
fe3a55b0
C
31const 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),
35
36 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
37 logger.debug('Checking feeds parameters', { parameters: req.query })
38
39 if (areValidationErrors(req, res)) return
40
41 if (req.query.videoId && !await isVideoExist(req.query.videoId, res)) return
42
43 return next()
44 }
45]
46
244e76a5
RK
47// ---------------------------------------------------------------------------
48
49export {
fe3a55b0
C
50 videoFeedsValidator,
51 videoCommentsFeedsValidator
244e76a5 52}