]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/middlewares/validators/feeds.ts
Remove unused actor uuid field
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / feeds.ts
1 import * as express from 'express'
2 import { param, query } from 'express-validator/check'
3 import { doesAccountIdExist, doesAccountNameWithHostExist } from '../../helpers/custom-validators/accounts'
4 import { isIdOrUUIDValid, isIdValid } from '../../helpers/custom-validators/misc'
5 import { logger } from '../../helpers/logger'
6 import { areValidationErrors } from './utils'
7 import { isValidRSSFeed } from '../../helpers/custom-validators/feeds'
8 import { doesVideoChannelIdExist, doesVideoChannelNameWithHostExist } from '../../helpers/custom-validators/video-channels'
9 import { doesVideoExist } from '../../helpers/custom-validators/videos'
10
11 const videoFeedsValidator = [
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)'),
14 query('accountId').optional().custom(isIdValid),
15 query('accountName').optional(),
16 query('videoChannelId').optional().custom(isIdValid),
17 query('videoChannelName').optional(),
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
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
28
29 return next()
30 }
31 ]
32
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
43 if (req.query.videoId && !await doesVideoExist(req.query.videoId, res)) return
44
45 return next()
46 }
47 ]
48
49 // ---------------------------------------------------------------------------
50
51 export {
52 videoFeedsValidator,
53 videoCommentsFeedsValidator
54 }