new game stuff, analytics

This commit is contained in:
sky
2026-02-07 14:45:30 -05:00
parent 49e542b3e9
commit 71f377ac18
20 changed files with 144 additions and 562 deletions

View File

@ -8,9 +8,10 @@ import path, { dirname } from "node:path";
import mime from "mime-types";
import compression from "compression";
// import { accs, infdb, polytrack } from "./database.js";
import { accs } from "./database.js";
import { accs, top } from "./database.js";
import { } from "./accounts/friend.js";
import { findClientID, search, download } from "./accounts/music.js";
import { minoProxy } from "./games/osu.js";
import { banUser, removeAccount, verifyCookie, getUserFromCookie, createAccount, resetPassword, loginAccount, addBadge } from "./accounts/manage.js";
import { } from "./accounts/misc.js";
import { getRawData, generateAccountPage, editProfile, saveData, getUsers, isAdmin, retrieveData } from "./accounts/profile.js";
@ -21,18 +22,6 @@ import chokidar from 'chokidar';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
let recatters = JSON.parse(await fs.readFile("./data/recats.json"));
const watcher = chokidar.watch('./data/recats.json', {
persistent: true,
awaitWriteFinish: {
stabilityThreshold: 500,
pollInterval: 100
}
});
watcher.on('change', async (event, filePath) => {
recatters = JSON.parse(await fs.readFile("./data/recats.json"));
});
await findClientID();
setInterval(async () => {
await findClientID();
@ -42,14 +31,6 @@ const port = process.env.PORT || 3000;
const app = express();
let recatFolder = express.static("./edu", { extensions: ["html"] });
app.use((req, res, next) => {
if(recatters.includes(req.hostname)) {
return recatFolder(req, res, next);
}
next();
});
// why the fuck does this have to exist?
app.use("/resources/semag/hotline-miami/", (req,res,next) => {
if(req.method == "HEAD") {
@ -57,6 +38,9 @@ app.use("/resources/semag/hotline-miami/", (req,res,next) => {
}
next();
});
app.use("/osu/", await minoProxy)
app.use("/resources/semag/portal/", (req,res,next) => {
res.setHeader('Cross-Origin-Embedder-Policy', 'require-corp');
res.setHeader('Cross-Origin-Opener-Policy', 'same-origin');
@ -193,6 +177,22 @@ app.post("/api/account/upload", async (req, res, next) => {
}
});
app.post("/api/analytics/game", async (req, res) => {
if(req.body && req.body.path.length < 16) {
const query = top.prepare(`
INSERT INTO stats (game, plays)
VALUES ($id, 1)
ON CONFLICT(game) DO UPDATE SET plays = plays + 1
RETURNING *
`);
query.get({ $id: req.body.path });
res.send(200);
return;
}
res.send(400);
return;
})
app.post("/api/ai/sendMessage", async (req, res) => {
// take in chat id and message
// stream back reply
@ -284,7 +284,7 @@ app.use("/api/account/load", async (req, res, next) => {
});
app.use("/api/getUsers", async (req, res, next) => {
console.log(req.query)
// console.log(req.query)
let status = await getUsers(req.query.page, req.query.query);
res.status(200).send(status);
});