Compare commits
10 Commits
b91197f70d
...
37c0e14f7b
| Author | SHA1 | Date | |
|---|---|---|---|
| 37c0e14f7b | |||
| 486bf7cce7 | |||
| 2d2d3404c1 | |||
| a5f5637322 | |||
| 0f195a0ac7 | |||
| 88cc7073cc | |||
| 20026ecca7 | |||
| 601f71d2fd | |||
| c97ffb878e | |||
| 7228d92fbc |
@ -1,5 +1,6 @@
|
|||||||
FROM node:23.6-bullseye-slim
|
FROM node:23.6-bullseye-slim
|
||||||
VOLUME /opt/prod/storage
|
|
||||||
|
RUN apt-get update && apt-get install curl -y
|
||||||
|
|
||||||
WORKDIR /opt/prod/app
|
WORKDIR /opt/prod/app
|
||||||
COPY . .
|
COPY . .
|
||||||
13
dist/start.js
vendored
13
dist/start.js
vendored
@ -4,8 +4,6 @@ const cors = require("cors");
|
|||||||
const https = require("https");
|
const https = require("https");
|
||||||
const fs = require("fs/promises");
|
const fs = require("fs/promises");
|
||||||
|
|
||||||
fs.writeFile("/opt/prod/stoage/test.txt", "text");
|
|
||||||
|
|
||||||
const agent = new https.Agent({
|
const agent = new https.Agent({
|
||||||
rejectUnauthorized: false,
|
rejectUnauthorized: false,
|
||||||
});
|
});
|
||||||
@ -36,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());
|
||||||
@ -51,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 {
|
||||||
@ -239,8 +240,12 @@ async function weeklySpotifyHandler() {
|
|||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
createdPlaylists[currentPlaylistInternalId].tracks.push(track.uri);
|
createdPlaylists[currentPlaylistInternalId].tracks.push(track.uri);
|
||||||
|
console.log(`Adding ${lastfmTrack.name}} to ${currentPlaylistInternalId}`)
|
||||||
newTracksToAdd.push(track.uri);
|
newTracksToAdd.push(track.uri);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
console.log(`Skipping ${lastfmTrack.name}}, already added to ${currentPlaylistInternalId}`)
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -264,5 +269,3 @@ setInterval(() => {
|
|||||||
weeklySpotifyHandler();
|
weeklySpotifyHandler();
|
||||||
}
|
}
|
||||||
}, 1000 * 60 * 30); // Every 30 minutes
|
}, 1000 * 60 * 30); // Every 30 minutes
|
||||||
|
|
||||||
weeklySpotifyHandler();
|
|
||||||
Loading…
x
Reference in New Issue
Block a user