From dcc2697176c1d48228094873f8bce4b1952a3011 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Hosa?= Date: Thu, 24 Sep 2026 16:53:37 +0000 Subject: [PATCH] Aktualizovat server.js --- server.js | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/server.js b/server.js index 56c39d0..f114d00 100644 --- a/server.js +++ b/server.js @@ -6,32 +6,39 @@ const PORT = 8080; app.use(cors()); app.use(express.json()); -// Sem si budeme ukládat poslední přijatou skladbu +// Úložiště pro aktuální stav přehrávání let currentSongData = { - artist: "Čekám na Spotify...", - title: "Spusťte hudbu", - coverImg: null, - progressTime: "0:00/0:00", - ad: "false" + artist: "Čekám na Spotify...", + title: "Spusťte hudbu", + coverImg: null, + progressTime: "0:00/0:00", + isAd: false }; -// 1. Endpoint, kam Chrome rozšíření posílá data (POST) +// 1. Endpoint pro příjem dat z Chrome / Tampermonkey (POST) app.post('/endpoint', (req, res) => { - if (req.body && req.body.artist) { - currentSongData = req.body; // Uložíme data do paměti - console.log("--- New Song Received ---"); - console.log(`Interpret: ${currentSongData.artist}`); - console.log(`Skladba: ${currentSongData.title}`); - console.log(`Čas: ${currentSongData.progressTime} | Reklama: ${currentSongData.ad}`); - } - res.sendStatus(200); + if (req.body) { + // Přepíšeme celá přijatá data + currentSongData = req.body; + + // Sjednocení klíče pro reklamu (kdyby rozšíření poslalo 'ad' i 'isAd') + if (req.body.ad !== undefined && req.body.isAd === undefined) { + currentSongData.isAd = (req.body.ad === true || req.body.ad === "true"); + } + + console.log("--- New Event Received ---"); + console.log(`Interpret: ${currentSongData.artist}`); + console.log(`Skladba: ${currentSongData.title}`); + console.log(`Čas: ${currentSongData.progressTime} | Reklama: ${currentSongData.isAd}`); + } + res.sendStatus(200); }); -// 2. Endpoint, ze kterého si Python widget čte data (GET) +// 2. Endpoint pro Python widget (GET) app.get('/endpoint', (req, res) => { - res.json(currentSongData); + res.json(currentSongData); }); app.listen(PORT, '0.0.0.0', () => { - console.log(`Server běží a poslouchá na portu ${PORT}...`); + console.log(`Server běží a poslouchá na portu ${PORT}...`); }); \ No newline at end of file