From 7ab278c1afb2e0833b496a4956097542cb07b1d6 Mon Sep 17 00:00:00 2001 From: adjoly Date: Fri, 24 Oct 2025 15:21:33 +0200 Subject: [PATCH 1/2] =?UTF-8?q?=E3=80=8C=F0=9F=94=A8=E3=80=8D=20fix:=20fix?= =?UTF-8?q?ed=20some=20things.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/user/pMatchHistory.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/api/user/pMatchHistory.js b/src/api/user/pMatchHistory.js index 94dd63b..eb60871 100644 --- a/src/api/user/pMatchHistory.js +++ b/src/api/user/pMatchHistory.js @@ -3,9 +3,13 @@ const score_url = process.env.SCORE_URL || "http://localhost:3003"; async function fetchSave(request, reply, userId, addMatch) { let opponentName = ''; let opponentScore = 0; - if (request.body.opponent && request.body.opponentScore) { + if (request.body.opponent) { opponentName = request.body.opponent; + } + if (request.body.opponentScore !== undefined) { opponentScore = request.body.opponentScore; + } else { + opponentScore = 0; } const res = await fetch(score_url + "/", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ p1: userId, p2: opponentName, p1Score: request.body.myScore, p2Score: opponentScore }) }); if (!res.ok) { @@ -27,7 +31,7 @@ export async function pMatchHistory(request, reply, fastify, getUserInfo, addMat if (request.body.game !== 'pong' && request.body.game !== 'tetris') { return reply.code(400).send({ error: "Specified game does not exist" }); } - if (request.body.game === 'pong' && (!request.body.opponent || !request.body.opponentScore)) { + if (request.body.game === 'pong' && !request.body.opponent) { return reply.code(400).send({ error: "Game requires two players" }); } if (!getUserInfo.get(userId)) { @@ -41,7 +45,7 @@ export async function pMatchHistory(request, reply, fastify, getUserInfo, addMat return reply.code(400).send({ error: "Do you have dementia ? You cannot have played a match against yourself gramps" }); } } - await fetchSave(request, reply, userId, addMatch); + fetchSave(request, reply, userId, addMatch); if (request.body.game === 'pong') { if (request.body.myScore > request.body.opponentScore) { incWinsPong.run(userId); From 540c94a27239076269e06c1ca81cb8a798f25ada Mon Sep 17 00:00:00 2001 From: adjoly Date: Fri, 24 Oct 2025 15:38:55 +0200 Subject: [PATCH 2/2] =?UTF-8?q?=E3=80=8C=F0=9F=94=A8=E3=80=8D=20fix:=20fix?= =?UTF-8?q?ed=20some=20things.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/front/static/ts/main.ts | 2 +- src/front/static/ts/views/LoginPage.ts | 4 ++-- src/front/static/ts/views/Profile.ts | 6 +++--- src/front/static/ts/views/ProfileMenu.ts | 6 +++--- src/front/static/ts/views/RegisterPage.ts | 2 +- src/front/static/ts/views/Settings.ts | 8 ++++---- src/front/static/ts/views/Tetris.ts | 6 +++--- src/front/static/ts/views/TetrisVersus.ts | 6 +++--- src/start.js | 2 +- 9 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/front/static/ts/main.ts b/src/front/static/ts/main.ts index 6299759..5fee606 100644 --- a/src/front/static/ts/main.ts +++ b/src/front/static/ts/main.ts @@ -170,5 +170,5 @@ async function startMenuPP() { } } -setInterval(startMenuPP, 3000); +setInterval(startMenuPP, 5000); startMenuPP(); diff --git a/src/front/static/ts/views/LoginPage.ts b/src/front/static/ts/views/LoginPage.ts index eaf49ca..262ebf7 100644 --- a/src/front/static/ts/views/LoginPage.ts +++ b/src/front/static/ts/views/LoginPage.ts @@ -93,7 +93,7 @@ export default class extends Aview { // throw new Error("invalid response"); } } catch (error) { - console.error(error); + console.log(error); } } @@ -186,7 +186,7 @@ export default class extends Aview { } catch (error) { - console.error(error); + console.log(error); document.getElementById("login-error-message").innerHTML = "error: server error, try again later..."; document.getElementById("login-error-message").classList.remove("hidden"); } diff --git a/src/front/static/ts/views/Profile.ts b/src/front/static/ts/views/Profile.ts index 25258ab..48f6ea8 100644 --- a/src/front/static/ts/views/Profile.ts +++ b/src/front/static/ts/views/Profile.ts @@ -54,7 +54,7 @@ export default class extends Aview { credentials: "include", }); if (userdata_req.status == 404) { - console.error("invalid user"); + console.log("invalid user"); return; } let userdata = await userdata_req.json(); @@ -74,7 +74,7 @@ export default class extends Aview { let main = document.getElementById("profile-pong-scorelist"); if (!main) - return console.error("what"); + return console.log("what"); if (matches.matchHistory) { for (let match of matches.matchHistory) { @@ -136,7 +136,7 @@ export default class extends Aview { main = document.getElementById("profile-tetris-scorelist"); if (!main) - return console.error("what"); + return console.log("what"); // don't read this shit for you mental health if (matches.matchHistory) { diff --git a/src/front/static/ts/views/ProfileMenu.ts b/src/front/static/ts/views/ProfileMenu.ts index 9a480e0..44ae8c8 100644 --- a/src/front/static/ts/views/ProfileMenu.ts +++ b/src/front/static/ts/views/ProfileMenu.ts @@ -54,7 +54,7 @@ export default class extends Aview { }); if (userdata_req.status == 404) { - console.error("invalid user"); + console.log("invalid user"); return ; } let userdata = await userdata_req.json(); @@ -69,7 +69,7 @@ export default class extends Aview { document.getElementById("profile-items").innerHTML = await getMainHTML(); requestAnimationFrame(() => { - document.getElementById("menu-logout").addEventListener("click", async () => { + document.getElementById("menu-logout")?.addEventListener("click", async () => { let req = fetch(`${auth_api}/logout`, { method: "GET", credentials: "include", @@ -79,7 +79,7 @@ export default class extends Aview { if (res.status === 200) this.run(); else - console.error("logout failed"); + console.log("logout failed"); }); }); }); diff --git a/src/front/static/ts/views/RegisterPage.ts b/src/front/static/ts/views/RegisterPage.ts index ce19458..b002d29 100644 --- a/src/front/static/ts/views/RegisterPage.ts +++ b/src/front/static/ts/views/RegisterPage.ts @@ -91,7 +91,7 @@ export default class extends Aview { } catch (error) { - console.error(error); + console.log(error); if (document.getElementById("login-error-message")) { document.getElementById("login-error-message").innerHTML = "error: server error, try again later..."; document.getElementById("login-error-message")?.classList.remove("hidden"); diff --git a/src/front/static/ts/views/Settings.ts b/src/front/static/ts/views/Settings.ts index 3f115f6..6abdf41 100644 --- a/src/front/static/ts/views/Settings.ts +++ b/src/front/static/ts/views/Settings.ts @@ -74,7 +74,7 @@ export default class extends Aview { credentials: "include", }); if (userdata_req.status == 404) { - console.error("invalid user"); + console.log("invalid user"); return; } let userdata = await userdata_req.json(); @@ -106,16 +106,16 @@ export default class extends Aview { if (delete_req.status == 200) navigationManager("/"); else - console.error("xd"); // xd????????????? + console.log("xd"); // xd????????????? }); const upload = document.getElementById("upload-file") as HTMLInputElement; upload.addEventListener("change", () => { const fileList: FileList | null = upload.files; if (!fileList) - return console.error("empty"); + return console.log("empty"); if (!fileList[0].type.startsWith("image/")) { - console.error("invalid file"); + console.log("invalid file"); return; } diff --git a/src/front/static/ts/views/Tetris.ts b/src/front/static/ts/views/Tetris.ts index 496bbce..360961a 100644 --- a/src/front/static/ts/views/Tetris.ts +++ b/src/front/static/ts/views/Tetris.ts @@ -307,18 +307,18 @@ export default class extends Aview { ) as HTMLCanvasElement | null; this.canvas = el; if (!this.canvas) - throw console.error("no canvas :c"); + throw console.log("no canvas :c"); this.canvas.width = COLS * BLOCK; this.canvas.height = ROWS * BLOCK; const ctx = this.canvas.getContext("2d"); this.ctx = ctx; if (!this.ctx) - throw console.error("no ctx D:"); + throw console.log("no ctx D:"); this.holdCanvas = document.getElementById("hold") as HTMLCanvasElement; this.queueCanvas = document.getElementById("queue") as HTMLCanvasElement; if (!this.holdCanvas || !this.queueCanvas) - throw console.error("no canvas :c"); + throw console.log("no canvas :c"); this.holdCtx = this.holdCanvas.getContext("2d"); this.queueCtx = this.queueCanvas.getContext("2d"); if (!this.holdCtx || !this.queueCtx) diff --git a/src/front/static/ts/views/TetrisVersus.ts b/src/front/static/ts/views/TetrisVersus.ts index fbe83d0..38c1584 100644 --- a/src/front/static/ts/views/TetrisVersus.ts +++ b/src/front/static/ts/views/TetrisVersus.ts @@ -332,18 +332,18 @@ export default class extends Aview { ) as HTMLCanvasElement | null; this.canvas = el; if (!this.canvas) - throw console.error("no canvas :c"); + throw console.log("no canvas :c"); this.canvas.width = COLS * BLOCK; this.canvas.height = ROWS * BLOCK; const ctx = this.canvas.getContext("2d"); this.ctx = ctx; if (!this.ctx) - throw console.error("no ctx D:"); + throw console.log("no ctx D:"); this.holdCanvas = document.getElementById(canvasId + "-hold") as HTMLCanvasElement; this.queueCanvas = document.getElementById(canvasId + "-queue") as HTMLCanvasElement; if (!this.holdCanvas || !this.queueCanvas) - throw console.error("no canvas :c"); + throw console.log("no canvas :c"); this.holdCtx = this.holdCanvas.getContext("2d"); this.queueCtx = this.queueCanvas.getContext("2d"); if (!this.holdCtx || !this.queueCtx) diff --git a/src/start.js b/src/start.js index df7bc0e..ad4cc0b 100644 --- a/src/start.js +++ b/src/start.js @@ -77,6 +77,6 @@ async function start() { } start().catch((err) => { - console.error(err); + console.log(err); process.exit(1); });