Added route to get current played song

This commit is contained in:
dbroqua 2020-05-02 10:14:17 +02:00
parent edde981b1f
commit 90d297c3b3

6
app.js
View File

@ -12,6 +12,7 @@ import {
} from "./libs/Format";
let currentSongId = "";
let currentSong = {};
const pino = new Pino({
prettyPrint: true,
@ -41,6 +42,7 @@ app.post("/post", function (req, res, next) {
const newSongId = req.body.now_playing.song.id;
if (newSongId !== currentSongId) {
currentSongId = newSongId;
currentSong = req.body.now_playing.song;
fs.writeFile("./currentSongId", currentSongId, (err) => {
if (err) {
req.log.error(err);
@ -58,6 +60,10 @@ app.post("/post", function (req, res, next) {
}
});
app.get("/current", function (req, res, next) {
formatResponse(req, res, next, null, currentSong);
});
// Gestion des erreurs
app.use((err, req, res, next) => {
res.error = err;