WebHost: use JS to refresh waitSeed if scripting is enabled (#4843)

This commit is contained in:
Fabian Dill
2025-04-09 07:43:28 +02:00
committed by GitHub
parent 0f7deb1d2a
commit e211dfa1c2

View File

@@ -4,7 +4,9 @@
{% block head %} {% block head %}
<title>Generation in Progress</title> <title>Generation in Progress</title>
<meta http-equiv="refresh" content="1"> <noscript>
<meta http-equiv="refresh" content="1">
</noscript>
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename="styles/waitSeed.css") }}"/> <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename="styles/waitSeed.css") }}"/>
{% endblock %} {% endblock %}
@@ -16,4 +18,34 @@
Waiting for game to generate, this page auto-refreshes to check. Waiting for game to generate, this page auto-refreshes to check.
</div> </div>
</div> </div>
<script>
const waitSeedDiv = document.getElementById("wait-seed");
async function checkStatus() {
try {
const response = await fetch("{{ url_for('api.wait_seed_api', seed=seed_id) }}");
if (response.status !== 202) {
// Seed is ready; reload page to load seed page.
location.reload();
return;
}
const data = await response.json();
waitSeedDiv.innerHTML = `
<h1>Generation in Progress</h1>
<p>${data.text}</p>
`;
setTimeout(checkStatus, 1000); // Continue polling.
} catch (error) {
waitSeedDiv.innerHTML = `
<h1>Progress Unknown</h1>
<p>${error.message}<br />(Last checked: ${new Date().toLocaleTimeString()})</p>
`;
setTimeout(checkStatus, 1000);
}
}
setTimeout(checkStatus, 1000);
</script>
{% endblock %} {% endblock %}