mirror of
https://github.com/turt2live/matrix-dimension.git
synced 2024-10-01 01:05:53 -04:00
Use integrated URL instead of split-host
This commit is contained in:
parent
d4502a5e41
commit
dc54c50c39
5
package-lock.json
generated
5
package-lock.json
generated
@ -16765,11 +16765,6 @@
|
|||||||
"integrity": "sha512-oYBGY0GV1H1dX+ZdKnB6JVsYC1w/Xl20H111eb+WSS8nUYmlHgGb4y5buFSkzzceEeYYh5kMhXoAmoTpiQauiA==",
|
"integrity": "sha512-oYBGY0GV1H1dX+ZdKnB6JVsYC1w/Xl20H111eb+WSS8nUYmlHgGb4y5buFSkzzceEeYYh5kMhXoAmoTpiQauiA==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"split-host": {
|
|
||||||
"version": "0.1.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/split-host/-/split-host-0.1.1.tgz",
|
|
||||||
"integrity": "sha512-nrlaPJMHkr3hKx7aCyr+S0OgUvAm/xKzWWMHej0IsMamWjRC52Fv+NGZwuqRE1lyu1iNWCmcrpZ1S1qvk+Uiwg=="
|
|
||||||
},
|
|
||||||
"split-string": {
|
"split-string": {
|
||||||
"version": "3.1.0",
|
"version": "3.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/split-string/-/split-string-3.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/split-string/-/split-string-3.1.0.tgz",
|
||||||
|
@ -53,7 +53,6 @@
|
|||||||
"sequelize": "6.6.2",
|
"sequelize": "6.6.2",
|
||||||
"sequelize-typescript": "^2.1.0",
|
"sequelize-typescript": "^2.1.0",
|
||||||
"sharp": "^0.28.3",
|
"sharp": "^0.28.3",
|
||||||
"split-host": "^0.1.1",
|
|
||||||
"spotify-uri": "^2.2.0",
|
"spotify-uri": "^2.2.0",
|
||||||
"sqlite3": "^5.0.2",
|
"sqlite3": "^5.0.2",
|
||||||
"telegraf": "^3.30.1",
|
"telegraf": "^3.30.1",
|
||||||
|
@ -3,7 +3,6 @@ import { LogService } from "matrix-js-snippets";
|
|||||||
import { Cache, CACHE_FEDERATION } from "../MemoryCache";
|
import { Cache, CACHE_FEDERATION } from "../MemoryCache";
|
||||||
import * as request from "request";
|
import * as request from "request";
|
||||||
import config from "../config";
|
import config from "../config";
|
||||||
import splitHost from 'split-host';
|
|
||||||
import * as requestPromise from "request-promise";
|
import * as requestPromise from "request-promise";
|
||||||
import { isIP } from "net";
|
import { isIP } from "net";
|
||||||
|
|
||||||
@ -37,12 +36,12 @@ export async function getFederationConnInfo(serverName: string): Promise<IFedera
|
|||||||
|
|
||||||
// Dev note: The remainder of this is largely transcribed from matrix-media-repo
|
// Dev note: The remainder of this is largely transcribed from matrix-media-repo
|
||||||
|
|
||||||
const hp = splitHost(serverName);
|
const hp = new URL(serverName);
|
||||||
if (!hp.host) throw new Error("No hostname provided");
|
if (!hp.host) throw new Error("No hostname provided");
|
||||||
let defaultPort = false;
|
let defaultPort = false;
|
||||||
if (!hp.port) {
|
if (!hp.port) {
|
||||||
defaultPort = true;
|
defaultPort = true;
|
||||||
hp.port = 8448;
|
hp.port = '8448';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 1 of the discovery process: if the hostname is an IP, use that with explicit or default port
|
// Step 1 of the discovery process: if the hostname is an IP, use that with explicit or default port
|
||||||
@ -69,7 +68,7 @@ export async function getFederationConnInfo(serverName: string): Promise<IFedera
|
|||||||
if (typeof (result) === 'string') result = JSON.parse(result);
|
if (typeof (result) === 'string') result = JSON.parse(result);
|
||||||
const wkServerAddr = result['m.server'];
|
const wkServerAddr = result['m.server'];
|
||||||
if (wkServerAddr) {
|
if (wkServerAddr) {
|
||||||
const wkHp = splitHost(wkServerAddr);
|
const wkHp = new URL(wkServerAddr);
|
||||||
if (!wkHp.host) {
|
if (!wkHp.host) {
|
||||||
// noinspection ExceptionCaughtLocallyJS
|
// noinspection ExceptionCaughtLocallyJS
|
||||||
throw new Error("No hostname provided for m.server");
|
throw new Error("No hostname provided for m.server");
|
||||||
@ -77,7 +76,7 @@ export async function getFederationConnInfo(serverName: string): Promise<IFedera
|
|||||||
let wkDefaultPort = false;
|
let wkDefaultPort = false;
|
||||||
if (!wkHp.port) {
|
if (!wkHp.port) {
|
||||||
wkDefaultPort = true;
|
wkDefaultPort = true;
|
||||||
wkHp.port = 8448;
|
wkHp.port = '8448';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 3a: if the delegated host is an IP address, use that (regardless of port)
|
// Step 3a: if the delegated host is an IP address, use that (regardless of port)
|
||||||
|
Loading…
Reference in New Issue
Block a user