Skip to content

Commit 63137f4

Browse files
committed
index.html: alert + handle errors for restart/reboot/factory-reset
1 parent 1e387f2 commit 63137f4

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

static/index.html

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ <h3 style="text-align: center; margin-bottom: 0.125rem">
6464
<button type="button" id="downloadBtn">
6565
📜 Download log package (.tar.gz)
6666
</button>
67-
<button type="button" onclick="window.location.href='/restart'">
67+
<button type="button" onclick="handleAction('/restart')">
6868
🧬 Apply / restart
6969
</button>
70-
<button type="button" onclick="window.location.href='/reboot'">
70+
<button type="button" onclick="handleAction('/reboot')">
7171
🔁 Reboot device
7272
</button>
7373
<button type="button" data-endpoint="/upload-certs">
@@ -78,7 +78,7 @@ <h3 style="text-align: center; margin-bottom: 0.125rem">
7878
</button>
7979
<button
8080
type="button"
81-
onclick="if (confirm('Are you sure you want to factory reset?')) { window.location.href='/factory-reset'; }"
81+
onclick="handleAction('/factory-reset', 'Are you sure you want to factory reset?')"
8282
>
8383
♻️ Factory reset
8484
</button>
@@ -199,6 +199,25 @@ <h3 style="text-align: center; margin-bottom: 0.125rem">
199199
}
200200
}
201201

202+
async function handleAction(endpoint, confirmMessage = null) {
203+
try {
204+
if (confirmMessage && !confirm(confirmMessage)) {
205+
return; // User canceled
206+
}
207+
208+
const response = await fetch(endpoint, { method: "POST" });
209+
210+
if (!response.ok) {
211+
throw new Error(`Status: ${response.status}`);
212+
}
213+
214+
alert("✅ Request completed successfully!");
215+
} catch (error) {
216+
console.error("Request failed:", error);
217+
alert("❌ Request failed.");
218+
}
219+
}
220+
202221
async function loadConfig() {
203222
const res = await fetch("/config");
204223
const data = await res.json();

0 commit comments

Comments
 (0)