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