Add matrix-URI parsing support using matrix-uri-parser
This commit is contained in:
parent
7d22a57874
commit
9c48ff884c
3 changed files with 31 additions and 0 deletions
|
@ -33,5 +33,8 @@
|
|||
"rollup-plugin-terser": "^7.0.2",
|
||||
"serve-static": "^1.14.1",
|
||||
"xxhashjs": "^0.2.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"matrix-uri-parser": "https://github.com/matrix-org/matrix-uri-parser-js"
|
||||
}
|
||||
}
|
||||
|
|
24
src/Link.js
24
src/Link.js
|
@ -16,6 +16,7 @@ limitations under the License.
|
|||
|
||||
import {createEnum} from "./utils/enum.js";
|
||||
import {orderedUnique} from "./utils/unique.js";
|
||||
import {MatrixURL} from "matrix-uri-parser";
|
||||
|
||||
const ROOMALIAS_PATTERN = /^#([^:]*):(.+)$/;
|
||||
const ROOMID_PATTERN = /^!([^:]*):(.+)$/;
|
||||
|
@ -111,6 +112,29 @@ export class Link {
|
|||
return null;
|
||||
}
|
||||
linkStr = linkStr.substr(2);
|
||||
|
||||
const linkStrMatrixUrl = fragment.substr(2).startsWith("matrix:") ? fragment.substr(2) : "matrix:"+fragment.substr(2);
|
||||
|
||||
try {
|
||||
const parsedUrl = new MatrixURL(linkStrMatrixUrl); // Try to parse URL as matrix-URL
|
||||
|
||||
let [localPart, server] = parsedUrl.id.split(":"); // Split ID into local and server part
|
||||
|
||||
if(!server) server = parsedUrl.authority; // If no server part is present, try to use authority
|
||||
if(!server) return null; // Reject if we can't figure out the server
|
||||
|
||||
const webInstances = getWebInstanceMap(parsedUrl.unknownParams);
|
||||
|
||||
let clientId;
|
||||
|
||||
const clientParam = parsedUrl.unknownParams.find(([key]) => key === "client");
|
||||
if(clientParam) clientId = clientParam[1];
|
||||
|
||||
const link = new Link(clientId, parsedUrl.via, parsedUrl.kind, localPart, server, webInstances, parsedUrl.eventId);
|
||||
|
||||
return link;
|
||||
} catch(e) {} // The fragment was no matrix-URL.
|
||||
|
||||
const [identifier, eventId] = linkStr.split("/");
|
||||
|
||||
let viaServers = [];
|
||||
|
|
|
@ -1418,6 +1418,10 @@ matched@^5.0.0:
|
|||
glob "^7.1.6"
|
||||
picomatch "^2.2.1"
|
||||
|
||||
"matrix-uri-parser@https://github.com/matrix-org/matrix-uri-parser-js":
|
||||
version "0.1.0"
|
||||
resolved "https://github.com/matrix-org/matrix-uri-parser-js#506c2545dae5e0d05633bc905a937731a1e69104"
|
||||
|
||||
mdn-polyfills@^5.20.0:
|
||||
version "5.20.0"
|
||||
resolved "https://registry.yarnpkg.com/mdn-polyfills/-/mdn-polyfills-5.20.0.tgz#ca8247edf20a4f60dec6804372229812b348260b"
|
||||
|
|
Loading…
Reference in a new issue