-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusb.html
More file actions
80 lines (75 loc) · 2.7 KB
/
usb.html
File metadata and controls
80 lines (75 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>S.O.S.B.I Wizard</title>
</head>
<body>
<h1>Pick an USB device to place the operative sistem</h1>
<select id="usbSelect"></select>
<button id="refreshBtn">Refresh</button>
<button onclick="window.location.href = 'index.html';">Back</button>
<button id="nextBtn">Next</button>
<script>
const usbSelect = document.getElementById('usbSelect');
const nextBtn = document.getElementById('nextBtn');
const refreshBtn = document.getElementById('refreshBtn');
function setOptions(usbs) {
usbSelect.innerHTML = '';
if (!Array.isArray(usbs) || usbs.length === 0) {
const opt = document.createElement('option');
opt.value = '';
opt.textContent = 'No USB detected';
usbSelect.appendChild(opt);
usbSelect.disabled = true;
nextBtn.disabled = true;
return;
}
usbs.forEach(u => {
const opt = document.createElement('option');
opt.value = u;
opt.textContent = u;
usbSelect.appendChild(opt);
});
usbSelect.disabled = false;
nextBtn.disabled = false;
}
async function loadState() {
try {
const resp = await fetch('state.json', { cache: 'no-store' });
if (!resp.ok) throw new Error('HTTP ' + resp.status);
const data = await resp.json();
setOptions(data.usb_devices);
} catch (err) {
setOptions([]);
console.warn('loadState error:', err);
}
}
async function postSelection() {
const selected = usbSelect.value;
if (!selected) return;
try {
await fetch('/api/state', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ selected_usb: selected })
});
} catch (err) {
console.warn('postSelection error:', err);
}
window.location.href = 'os.html';
}
refreshBtn.addEventListener('click', async () => {
try {
await fetch('/api/scan', { method: 'POST' });
} catch (err) {
console.warn('scan error:', err);
}
loadState();
});
nextBtn.addEventListener('click', postSelection);
loadState();
</script>
</body>
</html>