diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/components/InvoiceData.svelte | 2 | ||||
| -rw-r--r-- | src/components/Qr.svelte | 8 | ||||
| -rw-r--r-- | src/routes/(app)/[username]/receive/+page.server.js | 13 | ||||
| -rw-r--r-- | src/routes/(app)/fund/[id]/+page.server.ts | 10 | ||||
| -rw-r--r-- | src/routes/(app)/invoice/[id]/+layout.server.ts | 4 | ||||
| -rw-r--r-- | src/routes/(app)/otpsecret/+server.ts | 5 | ||||
| -rw-r--r-- | src/routes/(app)/qr/[text]/+page.server.ts | 7 | ||||
| -rw-r--r-- | src/routes/(app)/qr/[text]/+page.svelte | 4 | ||||
| -rw-r--r-- | src/routes/(app)/qr/[text]/raw/+server.ts | 16 | ||||
| -rw-r--r-- | src/routes/(app)/settings/security/+page.svelte | 2 |
10 files changed, 34 insertions, 37 deletions
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 @@ <div> <a href={link}> <img - {src} + src={`/qr/${encodeURIComponent(invoice.text)}/raw`} class="mx-auto z-10 max-w-[360px] border-4 border-white" alt={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 @@ <script> import screenfull from "screenfull"; - let { src } = $props(); + let { text } = $props(); let qr = $state(); </script> @@ -10,5 +10,9 @@ onclick={() => screenfull.toggle(qr)} onkeydown={() => screenfull.toggle(qr)} > - <img {src} class="mx-auto" alt="QR Code" /> + <img + src={`/qr/${encodeURIComponent(text)}/raw`} + class="mx-auto" + alt="QR Code" + /> </div> 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; </script> <div class="container px-4 max-w-4xl mx-auto space-y-5"> - <Qr {src} /> + <Qr {text} /> <button type="button" diff --git a/src/routes/(app)/qr/[text]/raw/+server.ts b/src/routes/(app)/qr/[text]/raw/+server.ts new file mode 100644 index 00000000..a24d3a3c --- /dev/null +++ b/src/routes/(app)/qr/[text]/raw/+server.ts @@ -0,0 +1,16 @@ +import Qr from "qrcode-base64"; + +export async function GET({ params }) { + const { text } = params; + + const dataUri = Qr.drawImg(text, { size: 600 }); + const base64Data = dataUri.split(",")[1]; + const binaryData = Buffer.from(base64Data, "base64"); + + return new Response(binaryData, { + headers: { + "Content-Type": "image/gif", + "Cache-Control": "public, max-age=31536000, immutable", + }, + }); +} diff --git a/src/routes/(app)/settings/security/+page.svelte b/src/routes/(app)/settings/security/+page.svelte index 8298652b..c4a0b5be 100644 --- a/src/routes/(app)/settings/security/+page.svelte +++ b/src/routes/(app)/settings/security/+page.svelte @@ -209,7 +209,7 @@ {#if setting2fa} <a href={otp.uri}> - <Qr src={otp.qr} /> + <Qr text={otp.uri} /> </a> <div class="text-center my-4"> |
