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; }