1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-11-27 08:21:03 +02:00

Use url-parse

This commit is contained in:
Roman 2021-08-15 13:48:32 +01:00
parent 20d1f74ee4
commit 6c18c6ddc7

View File

@ -1,3 +1,5 @@
const URL = require('url-parse');
export function isCallbackUrl(s: string) {
return s.startsWith('joplin://x-callback-url/');
}
@ -27,15 +29,9 @@ export interface CallbackUrlInfo {
export function parseCallbackUrl(s: string): CallbackUrlInfo {
if (!isCallbackUrl(s)) throw new Error(`Invalid callback url ${s}`);
const url = new URL(s);
const params: Record<string, string> = {};
for (const [key, value] of url.searchParams) {
params[key] = value;
}
const url = new URL(s, true);
return {
command: url.pathname.substring(url.pathname.lastIndexOf('/') + 1) as Command,
params,
params: url.query,
};
}