Switch to main #1
13
.Dockerfile
13
.Dockerfile
@ -1,18 +1,7 @@
|
||||
FROM node:23.6-alpine
|
||||
FROM node:23.6-bullseye-slim
|
||||
WORKDIR /opt/prod/app
|
||||
COPY . .
|
||||
|
||||
RUN apk add --update --no-cache \
|
||||
make \
|
||||
g++ \
|
||||
jpeg-dev \
|
||||
cairo-dev \
|
||||
giflib-dev \
|
||||
pango-dev \
|
||||
libtool \
|
||||
autoconf \
|
||||
automake
|
||||
|
||||
RUN npm install
|
||||
EXPOSE 3000
|
||||
CMD [ "node", "dist/start.js" ]
|
||||
88
dist/start.js
vendored
88
dist/start.js
vendored
@ -56,85 +56,7 @@ app.get("/getMostRecentSpotifyTrack", async function (req, res) {
|
||||
}
|
||||
});
|
||||
|
||||
const CanvasApi = require("canvas");
|
||||
CanvasApi.registerFont("./consumer/ComicSans.ttf", { family: "Comic Sans MS" });
|
||||
const backgroundImage = CanvasApi.loadImage("./consumer/background.png");
|
||||
const arrowImage = CanvasApi.loadImage("./consumer/arrow.png");
|
||||
app.get("/consoomer/getLineGraphImage", async (request, response) => {
|
||||
const config = {
|
||||
maxPoints: 60,
|
||||
lowestX: -80,
|
||||
highestX: 1630,
|
||||
};
|
||||
|
||||
const params = {
|
||||
userId: request.query.userId ?? "-1",
|
||||
nickname: request.query.nickname ?? "Idiot",
|
||||
profileImageUrl:
|
||||
request.query.profileImageUrl ?? "https://i.imgur.com/E7JL7yp.png",
|
||||
points: parseInt(request.query.points) ?? 0,
|
||||
};
|
||||
if (!Object.values(params).every((v) => typeof v !== "undefined")) {
|
||||
response.send("Bad params");
|
||||
return;
|
||||
}
|
||||
if (Number.isNaN(params.points)) {
|
||||
response.send("Bad points");
|
||||
return;
|
||||
} else {
|
||||
params.points = Math.min(Math.abs(params.points), config.maxPoints);
|
||||
}
|
||||
|
||||
const step = Math.floor(
|
||||
(Math.abs(config.lowestX) + config.highestX) / config.maxPoints
|
||||
);
|
||||
const xPosition = Math.floor(step * params.points) + config.lowestX;
|
||||
|
||||
//min x = -80
|
||||
//max x = 1630
|
||||
//y = 135
|
||||
|
||||
const canvas = CanvasApi.createCanvas(1920, 737);
|
||||
const context = canvas.getContext("2d");
|
||||
|
||||
try {
|
||||
context.drawImage(await backgroundImage, 0, 0);
|
||||
|
||||
let profileImage = apiCache.get(
|
||||
"consoomer.profilePic." + params.profileImageUrl
|
||||
);
|
||||
if (!profileImage) {
|
||||
profileImage = await CanvasApi.loadImage(
|
||||
await fetch(params.profileImageUrl).then(async (r) =>
|
||||
Buffer.from(await r.arrayBuffer())
|
||||
)
|
||||
);
|
||||
apiCache.set(
|
||||
"consoomer.profilePic." + params.profileImageUrl,
|
||||
profileImage,
|
||||
300000
|
||||
); // 5 minutes
|
||||
}
|
||||
context.drawImage(profileImage, xPosition + 115, 432);
|
||||
|
||||
context.drawImage(await arrowImage, xPosition, 135);
|
||||
|
||||
context.font = "48px 'Comic Sans MS'";
|
||||
context.fillText("Consoomer Report", 700, 75);
|
||||
context.font = "34px 'Comic Sans MS'";
|
||||
context.fillText(`Results for: ${params.nickname}`, 700, 115);
|
||||
context.fillText(`Total: ${params.points}`, 698, 150);
|
||||
|
||||
response.header("Content-Type", "image/png");
|
||||
response.send(canvas.toBuffer("image/png"));
|
||||
} catch (error) {
|
||||
//throw error
|
||||
response.send("Uknown error");
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
app.listen(3000);
|
||||
app.listen(3000);`2`
|
||||
|
||||
async function getSpotifyApi() {
|
||||
return {
|
||||
@ -288,7 +210,7 @@ async function weeklySpotifyHandler() {
|
||||
createdPlaylists[currentPlaylistInternalId].spotifyPlaylistId;
|
||||
|
||||
const topTracks = await fetch(
|
||||
"https://ws.audioscrobbler.com/2.0/?method=user.getTopTracks&user=jdf221&period=7day&api_key=5d7730f5457bb3e794f69d7713b884ad&format=json"
|
||||
`https://ws.audioscrobbler.com/2.0/?method=user.getTopTracks&user=jdf221&period=7day&api_key=${process.env.LASTFM_API_KEY}&format=json`
|
||||
).then((b) => b.json());
|
||||
const filteredTopTracks = topTracks.toptracks.track.filter(
|
||||
(t) => parseInt(t.playcount) > 2
|
||||
@ -331,13 +253,15 @@ async function weeklySpotifyHandler() {
|
||||
);
|
||||
}
|
||||
|
||||
setInterval(() => {
|
||||
setIntervJDJDJDJDDJDJal(() => {
|
||||
const currentDate = new Date();
|
||||
if (
|
||||
currentDate.getDay() === 0 &&
|
||||
currentDate.getUTCHours() === 0 &&
|
||||
currentDate.getUTCMinutes() < 29
|
||||
) {
|
||||
//weeklySpotifyHandler();
|
||||
weeklySpotifyHandler();
|
||||
}
|
||||
}, 1000 * 60 * 30); // Every 30 minutes
|
||||
|
||||
weeklySpotifyHandler();
|
||||
@ -4,7 +4,6 @@
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"body-parser": "^1.19.0",
|
||||
"canvas": "^2.11.2",
|
||||
"cors": "^2.8.5",
|
||||
"express": "^4.17.1",
|
||||
"form-data": "^4.0.0"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user