its still fucked but etyd.cc will work now

This commit is contained in:
Enstrayed
2024-09-24 23:15:23 -07:00
parent 5f1181476d
commit 0bf467a1c8
7 changed files with 169 additions and 161 deletions

26
routes/nowplaying.js Normal file
View File

@@ -0,0 +1,26 @@
import { app, globalConfig } from "../index.js"
import { queryLastfm } from "../liberals/libnowplaying.js"
var timeSinceLastLastfmQuery = Date.now()-5000
var cachedLastfmResult = {}
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)
})
}
})
export {app}