aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/parse.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/parse.ts')
-rw-r--r--src/lib/parse.ts29
1 files changed, 14 insertions, 15 deletions
diff --git a/src/lib/parse.ts b/src/lib/parse.ts
index e4bd3497..03d21943 100644
--- a/src/lib/parse.ts
+++ b/src/lib/parse.ts
@@ -1,26 +1,17 @@
import { PUBLIC_DOMAIN } from "$env/static/public";
-import { get, sats, isLiquid, post } from "$lib/utils";
+import { get, isLiquid, auth, post, sats } from "$lib/utils";
import { redirect } from "@sveltejs/kit";
import bip21 from "bip21";
import { validate } from "bitcoin-address-validation";
export default async (s, host) => {
if (!s) return;
- let t = s;
-
- if (t.includes("lightning=")) {
- const url = new URL(t);
- const params = new URLSearchParams(url.search);
- t = params.get("lightning");
- }
-
- if (t.startsWith("http")) redirect(307, t);
- if (t.startsWith(host)) redirect(307, `http://${t}`);
-
+ let t = s.trim();
let amount;
let user;
- t = t.trim();
+ if (t.startsWith("http")) redirect(307, t);
+ if (t.startsWith(host)) redirect(307, `http://${t}`);
if (t.startsWith("lightning:")) t = t.replace("lightning:", "");
if (t.endsWith(`@${PUBLIC_DOMAIN}`)) t = t.split("@")[0];
@@ -30,8 +21,6 @@ export default async (s, host) => {
} catch (e) {}
}
- if (t.includes("/fund")) redirect(307, t.substring(t.indexOf("/fund")));
-
// lightning
if (t.toLowerCase().startsWith("lightning:"))
t = t.toLowerCase().replace("lightning:", "");
@@ -44,6 +33,12 @@ export default async (s, host) => {
redirect(307, `/send/lightning/${t}`);
}
+ if (t.includes("lightning=")) {
+ const url = new URL(t);
+ const params = new URLSearchParams(url.search);
+ t = params.get("lightning");
+ }
+
if (t.toLowerCase().startsWith("ln")) {
try {
await get(`/invoice/${t}`);
@@ -70,6 +65,8 @@ export default async (s, host) => {
redirect(307, `/ecash/${id}`);
}
+ if (t.startsWith("creq")) redirect(307, `/send/ecash/${t}`);
+
// user
try {
user = await get(`/users/${t.split("/")[0]}`);
@@ -79,6 +76,8 @@ export default async (s, host) => {
if (user) redirect(307, `/pay/${t}`);
let fund;
+ if (t.includes("/fund")) redirect(307, t.substring(t.indexOf("/fund")));
+
try {
fund = await get(`/fund/${t}`);
} catch (e) {}