diff options
Diffstat (limited to 'server/middlewares/validators')
-rw-r--r-- | server/middlewares/validators/feeds.ts | 11 | ||||
-rw-r--r-- | server/middlewares/validators/video-channels.ts | 23 |
2 files changed, 19 insertions, 15 deletions
diff --git a/server/middlewares/validators/feeds.ts b/server/middlewares/validators/feeds.ts index 3c8532bd9..c1054ad9b 100644 --- a/server/middlewares/validators/feeds.ts +++ b/server/middlewares/validators/feeds.ts | |||
@@ -1,13 +1,13 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { param, query } from 'express-validator/check' | 2 | import { param, query } from 'express-validator/check' |
3 | import { isAccountIdExist, isAccountNameValid } from '../../helpers/custom-validators/accounts' | 3 | import { isAccountIdExist, isAccountNameValid, isAccountNameWithHostExist } from '../../helpers/custom-validators/accounts' |
4 | import { join } from 'path' | ||
5 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' | 4 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' |
6 | import { logger } from '../../helpers/logger' | 5 | import { logger } from '../../helpers/logger' |
7 | import { areValidationErrors } from './utils' | 6 | import { areValidationErrors } from './utils' |
8 | import { isValidRSSFeed } from '../../helpers/custom-validators/feeds' | 7 | import { isValidRSSFeed } from '../../helpers/custom-validators/feeds' |
9 | import { isVideoChannelExist } from '../../helpers/custom-validators/video-channels' | 8 | import { isVideoChannelIdExist, isVideoChannelNameWithHostExist } from '../../helpers/custom-validators/video-channels' |
10 | import { isVideoExist } from '../../helpers/custom-validators/videos' | 9 | import { isVideoExist } from '../../helpers/custom-validators/videos' |
10 | import { isActorPreferredUsernameValid } from '../../helpers/custom-validators/activitypub/actor' | ||
11 | 11 | ||
12 | const videoFeedsValidator = [ | 12 | const videoFeedsValidator = [ |
13 | param('format').optional().custom(isValidRSSFeed).withMessage('Should have a valid format (rss, atom, json)'), | 13 | param('format').optional().custom(isValidRSSFeed).withMessage('Should have a valid format (rss, atom, json)'), |
@@ -15,6 +15,7 @@ const videoFeedsValidator = [ | |||
15 | query('accountId').optional().custom(isIdOrUUIDValid), | 15 | query('accountId').optional().custom(isIdOrUUIDValid), |
16 | query('accountName').optional().custom(isAccountNameValid), | 16 | query('accountName').optional().custom(isAccountNameValid), |
17 | query('videoChannelId').optional().custom(isIdOrUUIDValid), | 17 | query('videoChannelId').optional().custom(isIdOrUUIDValid), |
18 | query('videoChannelName').optional().custom(isActorPreferredUsernameValid), | ||
18 | 19 | ||
19 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 20 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
20 | logger.debug('Checking feeds parameters', { parameters: req.query }) | 21 | logger.debug('Checking feeds parameters', { parameters: req.query }) |
@@ -22,7 +23,9 @@ const videoFeedsValidator = [ | |||
22 | if (areValidationErrors(req, res)) return | 23 | if (areValidationErrors(req, res)) return |
23 | 24 | ||
24 | if (req.query.accountId && !await isAccountIdExist(req.query.accountId, res)) return | 25 | if (req.query.accountId && !await isAccountIdExist(req.query.accountId, res)) return |
25 | if (req.query.videoChannelId && !await isVideoChannelExist(req.query.videoChannelId, res)) return | 26 | if (req.query.videoChannelName && !await isVideoChannelIdExist(req.query.videoChannelName, res)) return |
27 | if (req.query.accountName && !await isAccountNameWithHostExist(req.query.accountName, res)) return | ||
28 | if (req.query.videoChannelName && !await isVideoChannelNameWithHostExist(req.query.videoChannelName, res)) return | ||
26 | 29 | ||
27 | return next() | 30 | return next() |
28 | } | 31 | } |
diff --git a/server/middlewares/validators/video-channels.ts b/server/middlewares/validators/video-channels.ts index d354c7e05..79587b028 100644 --- a/server/middlewares/validators/video-channels.ts +++ b/server/middlewares/validators/video-channels.ts | |||
@@ -2,18 +2,18 @@ import * as express from 'express' | |||
2 | import { body, param } from 'express-validator/check' | 2 | import { body, param } from 'express-validator/check' |
3 | import { UserRight } from '../../../shared' | 3 | import { UserRight } from '../../../shared' |
4 | import { isAccountNameWithHostExist } from '../../helpers/custom-validators/accounts' | 4 | import { isAccountNameWithHostExist } from '../../helpers/custom-validators/accounts' |
5 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' | ||
6 | import { | 5 | import { |
7 | isLocalVideoChannelNameExist, | 6 | isLocalVideoChannelNameExist, |
8 | isVideoChannelDescriptionValid, | 7 | isVideoChannelDescriptionValid, |
9 | isVideoChannelExist, | ||
10 | isVideoChannelNameValid, | 8 | isVideoChannelNameValid, |
9 | isVideoChannelNameWithHostExist, | ||
11 | isVideoChannelSupportValid | 10 | isVideoChannelSupportValid |
12 | } from '../../helpers/custom-validators/video-channels' | 11 | } from '../../helpers/custom-validators/video-channels' |
13 | import { logger } from '../../helpers/logger' | 12 | import { logger } from '../../helpers/logger' |
14 | import { UserModel } from '../../models/account/user' | 13 | import { UserModel } from '../../models/account/user' |
15 | import { VideoChannelModel } from '../../models/video/video-channel' | 14 | import { VideoChannelModel } from '../../models/video/video-channel' |
16 | import { areValidationErrors } from './utils' | 15 | import { areValidationErrors } from './utils' |
16 | import { isActorPreferredUsernameValid } from '../../helpers/custom-validators/activitypub/actor' | ||
17 | 17 | ||
18 | const listVideoAccountChannelsValidator = [ | 18 | const listVideoAccountChannelsValidator = [ |
19 | param('accountName').exists().withMessage('Should have a valid account name'), | 19 | param('accountName').exists().withMessage('Should have a valid account name'), |
@@ -29,6 +29,7 @@ const listVideoAccountChannelsValidator = [ | |||
29 | ] | 29 | ] |
30 | 30 | ||
31 | const videoChannelsAddValidator = [ | 31 | const videoChannelsAddValidator = [ |
32 | body('name').custom(isActorPreferredUsernameValid).withMessage('Should have a valid channel name'), | ||
32 | body('displayName').custom(isVideoChannelNameValid).withMessage('Should have a valid display name'), | 33 | body('displayName').custom(isVideoChannelNameValid).withMessage('Should have a valid display name'), |
33 | body('description').optional().custom(isVideoChannelDescriptionValid).withMessage('Should have a valid description'), | 34 | body('description').optional().custom(isVideoChannelDescriptionValid).withMessage('Should have a valid description'), |
34 | body('support').optional().custom(isVideoChannelSupportValid).withMessage('Should have a valid support text'), | 35 | body('support').optional().custom(isVideoChannelSupportValid).withMessage('Should have a valid support text'), |
@@ -43,7 +44,7 @@ const videoChannelsAddValidator = [ | |||
43 | ] | 44 | ] |
44 | 45 | ||
45 | const videoChannelsUpdateValidator = [ | 46 | const videoChannelsUpdateValidator = [ |
46 | param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), | 47 | param('nameWithHost').exists().withMessage('Should have an video channel name with host'), |
47 | body('displayName').optional().custom(isVideoChannelNameValid).withMessage('Should have a valid display name'), | 48 | body('displayName').optional().custom(isVideoChannelNameValid).withMessage('Should have a valid display name'), |
48 | body('description').optional().custom(isVideoChannelDescriptionValid).withMessage('Should have a valid description'), | 49 | body('description').optional().custom(isVideoChannelDescriptionValid).withMessage('Should have a valid description'), |
49 | body('support').optional().custom(isVideoChannelSupportValid).withMessage('Should have a valid support text'), | 50 | body('support').optional().custom(isVideoChannelSupportValid).withMessage('Should have a valid support text'), |
@@ -52,7 +53,7 @@ const videoChannelsUpdateValidator = [ | |||
52 | logger.debug('Checking videoChannelsUpdate parameters', { parameters: req.body }) | 53 | logger.debug('Checking videoChannelsUpdate parameters', { parameters: req.body }) |
53 | 54 | ||
54 | if (areValidationErrors(req, res)) return | 55 | if (areValidationErrors(req, res)) return |
55 | if (!await isVideoChannelExist(req.params.id, res)) return | 56 | if (!await isVideoChannelNameWithHostExist(req.params.nameWithHost, res)) return |
56 | 57 | ||
57 | // We need to make additional checks | 58 | // We need to make additional checks |
58 | if (res.locals.videoChannel.Actor.isOwned() === false) { | 59 | if (res.locals.videoChannel.Actor.isOwned() === false) { |
@@ -72,13 +73,13 @@ const videoChannelsUpdateValidator = [ | |||
72 | ] | 73 | ] |
73 | 74 | ||
74 | const videoChannelsRemoveValidator = [ | 75 | const videoChannelsRemoveValidator = [ |
75 | param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), | 76 | param('nameWithHost').exists().withMessage('Should have an video channel name with host'), |
76 | 77 | ||
77 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 78 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
78 | logger.debug('Checking videoChannelsRemove parameters', { parameters: req.params }) | 79 | logger.debug('Checking videoChannelsRemove parameters', { parameters: req.params }) |
79 | 80 | ||
80 | if (areValidationErrors(req, res)) return | 81 | if (areValidationErrors(req, res)) return |
81 | if (!await isVideoChannelExist(req.params.id, res)) return | 82 | if (!await isVideoChannelNameWithHostExist(req.params.nameWithHost, res)) return |
82 | 83 | ||
83 | if (!checkUserCanDeleteVideoChannel(res.locals.oauth.token.User, res.locals.videoChannel, res)) return | 84 | if (!checkUserCanDeleteVideoChannel(res.locals.oauth.token.User, res.locals.videoChannel, res)) return |
84 | if (!await checkVideoChannelIsNotTheLastOne(res)) return | 85 | if (!await checkVideoChannelIsNotTheLastOne(res)) return |
@@ -87,15 +88,15 @@ const videoChannelsRemoveValidator = [ | |||
87 | } | 88 | } |
88 | ] | 89 | ] |
89 | 90 | ||
90 | const videoChannelsGetValidator = [ | 91 | const videoChannelsNameWithHostValidator = [ |
91 | param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), | 92 | param('nameWithHost').exists().withMessage('Should have an video channel name with host'), |
92 | 93 | ||
93 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 94 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
94 | logger.debug('Checking videoChannelsGet parameters', { parameters: req.params }) | 95 | logger.debug('Checking videoChannelsNameWithHostValidator parameters', { parameters: req.params }) |
95 | 96 | ||
96 | if (areValidationErrors(req, res)) return | 97 | if (areValidationErrors(req, res)) return |
97 | 98 | ||
98 | if (!await isVideoChannelExist(req.params.id, res)) return | 99 | if (!await isVideoChannelNameWithHostExist(req.params.nameWithHost, res)) return |
99 | 100 | ||
100 | return next() | 101 | return next() |
101 | } | 102 | } |
@@ -121,7 +122,7 @@ export { | |||
121 | videoChannelsAddValidator, | 122 | videoChannelsAddValidator, |
122 | videoChannelsUpdateValidator, | 123 | videoChannelsUpdateValidator, |
123 | videoChannelsRemoveValidator, | 124 | videoChannelsRemoveValidator, |
124 | videoChannelsGetValidator, | 125 | videoChannelsNameWithHostValidator, |
125 | localVideoChannelValidator | 126 | localVideoChannelValidator |
126 | } | 127 | } |
127 | 128 | ||