Host QR codes locally

This commit is contained in:
Cadence Ember
2024-10-04 02:21:57 +13:00
parent 4287a329f5
commit 5a86c07eb9
7 changed files with 40 additions and 6 deletions

19
src/web/routes/qr.js Normal file
View File

@@ -0,0 +1,19 @@
// @ts-check
const {z} = require("zod")
const {defineEventHandler, getValidatedQuery} = require("h3")
const {as} = require("../../passthrough")
const uqr = require("uqr")
const schema = {
qr: z.object({
data: z.string().max(128)
})
}
as.router.get("/qr", defineEventHandler(async event => {
const {data} = await getValidatedQuery(event, schema.qr.parse)
return new Response(uqr.renderSVG(data, {pixelSize: 3}), {headers: {"content-type": "image/svg+xml"}})
}))