From 26609ebd6b7a546e3ba4e154360bac6120fa8090 Mon Sep 17 00:00:00 2001 From: Martin Berka Date: Thu, 29 Jun 2023 12:05:43 +0200 Subject: [PATCH] =?UTF-8?q?Do=C4=8Dasn=C3=A1=20oprava=20zobrazov=C3=A1n?= =?UTF-8?q?=C3=AD=20QR=20k=C3=B3d=C5=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/Api.ts | 4 ++-- client/src/App.tsx | 2 +- server/src/index.ts | 24 ++++++++++++++---------- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/client/src/Api.ts b/client/src/Api.ts index ff89e73..4f26ac6 100644 --- a/client/src/Api.ts +++ b/client/src/Api.ts @@ -22,8 +22,8 @@ const api = { post: (url: string, body: TBody) => request(url, { method: 'POST', body, headers: { 'Content-Type': 'application/json' } }), } -export const getQrUrl = () => { - return `${getBaseUrl()}/api/qr`; +export const getQrUrl = (login: string) => { + return `${getBaseUrl()}/api/qr?login=${login}`; } export const getData = async () => { diff --git a/client/src/App.tsx b/client/src/App.tsx index 745f1ed..871153b 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -353,7 +353,7 @@ function App() {

QR platba

Částka: {myOrder.totalPrice} Kč
- QR kód + QR kód

Generování QR kódů je v experimentální fázi - doporučujeme si překontrolovat údaje před odesláním platby.

} diff --git a/server/src/index.ts b/server/src/index.ts index a8635c7..48b07cf 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -57,6 +57,20 @@ app.post("/api/login", (req, res) => { res.status(200).json(generateToken(req.body.login)); }); +// TODO dočasné řešení - QR se zobrazuje přes , nemáme sem jak dostat token +app.get("/api/qr", (req, res) => { + // const login = getLogin(parseToken(req)); + if (!req.query?.login) { + throw Error("Nebyl předán login"); + } + const img = getQr(req.query.login as string); + res.writeHead(200, { + 'Content-Type': 'image/png', + 'Content-Length': img.length + }); + res.end(img); +}); + // ---------------------------------------------------- /** Middleware ověřující JWT token */ @@ -182,16 +196,6 @@ app.post("/api/updateChoice", (req, res) => { res.status(200).json(data); }); -app.get("/api/qr", (req, res) => { - const login = getLogin(parseToken(req)); - const img = getQr(login); - res.writeHead(200, { - 'Content-Type': 'image/png', - 'Content-Length': img.length - }); - res.end(img); -}); - app.post("/api/updateNote", (req, res) => { const login = getLogin(parseToken(req)); if (req.body.note && req.body.note.length > 100) {