8 Commits

Author SHA1 Message Date
fc0cb210cc fix(deps): update dependency express to v4.19.2 2024-04-17 15:01:27 +00:00
f621f6c5ae attempt to close the old socket
All checks were successful
deploy / deploy (push) Successful in 20s
2024-01-16 15:37:58 +00:00
3621941a0d e
All checks were successful
deploy / deploy (push) Successful in 22s
2024-01-16 15:36:30 +00:00
fe15f660e6 e
All checks were successful
deploy / deploy (push) Successful in 36s
2024-01-16 15:33:50 +00:00
5c2416e7ee e
Some checks failed
deploy / deploy (push) Has been cancelled
2024-01-16 15:33:11 +00:00
46efd6b6dc Merge branch 'master' of https://git.fascinated.cc/Fascinated/beatsaber-metrics-tracker
Some checks failed
deploy / deploy (push) Failing after 23s
2024-01-16 15:31:32 +00:00
7749a570d6 impl a simple dead socket handler 2024-01-16 15:29:59 +00:00
b9dedbc603 switch to pnpm 2023-11-08 06:45:46 +00:00
8 changed files with 1520 additions and 108 deletions

4
.gitignore vendored
View File

@ -144,3 +144,7 @@ dist
# Built Visual Studio Code Extensions # Built Visual Studio Code Extensions
*.vsix *.vsix
# lock files
package-lock.json
yarn.lock

View File

@ -1,9 +1,10 @@
FROM node:alpine FROM fascinated/docker-images:node-pnpm-latest
WORKDIR /usr/src/app WORKDIR /usr/src/app
COPY package*.json ./ COPY package.json pnpm-lock.yaml ./
RUN npm install RUN pnpm install
COPY . . COPY . .
RUN npx tsc -b RUN pnpm run build
ENV PORT=80 ENV PORT=80
EXPOSE 80 EXPOSE 80
CMD [ "npm", "start" ] CMD [ "pnpm", "start" ]

32
package-lock.json generated
View File

@ -319,12 +319,12 @@
} }
}, },
"node_modules/body-parser": { "node_modules/body-parser": {
"version": "1.20.1", "version": "1.20.2",
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.1.tgz", "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.2.tgz",
"integrity": "sha512-jWi7abTbYwajOytWCQc37VulmWiRae5RyTpaCyDcS5/lMdtwSz5lOpDE67srw/HYe35f1z3fDQw+3txg7gNtWw==", "integrity": "sha512-ml9pReCu3M61kGlqoTm2umSXTlRTuGTx0bfYj+uIUKKYycG5NtSbeetV3faSU6R7ajOPw0g/J1PvK4qNy7s5bA==",
"dependencies": { "dependencies": {
"bytes": "3.1.2", "bytes": "3.1.2",
"content-type": "~1.0.4", "content-type": "~1.0.5",
"debug": "2.6.9", "debug": "2.6.9",
"depd": "2.0.0", "depd": "2.0.0",
"destroy": "1.2.0", "destroy": "1.2.0",
@ -332,7 +332,7 @@
"iconv-lite": "0.4.24", "iconv-lite": "0.4.24",
"on-finished": "2.4.1", "on-finished": "2.4.1",
"qs": "6.11.0", "qs": "6.11.0",
"raw-body": "2.5.1", "raw-body": "2.5.2",
"type-is": "~1.6.18", "type-is": "~1.6.18",
"unpipe": "1.0.0" "unpipe": "1.0.0"
}, },
@ -477,9 +477,9 @@
} }
}, },
"node_modules/cookie": { "node_modules/cookie": {
"version": "0.5.0", "version": "0.6.0",
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.5.0.tgz", "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.6.0.tgz",
"integrity": "sha512-YZ3GUyn/o8gfKJlnlX7g7xq4gyO6OSuhGPKaaGssGB2qgDUS0gPgtTvoyZLTt9Ab6dC4hfc9dV5arkvc/OCmrw==", "integrity": "sha512-U71cyTamuh1CRNCfpGY6to28lxvNwPG4Guz/EVjgf3Jmzv0vlDp1atT9eS5dDjMYHucpHbWns6Lwf3BKz6svdw==",
"engines": { "engines": {
"node": ">= 0.6" "node": ">= 0.6"
} }
@ -615,16 +615,16 @@
} }
}, },
"node_modules/express": { "node_modules/express": {
"version": "4.18.2", "version": "4.19.2",
"resolved": "https://registry.npmjs.org/express/-/express-4.18.2.tgz", "resolved": "https://registry.npmjs.org/express/-/express-4.19.2.tgz",
"integrity": "sha512-5/PsL6iGPdfQ/lKM1UuielYgv3BUoJfz1aUwU9vHZ+J7gyvwdQXFEBIEIaxeGf0GIcreATNyBExtalisDbuMqQ==", "integrity": "sha512-5T6nhjsT+EOMzuck8JjBHARTHfMht0POzlA60WV2pMD3gyXw2LZnZ+ueGdNxG+0calOJcWKbpFcuzLZ91YWq9Q==",
"dependencies": { "dependencies": {
"accepts": "~1.3.8", "accepts": "~1.3.8",
"array-flatten": "1.1.1", "array-flatten": "1.1.1",
"body-parser": "1.20.1", "body-parser": "1.20.2",
"content-disposition": "0.5.4", "content-disposition": "0.5.4",
"content-type": "~1.0.4", "content-type": "~1.0.4",
"cookie": "0.5.0", "cookie": "0.6.0",
"cookie-signature": "1.0.6", "cookie-signature": "1.0.6",
"debug": "2.6.9", "debug": "2.6.9",
"depd": "2.0.0", "depd": "2.0.0",
@ -1391,9 +1391,9 @@
} }
}, },
"node_modules/raw-body": { "node_modules/raw-body": {
"version": "2.5.1", "version": "2.5.2",
"resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.1.tgz", "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.2.tgz",
"integrity": "sha512-qqJBtEyVgS0ZmPGdCFPWJ3FreoqvG4MVQln/kCgF7Olq95IbOp0/BWyMwbdtn4VTvkM8Y7khCQ2Xgk/tcrCXig==", "integrity": "sha512-8zGqypfENjCIqGhgXToC8aB2r7YrBX+AQAfIPs/Mlk+BtPTztOvTS01NRW/3Eh60J+a48lt8qsCzirQ6loCVfA==",
"dependencies": { "dependencies": {
"bytes": "3.1.2", "bytes": "3.1.2",
"http-errors": "2.0.0", "http-errors": "2.0.0",

View File

@ -6,6 +6,7 @@
"scripts": { "scripts": {
"start": "node dist/index.js", "start": "node dist/index.js",
"tsc": "tsc -w", "tsc": "tsc -w",
"build": "tsc",
"dev": "nodemon dist/index.js" "dev": "nodemon dist/index.js"
}, },
"author": "", "author": "",

1381
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -11,6 +11,10 @@ let totalUpdated: number | undefined;
let totalCreated: number | undefined; let totalCreated: number | undefined;
let totalDeleted: number | undefined; let totalDeleted: number | undefined;
// Thee last time a map was heard
let lastMap: number = Date.now();
let socket: WebsocketClient | undefined;
async function update() { async function update() {
if (totalCreated == undefined) { if (totalCreated == undefined) {
throw new Error("Total created is undefined"); throw new Error("Total created is undefined");
@ -42,7 +46,7 @@ async function update() {
} }
async function connectWebsocket() { async function connectWebsocket() {
const socket = new WebsocketClient(WEBSOCKET_URL); socket = new WebsocketClient(WEBSOCKET_URL);
await connectMongo(); await connectMongo();
let beatSaver = await BeatSaverSchema.findOne({ _id: "beatsaver" }); let beatSaver = await BeatSaverSchema.findOne({ _id: "beatsaver" });
if (!beatSaver) { if (!beatSaver) {
@ -125,3 +129,11 @@ async function connectWebsocket() {
connectWebsocket(); connectWebsocket();
cron.schedule("*/5 * * * *", update); cron.schedule("*/5 * * * *", update);
cron.schedule("*/1 * * * *", () => {
// 1 minute
if (lastMap && Date.now() - lastMap > 60_000) {
console.log("Beatsaver websocket is dead, reconnecting");
socket?.close();
connectWebsocket();
}
});

View File

@ -10,6 +10,10 @@ import { normalizedRegionName } from "../utils/regionUtils";
let totalScores: number | undefined; let totalScores: number | undefined;
// Thee last time a score was heard
let lastScore: number = Date.now();
let socket: WebsocketClient | undefined;
/** /**
* Updates the player count and adds data to influx * Updates the player count and adds data to influx
*/ */
@ -47,7 +51,7 @@ async function connectWebsocket() {
// set total scores to the current total plays in the database // set total scores to the current total plays in the database
totalScores = leaderboard?.totalPlays || 0; totalScores = leaderboard?.totalPlays || 0;
const socket = new WebsocketClient("wss://scoresaber.com/ws"); socket = new WebsocketClient("wss://scoresaber.com/ws");
socket.onopen = () => { socket.onopen = () => {
console.log("Connected to scoresaber websocket"); console.log("Connected to scoresaber websocket");
}; };
@ -62,6 +66,7 @@ async function connectWebsocket() {
}; };
socket.onmessage = async (message) => { socket.onmessage = async (message) => {
lastScore = Date.now();
const data = message.data; const data = message.data;
let json; let json;
try { try {
@ -152,3 +157,11 @@ async function connectWebsocket() {
update(); update();
connectWebsocket(); connectWebsocket();
cron.schedule("*/1 * * * *", update); cron.schedule("*/1 * * * *", update);
cron.schedule("*/1 * * * *", () => {
// 1 minute
if (lastScore && Date.now() - lastScore > 60_000) {
console.log("Scoresaber websocket is dead, reconnecting");
socket?.close();
connectWebsocket();
}
});