mirror of
https://github.com/theoleuthardt/werkzeugkiste.git
synced 2026-06-13 09:37:53 +00:00
feat: backend route for generating qr codes out of data
This commit is contained in:
parent
ccca78cec0
commit
3d3f56991b
4 changed files with 356 additions and 2 deletions
33
backend/src/routes/generateqrcode.route.ts
Normal file
33
backend/src/routes/generateqrcode.route.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
|
||||
import QRCode from "qrcode";
|
||||
|
||||
interface RequestBody {
|
||||
text: string;
|
||||
}
|
||||
|
||||
export async function generateQRCode(app: FastifyInstance) {
|
||||
app.post(
|
||||
"/api/generate-qrcode",
|
||||
async (
|
||||
request: FastifyRequest<{ Body: RequestBody }>,
|
||||
reply: FastifyReply,
|
||||
) => {
|
||||
const data = request.body;
|
||||
|
||||
if (!data) {
|
||||
return reply.status(400).send({ error: "Missing data parameter" });
|
||||
}
|
||||
|
||||
try {
|
||||
const qrCodeDataUrl = QRCode.toDataURL(data.text);
|
||||
return reply
|
||||
.header("Content-Type", "application/json")
|
||||
.status(200)
|
||||
.send({ qrCode: qrCodeDataUrl });
|
||||
} catch (error) {
|
||||
console.error("QR Code generation error:", error);
|
||||
reply.status(500).send({ error: "Error generating QR code" });
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue