]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - server/middlewares/validators/feeds.ts
Serve audit logs to client
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / feeds.ts
... / ...
CommitLineData
1import * as express from 'express'
2import { param, query } from 'express-validator'
3import { isIdOrUUIDValid, isIdValid } from '../../helpers/custom-validators/misc'
4import { logger } from '../../helpers/logger'
5import { areValidationErrors } from './utils'
6import { isValidRSSFeed } from '../../helpers/custom-validators/feeds'
7import { doesVideoExist } from '../../helpers/middlewares/videos'
8import {
9 doesAccountIdExist,
10 doesAccountNameWithHostExist,
11 doesVideoChannelIdExist,
12 doesVideoChannelNameWithHostExist
13} from '../../helpers/middlewares'
14
15const 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(),
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
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
32
33 return next()
34 }
35]
36
37const 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
47 if (req.query.videoId && !await doesVideoExist(req.query.videoId, res)) return
48
49 return next()
50 }
51]
52
53// ---------------------------------------------------------------------------
54
55export {
56 videoFeedsValidator,
57 videoCommentsFeedsValidator
58}