Major changes

This commit is contained in:
Enstrayed
2024-08-21 17:26:23 -07:00
parent 8c2e39e88c
commit 05c7261c46
10 changed files with 90 additions and 176 deletions

View File

@@ -1,5 +1,5 @@
const { app, globalConfig } = require("../index.js")
const { queryLastfm } = require("../liberals/nowplaying.js")
const { queryLastfm } = require("../liberals/libnowplaying.js")
var timeSinceLastLastfmQuery = Date.now()-5000
var cachedLastfmResult = {}
@@ -11,14 +11,14 @@ const notPlayingAnythingPlaceholder = {
"html": `<span>I'm not currently listening to anything.</span>`
}
app.get("/nowplaying", (rreq,rres) => {
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 == 1) {
if (response == {}) {
cachedLastfmResult = notPlayingAnythingPlaceholder
} else {
cachedLastfmResult = response