Compare commits

...

10 Commits

Author SHA1 Message Date
37c0e14f7b Add CURL 2025-04-22 20:41:19 -05:00
486bf7cce7 Test 2025-04-21 21:21:05 -05:00
2d2d3404c1 Fix Dockerfile name 2025-04-21 21:01:59 -05:00
a5f5637322 All working now 2025-01-26 17:25:25 -06:00
0f195a0ac7 Test 2025-01-26 17:17:58 -06:00
88cc7073cc Test 2025-01-26 17:15:26 -06:00
20026ecca7 Test 2025-01-26 17:15:10 -06:00
601f71d2fd Test 2025-01-26 17:08:18 -06:00
c97ffb878e Test 2025-01-26 17:06:18 -06:00
7228d92fbc Test 2025-01-26 17:05:19 -06:00
2 changed files with 11 additions and 7 deletions

View File

@ -1,5 +1,6 @@
FROM node:23.6-bullseye-slim
VOLUME /opt/prod/storage
RUN apt-get update && apt-get install curl -y
WORKDIR /opt/prod/app
COPY . .

15
dist/start.js vendored
View File

@ -4,8 +4,6 @@ const cors = require("cors");
const https = require("https");
const fs = require("fs/promises");
fs.writeFile("/opt/prod/stoage/test.txt", "text");
const agent = new https.Agent({
rejectUnauthorized: false,
});
@ -36,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());
@ -51,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 {
@ -239,8 +240,12 @@ async function weeklySpotifyHandler() {
)
) {
createdPlaylists[currentPlaylistInternalId].tracks.push(track.uri);
console.log(`Adding ${lastfmTrack.name}} to ${currentPlaylistInternalId}`)
newTracksToAdd.push(track.uri);
}
else {
console.log(`Skipping ${lastfmTrack.name}}, already added to ${currentPlaylistInternalId}`)
}
break;
}
}
@ -263,6 +268,4 @@ setInterval(() => {
) {
weeklySpotifyHandler();
}
}, 1000 * 60 * 30); // Every 30 minutes
weeklySpotifyHandler();
}, 1000 * 60 * 30); // Every 30 minutes