From d47807d6e09a7d72ea1e0a54f1ed6dbec84a2a90 Mon Sep 17 00:00:00 2001 From: ZareMate <0.zaremate@gmail.com> Date: Tue, 27 Jan 2026 14:06:29 +0100 Subject: [PATCH] test --- server.js | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/server.js b/server.js index 7351aaef..e6890e22 100644 --- a/server.js +++ b/server.js @@ -196,6 +196,55 @@ app.get("/api/item/:id", (req, res) => { }); }); +app.post("/api/shop/items/buy", (req, res) => { + const { shopId, address, items } = req.body; + + // Basic validation + if ( + typeof shopId !== "number" || + typeof address !== "string" || + !Array.isArray(items) + ) { + return res.status(400).json({ + ok: false, + error: "Invalid parameters", + }); + } + + for (const item of items) { + if (typeof item.id !== "string" || typeof item.quantity !== "number") { + return res.status(400).json({ + ok: false, + error: "Invalid item format", + }); + } + } + + // Build request payload + const request = { + type: "request", + to: shopId, + address, + items: items.map((item) => ({ + name: item.id, + _requestCount: item.quantity, + })), + }; + + // Send via WebSocket + wss.clients.forEach((client) => { + if (client.readyState === 1) { + client.send(JSON.stringify(request)); + } + }); + + return res.status(200).json({ + ok: true, + message: "Items sent successfully", + data: request, + }); +}); + // Serve the items UI page from public/items.html for the /items route. // The actual HTML/JS for the page lives in public/items.html (moved from server-side rendering). app.get("/", (req, res) => {