44 lines
1.3 KiB
JavaScript
44 lines
1.3 KiB
JavaScript
const express = require('express');
|
|
const cors = require('cors');
|
|
const app = express();
|
|
const PORT = 8080;
|
|
|
|
app.use(cors());
|
|
app.use(express.json());
|
|
|
|
// Ú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",
|
|
isAd: false
|
|
};
|
|
|
|
// 1. Endpoint pro příjem dat z Chrome / Tampermonkey (POST)
|
|
app.post('/endpoint', (req, res) => {
|
|
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 pro Python widget (GET)
|
|
app.get('/endpoint', (req, res) => {
|
|
res.json(currentSongData);
|
|
});
|
|
|
|
app.listen(PORT, '0.0.0.0', () => {
|
|
console.log(`Server běží a poslouchá na portu ${PORT}...`);
|
|
}); |