101 lines
4.2 KiB
HTML
101 lines
4.2 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>PaperColor Setup</title>
|
|
<style>
|
|
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
body { font-family: -apple-system, sans-serif; max-width: 400px; margin: 40px auto; padding: 20px; background: #f5f5f5; }
|
|
h1 { margin-bottom: 20px; color: #333; }
|
|
.field { margin-bottom: 16px; }
|
|
label { display: block; font-weight: 600; margin-bottom: 4px; color: #555; }
|
|
input, select { width: 100%; padding: 10px; border: 1px solid #ddd; border-radius: 6px; font-size: 16px; }
|
|
button { width: 100%; padding: 12px; background: #2563eb; color: white; border: none; border-radius: 6px; font-size: 16px; cursor: pointer; margin-top: 10px; }
|
|
button:hover { background: #1d4ed8; }
|
|
.status { margin-top: 16px; padding: 10px; border-radius: 6px; display: none; }
|
|
.status.error { display: block; background: #fee2e2; color: #991b1b; }
|
|
.status.success { display: block; background: #d1fae5; color: #065f46; }
|
|
#networks { margin-bottom: 16px; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<h1>PaperColor Setup</h1>
|
|
<form id="setupForm">
|
|
<div class="field">
|
|
<label>WiFi Network</label>
|
|
<select id="wifiSsid"><option value="">Scanning...</option></select>
|
|
</div>
|
|
<div class="field">
|
|
<label>WiFi Password</label>
|
|
<input type="password" id="wifiPass" required>
|
|
</div>
|
|
<div class="field">
|
|
<label>Immich URL</label>
|
|
<input type="url" id="immichUrl" value="https://photos.example.com">
|
|
</div>
|
|
<div class="field">
|
|
<label>Immich API Key</label>
|
|
<input type="text" id="immichKey" required placeholder="Your API key">
|
|
</div>
|
|
<button type="submit">Save & Connect</button>
|
|
</form>
|
|
<div id="status" class="status"></div>
|
|
|
|
<script>
|
|
async function scanNetworks() {
|
|
try {
|
|
const res = await fetch('/api/wifi/scan');
|
|
const data = await res.json();
|
|
if (data.scanning) {
|
|
// Scan in progress — retry after 2s
|
|
setTimeout(scanNetworks, 2000);
|
|
return;
|
|
}
|
|
const select = document.getElementById('wifiSsid');
|
|
if (data.length === 0) {
|
|
select.innerHTML = '<option value="">No networks found</option>';
|
|
setTimeout(scanNetworks, 3000);
|
|
return;
|
|
}
|
|
select.innerHTML = data.map(n =>
|
|
`<option value="${n.ssid}">${n.ssid} (${n.rssi}dBm)</option>`
|
|
).join('');
|
|
} catch (e) {
|
|
console.error('Scan failed:', e);
|
|
setTimeout(scanNetworks, 3000);
|
|
}
|
|
}
|
|
|
|
document.getElementById('setupForm').addEventListener('submit', async (e) => {
|
|
e.preventDefault();
|
|
const status = document.getElementById('status');
|
|
try {
|
|
const res = await fetch('/api/setup', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({
|
|
wifi_ssid: document.getElementById('wifiSsid').value,
|
|
wifi_pass: document.getElementById('wifiPass').value,
|
|
immich_url: document.getElementById('immichUrl').value,
|
|
immich_key: document.getElementById('immichKey').value
|
|
})
|
|
});
|
|
const data = await res.json();
|
|
if (data.ok) {
|
|
status.className = 'status success';
|
|
status.textContent = 'Saved! Device is rebooting...';
|
|
} else {
|
|
throw new Error(data.error || 'Unknown error');
|
|
}
|
|
} catch (e) {
|
|
status.className = 'status error';
|
|
status.textContent = 'Error: ' + e.message;
|
|
}
|
|
});
|
|
|
|
scanNetworks();
|
|
</script>
|
|
</body>
|
|
</html>
|