From c792254f9c477d683b66a88d9fae934ed84fbd83 Mon Sep 17 00:00:00 2001 From: Tzvetan Trave Date: Sat, 25 Oct 2025 09:42:26 +0200 Subject: [PATCH 01/10] fixed avatars bloating DB when successive POST occured --- src/api/user/default.js | 2 +- src/api/user/pAvatar.js | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/api/user/default.js b/src/api/user/default.js index 88c7a4e..cedcf01 100644 --- a/src/api/user/default.js +++ b/src/api/user/default.js @@ -229,7 +229,7 @@ export default async function(fastify, options) { return pMatchHistory(request, reply, fastify, getUserInfo, addMatch, incWinsPong, incLossesPong, incWinsTetris, incLossesTetris); }); fastify.post('/users/:userId/avatar', { bodyLimit: 5242880, preHandler: [fastify.authenticate] }, async (request, reply) => { - return pAvatar(request, reply, fastify, getUserInfo, setAvatarId, postImage); + return pAvatar(request, reply, fastify, getUserInfo, getAvatarId, setAvatarId, deleteAvatarId, postImage, deleteImage); }); fastify.post('/ping', { preHandler: [fastify.authenticate] }, async (request, reply) => { return pPing(request, reply, fastify, setActivityTime); diff --git a/src/api/user/pAvatar.js b/src/api/user/pAvatar.js index f90299e..7515052 100644 --- a/src/api/user/pAvatar.js +++ b/src/api/user/pAvatar.js @@ -5,7 +5,7 @@ import sharp from 'sharp'; * @param {import('fastify').FastifyReply} reply * @param {import('fastify').FastifyInstance} fastify */ -export async function pAvatar(request, reply, fastify, getUserInfo, setAvatarId, postImage) { +export async function pAvatar(request, reply, fastify, getUserInfo, getAvatarId, setAvatarId, deleteAvatarId, postImage, deleteImage) { try { const userId = request.params.userId; if (request.user !== userId && request.user !== 'admin') { @@ -35,6 +35,12 @@ export async function pAvatar(request, reply, fastify, getUserInfo, setAvatarId, const fileName = `avatar_${userId}.webp`; const imageId = postImage.run(fileName, mimeType, webpBuffer); + const oldImageId = getAvatarId.get(userId); + if (oldImageId.avatarId !== -1) { + deleteImage.run(oldImageId.avatarId); + deleteAvatarId.run(userId); + } + setAvatarId.run(imageId.lastInsertRowid, userId); return reply.code(200).send({ msg: "Avatar uploaded successfully" }); From a073b61d6548ad7f5a1c890a81dfc5b908558a92 Mon Sep 17 00:00:00 2001 From: y-syo Date: Sat, 25 Oct 2025 10:30:11 +0200 Subject: [PATCH 02/10] =?UTF-8?q?=E3=80=8C=F0=9F=94=A8=E3=80=8D=20fix(fron?= =?UTF-8?q?t/Tetris*):=20fixed=20some=20issues=20with=20locking?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/front/static/ts/views/Tetris.ts | 57 ++++------------------- src/front/static/ts/views/TetrisVersus.ts | 13 ++++-- 2 files changed, 16 insertions(+), 54 deletions(-) diff --git a/src/front/static/ts/views/Tetris.ts b/src/front/static/ts/views/Tetris.ts index 360961a..29c347a 100644 --- a/src/front/static/ts/views/Tetris.ts +++ b/src/front/static/ts/views/Tetris.ts @@ -358,6 +358,7 @@ export default class extends Aview { hold() { if (!this.canHold) return; + this.isLocking = false; [this.piece, this.holdPiece] = [this.holdPiece, this.piece]; if (!this.piece) this.spawnPiece(); if (!this.piece) return; @@ -410,6 +411,8 @@ export default class extends Aview { lockPiece() { if (!this.piece) return; + this.canHold = false; + this.isLocking = false; let isValid: boolean = false; for (const cell of this.piece.getCells()) { @@ -442,7 +445,7 @@ export default class extends Aview { const newLevel = Math.floor(this.lines / 10) + 1; if (newLevel > this.level) { this.level = newLevel; - this.dropInterval = Math.max(100, 1000 - (this.level - 1) * 75); + this.dropInterval = Math.max(100, 1000 - (this.level - 1) * 250); } } } @@ -512,50 +515,6 @@ export default class extends Aview { } } - removeListeners() { - window.removeEventListener("keydown", (e) => { - this.keys[e.key] = true; - - if (this.isGameOver) return; - - if (e.key === "p" || e.key === "P" || e.key === "Escape") - this.isPaused = !this.isPaused; - - if (this.isPaused) return; - - if (e.key === "ArrowLeft") - { - this.inputTimestamp = Date.now(); - this.direction = -1;//this.movePiece(-1, 0); - this.move = true; - } - else if (e.key === "ArrowRight") - { - this.inputTimestamp = Date.now(); - this.direction = 1;//this.movePiece(1, 0); - this.move = true; - } - else if (e.key === "ArrowDown") this.softDrop(); - else if (e.code === "Space") { - e.preventDefault(); - this.hardDrop(); - } else if (e.key === "Shift" || e.key === "c" || e.key === "C") { - e.preventDefault(); - this.hold(); - } else if (e.key === "x" || e.key === "X" || e.key === "ArrowUp") { - e.preventDefault(); - this.rotatePiece("cw"); - } else if (e.key === "z" || e.key === "Z" || e.key === "Control") { - e.preventDefault(); - this.rotatePiece("ccw"); - } - }); - - document.removeEventListener("keyup", (e) => { - this.keys[e.key] = false; - }); - } - registerListeners() { window.addEventListener("keydown", (e) => { this.keys[e.key] = true; @@ -606,9 +565,6 @@ export default class extends Aview { this.inputManager(); if (this.isLocking ? timestamp - this.lastDrop > 500 : timestamp - this.lastDrop > this.dropInterval) { - if (this.isLocking && this.lockRotationCount == this.lockLastRotationCount) - this.lockPiece(); - this.lockLastRotationCount = this.lockRotationCount; if (!this.movePiece(0, 1)) { if (!this.isLocking) @@ -619,8 +575,11 @@ export default class extends Aview { } } else if (this.isLocking) - this.lockRotationCount = 0; + this.isLocking = false; this.lastDrop = timestamp; + if (this.isLocking && this.lockRotationCount == this.lockLastRotationCount) + this.lockPiece(); + this.lockLastRotationCount = this.lockRotationCount; } } this.draw(); diff --git a/src/front/static/ts/views/TetrisVersus.ts b/src/front/static/ts/views/TetrisVersus.ts index 38c1584..b1eb176 100644 --- a/src/front/static/ts/views/TetrisVersus.ts +++ b/src/front/static/ts/views/TetrisVersus.ts @@ -388,6 +388,7 @@ export default class extends Aview { hold() { if (!this.canHold) return; + this.isLocking = false; [this.piece, this.holdPiece] = [this.holdPiece, this.piece]; if (!this.piece) this.spawnPiece(); if (!this.piece) return; @@ -441,6 +442,8 @@ export default class extends Aview { lockPiece() { if (!this.piece) return; + this.canHold = false; + this.isLocking = false; let isValid: boolean = false; for (const cell of this.piece.getCells()) { @@ -494,7 +497,7 @@ export default class extends Aview { const newLevel = Math.floor(this.lines / 10) + 1; if (newLevel > this.level) { this.level = newLevel; - this.dropInterval = Math.max(100, 1000 - (this.level - 1) * 75); + this.dropInterval = Math.max(100, 1000 - (this.level - 1) * 250); } if (this.garbage) @@ -636,9 +639,6 @@ export default class extends Aview { this.inputManager(); if (this.isLocking ? timestamp - this.lastDrop > 500 : timestamp - this.lastDrop > this.dropInterval) { - if (this.isLocking && this.lockRotationCount == this.lockLastRotationCount) - this.lockPiece(); - this.lockLastRotationCount = this.lockRotationCount; if (!this.movePiece(0, 1)) { if (!this.isLocking) @@ -649,8 +649,11 @@ export default class extends Aview { } } else if (this.isLocking) - this.lockRotationCount = 0; + this.isLocking = false; this.lastDrop = timestamp; + if (this.isLocking && this.lockRotationCount == this.lockLastRotationCount) + this.lockPiece(); + this.lockLastRotationCount = this.lockRotationCount; } } this.draw(); From e9371b70f4c46956683c6cc530dd81a8c392dad9 Mon Sep 17 00:00:00 2001 From: adjoly Date: Fri, 24 Oct 2025 17:35:53 +0200 Subject: [PATCH 03/10] =?UTF-8?q?=E3=80=8C=F0=9F=94=A8=E3=80=8D=20fix:=20f?= =?UTF-8?q?ixed=20alert?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../monitoring/prometheus/config/prometheus.yml | 3 +++ docker/proxy/config/default.conf.template | 3 --- docker/proxy/config/default.prod.conf.template | 15 --------------- 3 files changed, 3 insertions(+), 18 deletions(-) diff --git a/docker/monitoring/prometheus/config/prometheus.yml b/docker/monitoring/prometheus/config/prometheus.yml index 59f9fc5..954ff39 100644 --- a/docker/monitoring/prometheus/config/prometheus.yml +++ b/docker/monitoring/prometheus/config/prometheus.yml @@ -23,3 +23,6 @@ scrape_configs: - job_name: 'node-exporter' static_configs: - targets: ['node-exporter:9100'] + +rule_files: + - /etc/prometheus/rules.yml diff --git a/docker/proxy/config/default.conf.template b/docker/proxy/config/default.conf.template index c8dc39b..e0985cd 100644 --- a/docker/proxy/config/default.conf.template +++ b/docker/proxy/config/default.conf.template @@ -38,9 +38,6 @@ server { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } - location /api/v1/user/metrics { - return 403; - } location /api/v1/auth/ { modsecurity off; diff --git a/docker/proxy/config/default.prod.conf.template b/docker/proxy/config/default.prod.conf.template index 045ed52..aa69a24 100644 --- a/docker/proxy/config/default.prod.conf.template +++ b/docker/proxy/config/default.prod.conf.template @@ -32,10 +32,6 @@ server { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } - location /api/v1/user/metrics { - return 403; - } - location /api/v1/auth/ { modsecurity off; proxy_pass http://transcendence-api-auth:3000/; @@ -44,17 +40,6 @@ server { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } - location /api/v1/auth/metrics { - return 403; - } - location /api/v1/auth/login/google/callback { - modsecurity off; - proxy_pass http://transcendence-api-auth:3000/login/google/callback; - } - location /api/v1/auth/register/google/callback { - modsecurity off; - proxy_pass http://transcendence-api-auth:3000/register/google/callback; - } } server { From 6a2fd4b98106b7ff477a82790a8e3b5b23abcf9c Mon Sep 17 00:00:00 2001 From: adjoly Date: Fri, 24 Oct 2025 17:50:18 +0200 Subject: [PATCH 04/10] =?UTF-8?q?=E3=80=8C=F0=9F=94=A8=E3=80=8D=20fix:=20f?= =?UTF-8?q?ixed=20check=20alert?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker/monitoring/alert-manager/alertmanager.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/monitoring/alert-manager/alertmanager.yml b/docker/monitoring/alert-manager/alertmanager.yml index 060f20a..4ffacd0 100644 --- a/docker/monitoring/alert-manager/alertmanager.yml +++ b/docker/monitoring/alert-manager/alertmanager.yml @@ -8,7 +8,7 @@ route: receiver: 'email-alerts' group_by: ['alertname'] group_wait: 30s - group_interval: 5m + group_interval: 1m repeat_interval: 1h receivers: From 944947e9ca391948e07c94ffa43ef2d73bc18b9d Mon Sep 17 00:00:00 2001 From: adjoly Date: Fri, 24 Oct 2025 17:57:18 +0200 Subject: [PATCH 05/10] =?UTF-8?q?=E3=80=8C=F0=9F=94=A8=E3=80=8D=20fix:=20f?= =?UTF-8?q?ixed=20some=20things.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker/monitoring/alert-manager/alertmanager.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/docker/monitoring/alert-manager/alertmanager.yml b/docker/monitoring/alert-manager/alertmanager.yml index 4ffacd0..f4fb2f3 100644 --- a/docker/monitoring/alert-manager/alertmanager.yml +++ b/docker/monitoring/alert-manager/alertmanager.yml @@ -3,6 +3,7 @@ global: smtp_from: smtp_auth_username: smtp_auth_password: + smtp_require_tls: true route: receiver: 'email-alerts' From 818f04e4540a69021df4284c71b7b05996a10c86 Mon Sep 17 00:00:00 2001 From: adjoly Date: Fri, 24 Oct 2025 18:04:07 +0200 Subject: [PATCH 06/10] =?UTF-8?q?=E3=80=8C=F0=9F=94=A8=E3=80=8D=20fix:=20f?= =?UTF-8?q?ixed=20some=20things.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker/monitoring/alert-manager/alertmanager.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/docker/monitoring/alert-manager/alertmanager.yml b/docker/monitoring/alert-manager/alertmanager.yml index f4fb2f3..b0bf94a 100644 --- a/docker/monitoring/alert-manager/alertmanager.yml +++ b/docker/monitoring/alert-manager/alertmanager.yml @@ -4,6 +4,7 @@ global: smtp_auth_username: smtp_auth_password: smtp_require_tls: true + smtp_starttls: true route: receiver: 'email-alerts' From c4bdc949ff8f81aeb93115c555ec78682e0662d9 Mon Sep 17 00:00:00 2001 From: adjoly Date: Fri, 24 Oct 2025 18:38:13 +0200 Subject: [PATCH 07/10] =?UTF-8?q?=E3=80=8C=F0=9F=94=A8=E3=80=8D=20fix:=20f?= =?UTF-8?q?ixed=20some=20things.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker/monitoring/alert-manager/alertmanager.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/docker/monitoring/alert-manager/alertmanager.yml b/docker/monitoring/alert-manager/alertmanager.yml index b0bf94a..4ffacd0 100644 --- a/docker/monitoring/alert-manager/alertmanager.yml +++ b/docker/monitoring/alert-manager/alertmanager.yml @@ -3,8 +3,6 @@ global: smtp_from: smtp_auth_username: smtp_auth_password: - smtp_require_tls: true - smtp_starttls: true route: receiver: 'email-alerts' From a7325e4ef0d5e9ace453cebc82489edac787a50a Mon Sep 17 00:00:00 2001 From: adjoly Date: Fri, 24 Oct 2025 18:40:53 +0200 Subject: [PATCH 08/10] =?UTF-8?q?=E3=80=8C=F0=9F=94=A8=E3=80=8D=20fix:=20f?= =?UTF-8?q?ixed=20some=20things.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/contract/scoreStore.json | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/contract/scoreStore.json diff --git a/src/contract/scoreStore.json b/src/contract/scoreStore.json new file mode 100644 index 0000000..b373bbd --- /dev/null +++ b/src/contract/scoreStore.json @@ -0,0 +1 @@ +[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"string","name":"p1","type":"string"},{"internalType":"string","name":"p2","type":"string"},{"internalType":"uint128","name":"p1Score","type":"uint128"},{"internalType":"uint128","name":"p2Score","type":"uint128"}],"name":"addScore","outputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"getScore","outputs":[{"components":[{"internalType":"string","name":"p1","type":"string"},{"internalType":"string","name":"p2","type":"string"},{"internalType":"uint128","name":"p1Score","type":"uint128"},{"internalType":"uint128","name":"p2Score","type":"uint128"}],"internalType":"struct score","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"scores","outputs":[{"internalType":"string","name":"p1","type":"string"},{"internalType":"string","name":"p2","type":"string"},{"internalType":"uint128","name":"p1Score","type":"uint128"},{"internalType":"uint128","name":"p2Score","type":"uint128"}],"stateMutability":"view","type":"function"}] \ No newline at end of file From 7aec961ffba8157b160ca1f808cb9b9ef32eb3f3 Mon Sep 17 00:00:00 2001 From: adjoly Date: Sat, 25 Oct 2025 10:51:25 +0200 Subject: [PATCH 09/10] =?UTF-8?q?=E3=80=8C=F0=9F=94=A8=E3=80=8D=20fix:=20f?= =?UTF-8?q?ixed=20front=20on=20setting=20to=20look=20cooler?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/front/static/ts/views/Settings.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/front/static/ts/views/Settings.ts b/src/front/static/ts/views/Settings.ts index 6abdf41..a9889c0 100644 --- a/src/front/static/ts/views/Settings.ts +++ b/src/front/static/ts/views/Settings.ts @@ -29,18 +29,20 @@ export default class extends Aview { -
-
`; From 666e993c4892f4d07280c1d783c13f890a47eb69 Mon Sep 17 00:00:00 2001 From: y-syo Date: Sat, 25 Oct 2025 11:10:17 +0200 Subject: [PATCH 10/10] =?UTF-8?q?=E3=80=8C=F0=9F=94=A8=E3=80=8D=20fix:=20f?= =?UTF-8?q?ixed=20some=20things.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/front/index.html | 2 +- src/front/static/css/style.css | 12 ++++++++++++ src/front/static/ts/views/Settings.ts | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/front/index.html b/src/front/index.html index dbd12eb..96203cc 100644 --- a/src/front/index.html +++ b/src/front/index.html @@ -39,7 +39,7 @@
`;