diff options
author | Chocobozzz <me@florianbigard.com> | 2018-05-24 15:30:28 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-05-24 15:30:28 +0200 |
commit | d14a9532a1363b464d6d15fce86afc4983a8357e (patch) | |
tree | 21f7c65eaa6bf5527637f093f79a4a61b46f40b7 /server/middlewares | |
parent | b528582df28f20ec7481d3c73d16b4291fe9c7e7 (diff) | |
download | PeerTube-d14a9532a1363b464d6d15fce86afc4983a8357e.tar.gz PeerTube-d14a9532a1363b464d6d15fce86afc4983a8357e.tar.zst PeerTube-d14a9532a1363b464d6d15fce86afc4983a8357e.zip |
Handle account name in client url
More consistent with AP urls
Diffstat (limited to 'server/middlewares')
-rw-r--r-- | server/middlewares/validators/account.ts | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/server/middlewares/validators/account.ts b/server/middlewares/validators/account.ts index 0c4b7051d..c01e742da 100644 --- a/server/middlewares/validators/account.ts +++ b/server/middlewares/validators/account.ts | |||
@@ -2,13 +2,14 @@ import * as express from 'express' | |||
2 | import { param } from 'express-validator/check' | 2 | import { param } from 'express-validator/check' |
3 | import { | 3 | import { |
4 | isAccountIdExist, | 4 | isAccountIdExist, |
5 | isAccountIdValid, | ||
5 | isAccountNameValid, | 6 | isAccountNameValid, |
6 | isAccountNameWithHostExist, | 7 | isAccountNameWithHostExist, |
7 | isLocalAccountNameExist | 8 | isLocalAccountNameExist |
8 | } from '../../helpers/custom-validators/accounts' | 9 | } from '../../helpers/custom-validators/accounts' |
9 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' | ||
10 | import { logger } from '../../helpers/logger' | 10 | import { logger } from '../../helpers/logger' |
11 | import { areValidationErrors } from './utils' | 11 | import { areValidationErrors } from './utils' |
12 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' | ||
12 | 13 | ||
13 | const localAccountValidator = [ | 14 | const localAccountValidator = [ |
14 | param('name').custom(isAccountNameValid).withMessage('Should have a valid account name'), | 15 | param('name').custom(isAccountNameValid).withMessage('Should have a valid account name'), |
@@ -24,13 +25,18 @@ const localAccountValidator = [ | |||
24 | ] | 25 | ] |
25 | 26 | ||
26 | const accountsGetValidator = [ | 27 | const accountsGetValidator = [ |
27 | param('id').custom(isIdOrUUIDValid).withMessage('Should have a valid id'), | 28 | param('id').custom(isAccountIdValid).withMessage('Should have a valid id/uuid/name/name with host'), |
28 | 29 | ||
29 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 30 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
30 | logger.debug('Checking accountsGetValidator parameters', { parameters: req.params }) | 31 | logger.debug('Checking accountsGetValidator parameters', { parameters: req.params }) |
31 | 32 | ||
32 | if (areValidationErrors(req, res)) return | 33 | if (areValidationErrors(req, res)) return |
33 | if (!await isAccountIdExist(req.params.id, 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 | ||
34 | 40 | ||
35 | return next() | 41 | return next() |
36 | } | 42 | } |