From 9407d7e5aeec3c729775be77c770a34277a1b383 Mon Sep 17 00:00:00 2001 From: Benjamin Kraft Date: Sun, 23 Jun 2024 17:32:41 +0200 Subject: [PATCH 1/2] flexible update limit, set only in .env --- .env.example | 3 ++- public/elotracker/chart-integration.js | 12 +++++++----- public/elotracker/update.php | 12 ++++++++++-- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/.env.example b/.env.example index ed5c22d..8cc27f1 100644 --- a/.env.example +++ b/.env.example @@ -2,4 +2,5 @@ MYSQL_PORT= MYSQL_USER= MYSQL_PASSWORD= MYSQL_DATABASE= -RIOT_API_KEY= \ No newline at end of file +RIOT_API_KEY= +UPDATE_LIMIT_MINUTES= \ No newline at end of file diff --git a/public/elotracker/chart-integration.js b/public/elotracker/chart-integration.js index eed08a6..d9af3d5 100644 --- a/public/elotracker/chart-integration.js +++ b/public/elotracker/chart-integration.js @@ -353,22 +353,24 @@ async function update_leaderboard_entries() { this.style.setProperty("--button-loading-bar-width", `${e.data * 100}%`); }) eventSource.addEventListener("forbidden", e => { + eventSource.close(); + let response = JSON.parse(e.data); const currenttime = new Date(); - const updatetime = new Date(e.data); + const updatetime = new Date(response.last); let timediff = new Date(currenttime - updatetime); - let resttime = new Date(600000 - (currenttime - updatetime)); + let resttime = new Date( 1000 * 60 * response.limit - (currenttime - updatetime)); window.alert(`Das letzte Update wurde vor ${format_time_minsec(timediff)} durchgeführt. Versuche es in ${format_time_minsec(resttime)} noch einmal`); reset_button(this); - eventSource.close(); }) eventSource.onerror = e => { + eventSource.close(); window.alert(`Beim Update ist ein Fehler aufgetreten. Versuche es später noch einmal`) reset_button(this); - eventSource.close(); } eventSource.addEventListener("done", e => { - reset_button(this); eventSource.close(); + reset_button(this); + update_leaderboard_elements(); }) diff --git a/public/elotracker/update.php b/public/elotracker/update.php index f814423..5d6c6a9 100755 --- a/public/elotracker/update.php +++ b/public/elotracker/update.php @@ -1,5 +1,7 @@ query(" SELECT date FROM updates - WHERE date > SUBTIME(NOW(), '00:10:00') + WHERE date > SUBTIME(NOW(), '00:$update_limit:00') LIMIT 1 "); if ($result->num_rows > 0) { - sendEvent("forbidden", $result->fetch_assoc()["date"]); + $response = [ + "limit" => $update_limit, + "last" => $result->fetch_assoc()["date"] + ]; + sendEvent("forbidden", json_encode($response)); die; } From 7dbd89a5f99ee7540ca35bf121627c42e491b690 Mon Sep 17 00:00:00 2001 From: Benjamin Kraft Date: Sun, 23 Jun 2024 18:26:18 +0200 Subject: [PATCH 2/2] tooltip date formatting updated --- public/elotracker/chart-integration.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/public/elotracker/chart-integration.js b/public/elotracker/chart-integration.js index d9af3d5..3f130a4 100644 --- a/public/elotracker/chart-integration.js +++ b/public/elotracker/chart-integration.js @@ -91,7 +91,15 @@ async function create_charts() { return format_rank(player_entries_byName[context.dataset.label][context.parsed.x / 1000]["tier"], player_entries_byName[context.dataset.label][context.parsed.x / 1000]["rank"], player_entries_byName[context.dataset.label][context.parsed.x / 1000]["points"]) }, title: items => { - return new Date(items[0].raw.x).toLocaleDateString(); + let ms = items[0].raw.x; + let options = { + weekday: "short", + day: "numeric", + month: "short", + hour: "2-digit", + minute: "2-digit" + } + return new Date(ms).toLocaleDateString("de-DE", options); }, beforeTitle: function (context) { return context[0].dataset.label;