]>
Commit | Line | Data |
---|---|---|
244e76a5 RK |
1 | import * as express from 'express' |
2 | import { param, query } from 'express-validator/check' | |
8a19bee1 | 3 | import { isAccountIdExist, isAccountNameValid, isAccountNameWithHostExist } from '../../helpers/custom-validators/accounts' |
244e76a5 RK |
4 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' |
5 | import { logger } from '../../helpers/logger' | |
6 | import { areValidationErrors } from './utils' | |
7 | import { isValidRSSFeed } from '../../helpers/custom-validators/feeds' | |
8a19bee1 | 8 | import { isVideoChannelIdExist, isVideoChannelNameWithHostExist } from '../../helpers/custom-validators/video-channels' |
fe3a55b0 | 9 | import { isVideoExist } from '../../helpers/custom-validators/videos' |
8a19bee1 | 10 | import { isActorPreferredUsernameValid } from '../../helpers/custom-validators/activitypub/actor' |
244e76a5 | 11 | |
fe3a55b0 | 12 | const 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), |
8a19bee1 | 18 | query('videoChannelName').optional().custom(isActorPreferredUsernameValid), |
244e76a5 RK |
19 | |
20 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
21 | logger.debug('Checking feeds parameters', { parameters: req.query }) | |
22 | ||
23 | if (areValidationErrors(req, res)) return | |
24 | ||
e0ea4b1d | 25 | if (req.query.accountId && !await isAccountIdExist(req.query.accountId, res)) return |
662fb3ab | 26 | if (req.query.videoChannelId && !await isVideoChannelIdExist(req.query.videoChannelId, res)) return |
8a19bee1 C |
27 | if (req.query.accountName && !await isAccountNameWithHostExist(req.query.accountName, res)) return |
28 | if (req.query.videoChannelName && !await isVideoChannelNameWithHostExist(req.query.videoChannelName, res)) return | |
244e76a5 RK |
29 | |
30 | return next() | |
31 | } | |
32 | ] | |
33 | ||
fe3a55b0 C |
34 | const videoCommentsFeedsValidator = [ |
35 | param('format').optional().custom(isValidRSSFeed).withMessage('Should have a valid format (rss, atom, json)'), | |
36 | query('format').optional().custom(isValidRSSFeed).withMessage('Should have a valid format (rss, atom, json)'), | |
37 | query('videoId').optional().custom(isIdOrUUIDValid), | |
38 | ||
39 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
40 | logger.debug('Checking feeds parameters', { parameters: req.query }) | |
41 | ||
42 | if (areValidationErrors(req, res)) return | |
43 | ||
44 | if (req.query.videoId && !await isVideoExist(req.query.videoId, res)) return | |
45 | ||
46 | return next() | |
47 | } | |
48 | ] | |
49 | ||
244e76a5 RK |
50 | // --------------------------------------------------------------------------- |
51 | ||
52 | export { | |
fe3a55b0 C |
53 | videoFeedsValidator, |
54 | videoCommentsFeedsValidator | |
244e76a5 | 55 | } |