diff options
author | Chocobozzz <me@florianbigard.com> | 2018-05-25 09:57:16 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-05-25 10:41:07 +0200 |
commit | ad9e39fb815d85e5e718c40540fa75471474fa17 (patch) | |
tree | 960accb16bca0fac7694b3f3d5d038534b66c224 /server/middlewares | |
parent | 06be7ed0b27b371465c5d1b7f92b4adfb0b866ea (diff) | |
download | PeerTube-ad9e39fb815d85e5e718c40540fa75471474fa17.tar.gz PeerTube-ad9e39fb815d85e5e718c40540fa75471474fa17.tar.zst PeerTube-ad9e39fb815d85e5e718c40540fa75471474fa17.zip |
Only use account name in routes
Diffstat (limited to 'server/middlewares')
-rw-r--r-- | server/middlewares/validators/account.ts | 32 | ||||
-rw-r--r-- | server/middlewares/validators/video-channels.ts | 6 |
2 files changed, 6 insertions, 32 deletions
diff --git a/server/middlewares/validators/account.ts b/server/middlewares/validators/account.ts index c01e742da..b3a51e631 100644 --- a/server/middlewares/validators/account.ts +++ b/server/middlewares/validators/account.ts | |||
@@ -1,15 +1,8 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { param } from 'express-validator/check' | 2 | import { param } from 'express-validator/check' |
3 | import { | 3 | import { isAccountNameValid, isAccountNameWithHostExist, isLocalAccountNameExist } from '../../helpers/custom-validators/accounts' |
4 | isAccountIdExist, | ||
5 | isAccountIdValid, | ||
6 | isAccountNameValid, | ||
7 | isAccountNameWithHostExist, | ||
8 | isLocalAccountNameExist | ||
9 | } from '../../helpers/custom-validators/accounts' | ||
10 | import { logger } from '../../helpers/logger' | 4 | import { logger } from '../../helpers/logger' |
11 | import { areValidationErrors } from './utils' | 5 | import { areValidationErrors } from './utils' |
12 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' | ||
13 | 6 | ||
14 | const localAccountValidator = [ | 7 | const localAccountValidator = [ |
15 | param('name').custom(isAccountNameValid).withMessage('Should have a valid account name'), | 8 | param('name').custom(isAccountNameValid).withMessage('Should have a valid account name'), |
@@ -24,32 +17,14 @@ const localAccountValidator = [ | |||
24 | } | 17 | } |
25 | ] | 18 | ] |
26 | 19 | ||
27 | const accountsGetValidator = [ | ||
28 | param('id').custom(isAccountIdValid).withMessage('Should have a valid id/uuid/name/name with host'), | ||
29 | |||
30 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
31 | logger.debug('Checking accountsGetValidator parameters', { parameters: req.params }) | ||
32 | |||
33 | if (areValidationErrors(req, res)) return | ||
34 | |||
35 | let accountFetched = false | ||
36 | if (isIdOrUUIDValid(req.params.id)) accountFetched = await isAccountIdExist(req.params.id, res, false) | ||
37 | if (!accountFetched) accountFetched = await isAccountNameWithHostExist(req.params.id, res, true) | ||
38 | |||
39 | if (!accountFetched) return | ||
40 | |||
41 | return next() | ||
42 | } | ||
43 | ] | ||
44 | |||
45 | const accountsNameWithHostGetValidator = [ | 20 | const accountsNameWithHostGetValidator = [ |
46 | param('nameWithHost').exists().withMessage('Should have an account name with host'), | 21 | param('accountName').exists().withMessage('Should have an account name with host'), |
47 | 22 | ||
48 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 23 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
49 | logger.debug('Checking accountsNameWithHostGetValidator parameters', { parameters: req.params }) | 24 | logger.debug('Checking accountsNameWithHostGetValidator parameters', { parameters: req.params }) |
50 | 25 | ||
51 | if (areValidationErrors(req, res)) return | 26 | if (areValidationErrors(req, res)) return |
52 | if (!await isAccountNameWithHostExist(req.params.nameWithHost, res)) return | 27 | if (!await isAccountNameWithHostExist(req.params.accountName, res)) return |
53 | 28 | ||
54 | return next() | 29 | return next() |
55 | } | 30 | } |
@@ -59,6 +34,5 @@ const accountsNameWithHostGetValidator = [ | |||
59 | 34 | ||
60 | export { | 35 | export { |
61 | localAccountValidator, | 36 | localAccountValidator, |
62 | accountsGetValidator, | ||
63 | accountsNameWithHostGetValidator | 37 | accountsNameWithHostGetValidator |
64 | } | 38 | } |
diff --git a/server/middlewares/validators/video-channels.ts b/server/middlewares/validators/video-channels.ts index 92c0de419..a5be5f114 100644 --- a/server/middlewares/validators/video-channels.ts +++ b/server/middlewares/validators/video-channels.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import * as express from 'express' | 1 | 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 { isAccountIdExist } from '../../helpers/custom-validators/accounts' | 4 | import { isAccountIdExist, isAccountNameWithHostExist } from '../../helpers/custom-validators/accounts' |
5 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' | 5 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' |
6 | import { | 6 | import { |
7 | isVideoChannelDescriptionValid, | 7 | isVideoChannelDescriptionValid, |
@@ -15,13 +15,13 @@ import { VideoChannelModel } from '../../models/video/video-channel' | |||
15 | import { areValidationErrors } from './utils' | 15 | import { areValidationErrors } from './utils' |
16 | 16 | ||
17 | const listVideoAccountChannelsValidator = [ | 17 | const listVideoAccountChannelsValidator = [ |
18 | param('accountId').custom(isIdOrUUIDValid).withMessage('Should have a valid account id'), | 18 | param('accountName').exists().withMessage('Should have a valid account name'), |
19 | 19 | ||
20 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 20 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
21 | logger.debug('Checking listVideoAccountChannelsValidator parameters', { parameters: req.body }) | 21 | logger.debug('Checking listVideoAccountChannelsValidator parameters', { parameters: req.body }) |
22 | 22 | ||
23 | if (areValidationErrors(req, res)) return | 23 | if (areValidationErrors(req, res)) return |
24 | if (!await isAccountIdExist(req.params.accountId, res)) return | 24 | if (!await isAccountNameWithHostExist(req.params.accountName, res)) return |
25 | 25 | ||
26 | return next() | 26 | return next() |
27 | } | 27 | } |