This commit is contained in:
Jared Furlow 2025-04-21 21:21:05 -05:00
parent 2d2d3404c1
commit 486bf7cce7

5
dist/start.js vendored
View File

@ -34,9 +34,11 @@ const apiCache = {
};
app.get("/getMostRecentSpotifyTrack", async function (req, res) {
console.log(apiCache.get("getMostRecentSpotifyTrack"));
if (apiCache.get("getMostRecentSpotifyTrack")) {
res.send(JSON.stringify(apiCache.get("getMostRecentSpotifyTrack")));
} else {
console.log("new")
const lastfmResponse = await fetch(
`http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=jdf221&api_key=${process.env.LASTFM_API_KEY}&format=json`
).then((res) => res.json());
@ -49,13 +51,14 @@ app.get("/getMostRecentSpotifyTrack", async function (req, res) {
const track = lastfmResponse?.["recenttracks"]?.["track"]?.[0];
response.track = track?.name;
response.artist = track?.artist?.["#text"];
console.log(response)
apiCache.set("getMostRecentSpotifyTrack", response);
res.send(JSON.stringify(response));
}
});
app.listen(3000);`2`
app.listen(3000);
async function getSpotifyApi() {
return {