From 7801ce67ace77f5de98ddc38d7b0b45c68faeb6b Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Tue, 3 Dec 2024 15:57:40 -0800 Subject: cache qrs --- src/components/InvoiceData.svelte | 2 +- src/components/Qr.svelte | 8 ++++++-- src/routes/(app)/[username]/receive/+page.server.js | 13 +++---------- src/routes/(app)/fund/[id]/+page.server.ts | 10 ++-------- src/routes/(app)/invoice/[id]/+layout.server.ts | 4 +--- src/routes/(app)/otpsecret/+server.ts | 5 +---- src/routes/(app)/qr/[text]/+page.server.ts | 7 +------ src/routes/(app)/qr/[text]/+page.svelte | 4 ++-- src/routes/(app)/qr/[text]/raw/+server.ts | 16 ++++++++++++++++ src/routes/(app)/settings/security/+page.svelte | 2 +- 10 files changed, 34 insertions(+), 37 deletions(-) create mode 100644 src/routes/(app)/qr/[text]/raw/+server.ts (limited to 'src') diff --git a/src/components/InvoiceData.svelte b/src/components/InvoiceData.svelte index de93c08e..e51d9a3b 100644 --- a/src/components/InvoiceData.svelte +++ b/src/components/InvoiceData.svelte @@ -21,7 +21,7 @@
{txt} diff --git a/src/components/Qr.svelte b/src/components/Qr.svelte index c8d33e23..72655ebc 100644 --- a/src/components/Qr.svelte +++ b/src/components/Qr.svelte @@ -1,6 +1,6 @@ @@ -10,5 +10,9 @@ onclick={() => screenfull.toggle(qr)} onkeydown={() => screenfull.toggle(qr)} > - QR Code + QR Code
diff --git a/src/routes/(app)/[username]/receive/+page.server.js b/src/routes/(app)/[username]/receive/+page.server.js index 159a77a2..b73b1d6a 100644 --- a/src/routes/(app)/[username]/receive/+page.server.js +++ b/src/routes/(app)/[username]/receive/+page.server.js @@ -1,14 +1,7 @@ import { redirect } from "@sveltejs/kit"; -import * as Qr from "qrcode-base64"; -export const load = async ({ cookies, params, url }) => { +export const load = async ({ cookies, params: { username }, url }) => { const token = cookies.get("token"); - if (!token) redirect(307, `/pay/${params.username}`); - - const username = cookies.get("username"); - - const text = `${username}@${url.host}`; - const src = Qr.drawImg(text, { size: 500 }); - - return { src, text }; + if (!token) redirect(307, `/pay/${username}`); + return { text: `${username}@${url.host}` }; }; diff --git a/src/routes/(app)/fund/[id]/+page.server.ts b/src/routes/(app)/fund/[id]/+page.server.ts index 4f189133..bc07d721 100644 --- a/src/routes/(app)/fund/[id]/+page.server.ts +++ b/src/routes/(app)/fund/[id]/+page.server.ts @@ -1,13 +1,7 @@ -import { redirect } from "@sveltejs/kit"; import { auth, get, post } from "$lib/utils"; -import Qr from "qrcode-base64"; - -export const load = async ({ params: { id }, url }) => { - const { amount, payments } = await get(`/fund/${id}`); +import { redirect } from "@sveltejs/kit"; - const src = Qr.drawImg(url.href, { size: 300 }); - return { amount, payments, src }; -}; +export const load = async ({ params: { id } }) => get(`/fund/${id}`); export const actions = { default: async ({ cookies, locals, params }) => { diff --git a/src/routes/(app)/invoice/[id]/+layout.server.ts b/src/routes/(app)/invoice/[id]/+layout.server.ts index f89e0de8..590e5d4d 100644 --- a/src/routes/(app)/invoice/[id]/+layout.server.ts +++ b/src/routes/(app)/invoice/[id]/+layout.server.ts @@ -1,6 +1,5 @@ import { get } from "$lib/utils"; import { redirect } from "@sveltejs/kit"; -import * as Qr from "qrcode-base64"; export async function load({ cookies, depends, params, url, parent }) { depends("app:invoice"); @@ -35,7 +34,6 @@ export async function load({ cookies, depends, params, url, parent }) { } } - const src = Qr.drawImg(invoice?.text || "", { size: 500 }); const theme = cookies.get("theme") || "light"; - return { id, invoice, subject, src, user, token, theme }; + return { id, invoice, subject, user, token, theme }; } diff --git a/src/routes/(app)/otpsecret/+server.ts b/src/routes/(app)/otpsecret/+server.ts index 7226a7c9..c260b7da 100644 --- a/src/routes/(app)/otpsecret/+server.ts +++ b/src/routes/(app)/otpsecret/+server.ts @@ -1,5 +1,4 @@ import { auth, post } from "$lib/utils"; -import Qr from "qrcode-base64"; import { error } from "@sveltejs/kit"; export async function POST({ cookies, request }) { @@ -7,9 +6,7 @@ export async function POST({ cookies, request }) { const body = await request.json(); const { username, secret } = await post("/otpsecret", body, auth(cookies)); const uri = `otpauth://totp/coinos:${username}?secret=${secret}&period=30&digits=6&algorithm=SHA1&issuer=coinos`; - return new Response( - JSON.stringify({ secret, uri, qr: Qr.drawImg(uri, { size: 600 }) }), - ); + return new Response(JSON.stringify({ secret, uri })); } catch (e: any) { if (e.message.includes("pin")) throw e; error(500, "Problem saving secret"); diff --git a/src/routes/(app)/qr/[text]/+page.server.ts b/src/routes/(app)/qr/[text]/+page.server.ts index 09e7593f..5a9debb3 100644 --- a/src/routes/(app)/qr/[text]/+page.server.ts +++ b/src/routes/(app)/qr/[text]/+page.server.ts @@ -1,8 +1,3 @@ -import Qr from "qrcode-base64"; - export async function load({ params }) { - const { text } = params; - const src = Qr.drawImg(text, { size: 600 }); - - return { src, text }; + return params; } diff --git a/src/routes/(app)/qr/[text]/+page.svelte b/src/routes/(app)/qr/[text]/+page.svelte index 02a5b718..46420743 100644 --- a/src/routes/(app)/qr/[text]/+page.svelte +++ b/src/routes/(app)/qr/[text]/+page.svelte @@ -3,11 +3,11 @@ import Qr from "$comp/Qr.svelte"; import { back, copy } from "$lib/utils"; let { data } = $props(); - let { src, text } = data; + let { text } = data;
- +