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 91006c8..b317d68 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; @@ -376,22 +384,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; }