aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-05-24 15:30:28 +0200
committerChocobozzz <me@florianbigard.com>2018-05-24 15:30:28 +0200
commitd14a9532a1363b464d6d15fce86afc4983a8357e (patch)
tree21f7c65eaa6bf5527637f093f79a4a61b46f40b7 /server/middlewares
parentb528582df28f20ec7481d3c73d16b4291fe9c7e7 (diff)
downloadPeerTube-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.ts12
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'
2import { param } from 'express-validator/check' 2import { param } from 'express-validator/check'
3import { 3import {
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'
9import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc'
10import { logger } from '../../helpers/logger' 10import { logger } from '../../helpers/logger'
11import { areValidationErrors } from './utils' 11import { areValidationErrors } from './utils'
12import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc'
12 13
13const localAccountValidator = [ 14const 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
26const accountsGetValidator = [ 27const 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 }