Major changes
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user