fix: more nojs
This commit is contained in:
@@ -236,15 +236,66 @@ export const dashboard = new Elysia()
|
||||
if (!resolved?.accountId) return redirect("/dashboard");
|
||||
const [acc] = await sql`SELECT plan, plan_expires_at FROM accounts WHERE id = ${resolved.accountId}`;
|
||||
if (acc.plan === "lifetime") return redirect("/dashboard/settings");
|
||||
return html("checkout", { nav: "settings", account: acc, payApi: process.env.PAY_API || "https://pay.pingql.com", invoiceId: null });
|
||||
|
||||
// Fetch coins server-side for no-JS rendering
|
||||
const payApi = process.env.PAY_API || "https://pay.pingql.com";
|
||||
let coins: any[] = [];
|
||||
try {
|
||||
const res = await fetch(`${payApi}/coins`);
|
||||
const data = await res.json();
|
||||
coins = data.coins || [];
|
||||
} catch {}
|
||||
|
||||
return html("checkout", { nav: "settings", account: acc, payApi, invoiceId: null, coins, invoice: null });
|
||||
})
|
||||
|
||||
// Existing invoice by ID — survives refreshes
|
||||
// Existing invoice by ID — SSR the payment status
|
||||
.get("/dashboard/checkout/:id", async ({ cookie, headers, params }) => {
|
||||
const resolved = await getAccountId(cookie, headers);
|
||||
if (!resolved?.accountId) return redirect("/dashboard");
|
||||
const [acc] = await sql`SELECT plan, plan_expires_at FROM accounts WHERE id = ${resolved.accountId}`;
|
||||
return html("checkout", { nav: "settings", account: acc, payApi: process.env.PAY_API || "https://pay.pingql.com", invoiceId: params.id });
|
||||
|
||||
const payApi = process.env.PAY_API || "https://pay.pingql.com";
|
||||
const key = cookie?.pingql_key?.value;
|
||||
let invoice: any = null;
|
||||
let coins: any[] = [];
|
||||
try {
|
||||
const [invoiceRes, coinsRes] = await Promise.all([
|
||||
fetch(`${payApi}/checkout/${params.id}`, { headers: { "Authorization": `Bearer ${key}` } }),
|
||||
fetch(`${payApi}/coins`),
|
||||
]);
|
||||
if (invoiceRes.ok) invoice = await invoiceRes.json();
|
||||
const coinsData = await coinsRes.json();
|
||||
coins = coinsData.coins || [];
|
||||
} catch {}
|
||||
|
||||
return html("checkout", { nav: "settings", account: acc, payApi, invoiceId: params.id, coins, invoice });
|
||||
})
|
||||
|
||||
// Create checkout via form POST (no-JS)
|
||||
.post("/dashboard/checkout", async ({ cookie, headers, body }) => {
|
||||
const resolved = await getAccountId(cookie, headers);
|
||||
if (!resolved?.accountId) return redirect("/dashboard");
|
||||
|
||||
const payApi = process.env.PAY_API || "https://pay.pingql.com";
|
||||
const key = cookie?.pingql_key?.value;
|
||||
const b = body as any;
|
||||
|
||||
try {
|
||||
const res = await fetch(`${payApi}/checkout`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json", "Authorization": `Bearer ${key}` },
|
||||
body: JSON.stringify({
|
||||
plan: b.plan,
|
||||
coin: b.coin,
|
||||
months: b.months ? Number(b.months) : undefined,
|
||||
}),
|
||||
});
|
||||
const data = await res.json();
|
||||
if (res.ok && data.id) return redirect(`/dashboard/checkout/${data.id}`);
|
||||
} catch {}
|
||||
|
||||
return redirect("/dashboard/checkout");
|
||||
})
|
||||
|
||||
// New monitor
|
||||
|
||||
Reference in New Issue
Block a user