diff options
author | Chocobozzz <me@florianbigard.com> | 2017-12-19 14:21:14 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2017-12-19 14:21:14 +0100 |
commit | 0405ab52dc0f445b88f8de76e30d6e6719196023 (patch) | |
tree | 85bb741791296ba1ede1efccd8d22f9f71169dc7 | |
parent | d4c6a3b985ea56f730d11fb1c5f04a4fdc86e4dc (diff) | |
download | PeerTube-0405ab52dc0f445b88f8de76e30d6e6719196023.tar.gz PeerTube-0405ab52dc0f445b88f8de76e30d6e6719196023.tar.zst PeerTube-0405ab52dc0f445b88f8de76e30d6e6719196023.zip |
Set port if not specified in webfinger
-rw-r--r-- | server/helpers/utils.ts | 18 | ||||
-rw-r--r-- | server/middlewares/servers.ts | 16 | ||||
-rw-r--r-- | server/middlewares/validators/webfinger.ts | 4 |
3 files changed, 19 insertions, 19 deletions
diff --git a/server/helpers/utils.ts b/server/helpers/utils.ts index ef6a878cf..769aa83c6 100644 --- a/server/helpers/utils.ts +++ b/server/helpers/utils.ts | |||
@@ -2,13 +2,26 @@ import * as express from 'express' | |||
2 | import { Model } from 'sequelize-typescript' | 2 | import { Model } from 'sequelize-typescript' |
3 | import { ResultList } from '../../shared' | 3 | import { ResultList } from '../../shared' |
4 | import { VideoResolution } from '../../shared/models/videos' | 4 | import { VideoResolution } from '../../shared/models/videos' |
5 | import { CONFIG } from '../initializers' | 5 | import { CONFIG, REMOTE_SCHEME } from '../initializers' |
6 | import { UserModel } from '../models/account/user' | 6 | import { UserModel } from '../models/account/user' |
7 | import { ActorModel } from '../models/activitypub/actor' | 7 | import { ActorModel } from '../models/activitypub/actor' |
8 | import { ApplicationModel } from '../models/application/application' | 8 | import { ApplicationModel } from '../models/application/application' |
9 | import { pseudoRandomBytesPromise } from './core-utils' | 9 | import { pseudoRandomBytesPromise } from './core-utils' |
10 | import { logger } from './logger' | 10 | import { logger } from './logger' |
11 | 11 | ||
12 | function getHostWithPort (host: string) { | ||
13 | const splitted = host.split(':') | ||
14 | |||
15 | // The port was not specified | ||
16 | if (splitted.length === 1) { | ||
17 | if (REMOTE_SCHEME.HTTP === 'https') return host + ':443' | ||
18 | |||
19 | return host + ':80' | ||
20 | } | ||
21 | |||
22 | return host | ||
23 | } | ||
24 | |||
12 | function badRequest (req: express.Request, res: express.Response, next: express.NextFunction) { | 25 | function badRequest (req: express.Request, res: express.Response, next: express.NextFunction) { |
13 | return res.type('json').status(400).end() | 26 | return res.type('json').status(400).end() |
14 | } | 27 | } |
@@ -108,5 +121,6 @@ export { | |||
108 | computeResolutionsToTranscode, | 121 | computeResolutionsToTranscode, |
109 | resetSequelizeInstance, | 122 | resetSequelizeInstance, |
110 | getServerActor, | 123 | getServerActor, |
111 | SortType | 124 | SortType, |
125 | getHostWithPort | ||
112 | } | 126 | } |
diff --git a/server/middlewares/servers.ts b/server/middlewares/servers.ts index 488f9c368..87bbe9fd7 100644 --- a/server/middlewares/servers.ts +++ b/server/middlewares/servers.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import 'express-validator' | 1 | import 'express-validator' |
2 | import * as express from 'express' | 2 | import * as express from 'express' |
3 | import { getHostWithPort } from '../helpers' | ||
3 | 4 | ||
4 | import { REMOTE_SCHEME } from '../initializers' | 5 | import { REMOTE_SCHEME } from '../initializers' |
5 | 6 | ||
@@ -25,18 +26,3 @@ function setBodyHostsPort (req: express.Request, res: express.Response, next: ex | |||
25 | export { | 26 | export { |
26 | setBodyHostsPort | 27 | setBodyHostsPort |
27 | } | 28 | } |
28 | |||
29 | // --------------------------------------------------------------------------- | ||
30 | |||
31 | function getHostWithPort (host: string) { | ||
32 | const splitted = host.split(':') | ||
33 | |||
34 | // The port was not specified | ||
35 | if (splitted.length === 1) { | ||
36 | if (REMOTE_SCHEME.HTTP === 'https') return host + ':443' | ||
37 | |||
38 | return host + ':80' | ||
39 | } | ||
40 | |||
41 | return host | ||
42 | } | ||
diff --git a/server/middlewares/validators/webfinger.ts b/server/middlewares/validators/webfinger.ts index 2c8351799..894c72498 100644 --- a/server/middlewares/validators/webfinger.ts +++ b/server/middlewares/validators/webfinger.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { query } from 'express-validator/check' | 2 | import { query } from 'express-validator/check' |
3 | import { logger } from '../../helpers' | 3 | import { getHostWithPort, logger } from '../../helpers' |
4 | import { isWebfingerResourceValid } from '../../helpers/custom-validators/webfinger' | 4 | import { isWebfingerResourceValid } from '../../helpers/custom-validators/webfinger' |
5 | import { ActorModel } from '../../models/activitypub/actor' | 5 | import { ActorModel } from '../../models/activitypub/actor' |
6 | import { areValidationErrors } from './utils' | 6 | import { areValidationErrors } from './utils' |
@@ -14,7 +14,7 @@ const webfingerValidator = [ | |||
14 | if (areValidationErrors(req, res)) return | 14 | if (areValidationErrors(req, res)) return |
15 | 15 | ||
16 | // Remove 'acct:' from the beginning of the string | 16 | // Remove 'acct:' from the beginning of the string |
17 | const nameWithHost = req.query.resource.substr(5) | 17 | const nameWithHost = getHostWithPort(req.query.resource.substr(5)) |
18 | const [ name ] = nameWithHost.split('@') | 18 | const [ name ] = nameWithHost.split('@') |
19 | 19 | ||
20 | const actor = await ActorModel.loadLocalByName(name) | 20 | const actor = await ActorModel.loadLocalByName(name) |