Aktualizovat server.js
This commit is contained in:
23
server.js
23
server.js
@@ -6,28 +6,35 @@ const PORT = 8080;
|
|||||||
app.use(cors());
|
app.use(cors());
|
||||||
app.use(express.json());
|
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 = {
|
let currentSongData = {
|
||||||
artist: "Čekám na Spotify...",
|
artist: "Čekám na Spotify...",
|
||||||
title: "Spusťte hudbu",
|
title: "Spusťte hudbu",
|
||||||
coverImg: null,
|
coverImg: null,
|
||||||
progressTime: "0:00/0:00",
|
progressTime: "0:00/0:00",
|
||||||
ad: "false"
|
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) => {
|
app.post('/endpoint', (req, res) => {
|
||||||
if (req.body && req.body.artist) {
|
if (req.body) {
|
||||||
currentSongData = req.body; // Uložíme data do paměti
|
// Přepíšeme celá přijatá data
|
||||||
console.log("--- New Song Received ---");
|
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(`Interpret: ${currentSongData.artist}`);
|
||||||
console.log(`Skladba: ${currentSongData.title}`);
|
console.log(`Skladba: ${currentSongData.title}`);
|
||||||
console.log(`Čas: ${currentSongData.progressTime} | Reklama: ${currentSongData.ad}`);
|
console.log(`Čas: ${currentSongData.progressTime} | Reklama: ${currentSongData.isAd}`);
|
||||||
}
|
}
|
||||||
res.sendStatus(200);
|
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) => {
|
app.get('/endpoint', (req, res) => {
|
||||||
res.json(currentSongData);
|
res.json(currentSongData);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user