""refactor"" basically everything

This commit is contained in:
Enstrayed
2024-09-22 14:04:15 -07:00
parent 2e527a8539
commit 5f1181476d
14 changed files with 78 additions and 90 deletions

View File

@@ -1,33 +0,0 @@
const { app, globalConfig } = require("../index.js")
const { queryLastfm } = require("../liberals/libnowplaying.js")
var timeSinceLastLastfmQuery = Date.now()-5000
var cachedLastfmResult = {}
const notPlayingAnythingPlaceholder = {
"json": {
"playing": false
},
"html": `<span>I'm not currently listening to anything.</span>`
}
app.get("/api/nowplaying", (rreq,rres) => {
if (Date.now() < timeSinceLastLastfmQuery+5000) {
rres.send(cachedLastfmResult[rreq.query.format] ?? cachedLastfmResult.json)
} else {
timeSinceLastLastfmQuery = Date.now()
queryLastfm().then(response => {
if (response == {}) {
cachedLastfmResult = notPlayingAnythingPlaceholder
} else {
cachedLastfmResult = response
}
rres.send(cachedLastfmResult[rreq.query.format] ?? cachedLastfmResult.json)
})
}
})
module.exports = {app}