d7b17d9cb2
One FastAPI process on port 9000 (the charger's hardcoded URL), replacing
discovering/station.py for production:
- csms.py: OCPP 1.6J handlers ported from the proven discovery code; the
decide() gate now supports per-gun RFID restriction ("connectors": [2])
enforced at StartTransaction
- users.py: username/password auth (PBKDF2), stateless HMAC sessions
(cookie + bearer, 30 days), fnmatch permission scopes
(charger:<cp>:<gun>, relay:<name>, admin) and a user CLI
- relays.py: local tinytuya control of the SmartLife/Tuya WiFi relays
(no cloud; needs one-time id/local-key extraction via tinytuya wizard)
- store.py: SQLite consumption tracking — who charged, when, how many kWh,
per-minute energy/power/SoC samples; tx ids survive restarts
- routes.py: /api/* with per-scope checks, allowlist/user CRUD, runtime
learn-mode flip, session history with visibility rules
- static/: self-contained vanilla-JS PWA — login, per-gun start/stop gated
by scope + gun readiness, relay toggles, history, admin tab
config.json (password hashes, session secret, Tuya keys) and sessions.db
are gitignored; config.example.json documents the shape. Covered by a
37-check smoke test incl. a fake charge point over the real WS route.
487 lines
19 KiB
HTML
487 lines
19 KiB
HTML
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
|
|
<meta name="theme-color" content="#0f172a">
|
|
<title>Home Energy</title>
|
|
<link rel="manifest" href="/static/manifest.json">
|
|
<link rel="icon" href="/static/icon.svg">
|
|
<style>
|
|
:root {
|
|
--bg: #f1f5f9; --card: #ffffff; --text: #0f172a; --muted: #64748b;
|
|
--line: #e2e8f0; --accent: #2563eb; --ok: #16a34a; --warn: #d97706;
|
|
--bad: #dc2626; --chip: #e2e8f0;
|
|
}
|
|
@media (prefers-color-scheme: dark) {
|
|
:root {
|
|
--bg: #0f172a; --card: #1e293b; --text: #e2e8f0; --muted: #94a3b8;
|
|
--line: #334155; --chip: #334155;
|
|
}
|
|
}
|
|
* { box-sizing: border-box; margin: 0; }
|
|
body {
|
|
background: var(--bg); color: var(--text);
|
|
font: 16px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
|
|
padding-bottom: 76px;
|
|
}
|
|
header {
|
|
display: flex; align-items: center; gap: 8px;
|
|
padding: 14px 16px 10px;
|
|
}
|
|
header h1 { font-size: 20px; flex: 1; }
|
|
header .who { color: var(--muted); font-size: 14px; }
|
|
main { max-width: 640px; margin: 0 auto; padding: 0 12px; }
|
|
.card {
|
|
background: var(--card); border: 1px solid var(--line);
|
|
border-radius: 14px; padding: 14px 16px; margin-bottom: 12px;
|
|
}
|
|
.card h2 { font-size: 15px; color: var(--muted); margin-bottom: 10px; font-weight: 600; }
|
|
.row { display: flex; align-items: center; gap: 10px; }
|
|
.row .grow { flex: 1; min-width: 0; }
|
|
.title { font-weight: 600; }
|
|
.sub { color: var(--muted); font-size: 13px; }
|
|
.chip {
|
|
display: inline-block; padding: 2px 10px; border-radius: 999px;
|
|
background: var(--chip); font-size: 13px; font-weight: 600;
|
|
}
|
|
.chip.ok { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
|
|
.chip.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
|
|
.chip.bad { background: color-mix(in srgb, var(--bad) 18%, transparent); color: var(--bad); }
|
|
.chip.accent { background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); }
|
|
button {
|
|
font: inherit; font-weight: 600; border: 0; border-radius: 10px;
|
|
padding: 10px 16px; cursor: pointer; background: var(--accent); color: #fff;
|
|
}
|
|
button.secondary { background: var(--chip); color: var(--text); }
|
|
button.danger { background: var(--bad); }
|
|
button.small { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
|
|
button:disabled { opacity: .45; cursor: default; }
|
|
input, select {
|
|
font: inherit; color: var(--text); background: var(--bg);
|
|
border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%;
|
|
}
|
|
form .row { margin-bottom: 8px; }
|
|
table { width: 100%; border-collapse: collapse; font-size: 14px; }
|
|
th, td { text-align: left; padding: 7px 6px; border-bottom: 1px solid var(--line); }
|
|
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }
|
|
td.num, th.num { text-align: right; }
|
|
.scroll { overflow-x: auto; }
|
|
nav {
|
|
position: fixed; bottom: 0; left: 0; right: 0;
|
|
display: flex; background: var(--card); border-top: 1px solid var(--line);
|
|
padding-bottom: env(safe-area-inset-bottom);
|
|
}
|
|
nav button {
|
|
flex: 1; background: none; color: var(--muted); border-radius: 0;
|
|
padding: 12px 0 10px; font-size: 13px;
|
|
}
|
|
nav button.active { color: var(--accent); }
|
|
#toast {
|
|
position: fixed; left: 50%; bottom: 86px; transform: translateX(-50%);
|
|
background: var(--text); color: var(--bg); padding: 10px 18px;
|
|
border-radius: 10px; font-size: 14px; opacity: 0; transition: opacity .25s;
|
|
pointer-events: none; max-width: 90vw;
|
|
}
|
|
#toast.show { opacity: 1; }
|
|
#login { max-width: 360px; margin: 12vh auto 0; padding: 0 16px; }
|
|
#login .card { padding: 22px; }
|
|
#login h1 { font-size: 22px; margin-bottom: 16px; text-align: center; }
|
|
#login button { width: 100%; margin-top: 6px; }
|
|
.hidden { display: none !important; }
|
|
.offline { text-align: center; color: var(--muted); padding: 18px 0; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<div id="login" class="hidden">
|
|
<div class="card">
|
|
<h1>⚡ Home Energy</h1>
|
|
<form onsubmit="return doLogin(event)">
|
|
<div class="row"><input id="l-user" placeholder="Username" autocomplete="username" required></div>
|
|
<div class="row"><input id="l-pass" type="password" placeholder="Password" autocomplete="current-password" required></div>
|
|
<button>Log in</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="app" class="hidden">
|
|
<header>
|
|
<h1>⚡ Home Energy</h1>
|
|
<span class="who" id="whoami"></span>
|
|
<button class="secondary small" id="logout-btn" onclick="doLogout()">Log out</button>
|
|
</header>
|
|
<main>
|
|
<section id="tab-control">
|
|
<div id="guns"></div>
|
|
<div class="card" id="relays-card">
|
|
<h2>Relays</h2>
|
|
<div id="relays"></div>
|
|
<div class="row" style="margin-top:8px">
|
|
<button class="secondary small" onclick="refreshRelaysLive()">Refresh live states</button>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
|
|
<section id="tab-history" class="hidden">
|
|
<div class="card">
|
|
<h2>Charging sessions</h2>
|
|
<div class="scroll"><table>
|
|
<thead><tr><th>Who</th><th>Gun</th><th>Started</th><th class="num">kWh</th><th></th></tr></thead>
|
|
<tbody id="sessions"></tbody>
|
|
</table></div>
|
|
</div>
|
|
</section>
|
|
|
|
<section id="tab-admin" class="hidden">
|
|
<div class="card">
|
|
<h2>Mode</h2>
|
|
<div class="row">
|
|
<div class="grow"><span class="title" id="mode-label"></span>
|
|
<div class="sub">Learn mode accepts and records unknown cards; enforce rejects them.</div></div>
|
|
<button class="small" id="mode-btn" onclick="toggleMode()"></button>
|
|
</div>
|
|
</div>
|
|
<div class="card">
|
|
<h2>Allowlist</h2>
|
|
<div class="scroll"><table>
|
|
<thead><tr><th>idTag</th><th>Name</th><th>Guns</th><th></th></tr></thead>
|
|
<tbody id="allowlist"></tbody>
|
|
</table></div>
|
|
<div id="seen-tags"></div>
|
|
<form onsubmit="return addAllowlist(event)" style="margin-top:10px">
|
|
<div class="row"><input id="a-tag" placeholder="idTag" required></div>
|
|
<div class="row">
|
|
<input id="a-name" placeholder="Name (e.g. RFID card C)" required>
|
|
<select id="a-kind" style="width:110px"><option>card</option><option>app</option><option>car</option></select>
|
|
</div>
|
|
<div class="row">
|
|
<input id="a-conn" placeholder="Guns, e.g. 1,2 — empty = all">
|
|
<button class="small">Add</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
<div class="card">
|
|
<h2>Users</h2>
|
|
<div class="scroll"><table>
|
|
<thead><tr><th>User</th><th>Scopes</th><th></th></tr></thead>
|
|
<tbody id="users"></tbody>
|
|
</table></div>
|
|
<form onsubmit="return addUser(event)" style="margin-top:10px">
|
|
<div class="row"><input id="u-name" placeholder="Username" required></div>
|
|
<div class="row"><input id="u-pass" type="password" placeholder="Password (empty = keep current)"></div>
|
|
<div class="row">
|
|
<input id="u-scopes" placeholder='Scopes, e.g. admin or charger:eu092025:1 relay:*'>
|
|
<button class="small">Save</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</section>
|
|
</main>
|
|
<nav>
|
|
<button data-tab="control" class="active" onclick="showTab('control')">⚡ Control</button>
|
|
<button data-tab="history" onclick="showTab('history')">📊 History</button>
|
|
<button data-tab="admin" class="hidden" onclick="showTab('admin')">⚙ Admin</button>
|
|
</nav>
|
|
</div>
|
|
|
|
<div id="toast"></div>
|
|
|
|
<script>
|
|
"use strict";
|
|
let me = null, status = null, pollTimer = null;
|
|
|
|
// ---- tiny helpers ----
|
|
const $ = (id) => document.getElementById(id);
|
|
const esc = (s) => String(s ?? "").replace(/[&<>"']/g, c => ({"&":"&","<":"<",">":">",'"':""","'":"'"}[c]));
|
|
|
|
function toast(msg) {
|
|
const t = $("toast");
|
|
t.textContent = msg;
|
|
t.classList.add("show");
|
|
clearTimeout(t._h);
|
|
t._h = setTimeout(() => t.classList.remove("show"), 3000);
|
|
}
|
|
|
|
async function api(path, opts = {}) {
|
|
const r = await fetch("/api" + path, {
|
|
headers: { "Content-Type": "application/json" }, ...opts,
|
|
});
|
|
if (r.status === 401 && path !== "/login") { showLogin(); throw new Error("not logged in"); }
|
|
if (!r.ok) {
|
|
let detail = r.statusText;
|
|
try { detail = (await r.json()).detail || detail; } catch {}
|
|
throw new Error(detail);
|
|
}
|
|
return r.json();
|
|
}
|
|
|
|
// fnmatch-style scope check, mirroring backend/users.py
|
|
function scopeOk(needed) {
|
|
if (!me) return false;
|
|
return me.scopes.some(g => {
|
|
if (g === "*" || g === "admin") return true;
|
|
const re = new RegExp("^" + g.split("*").map(p => p.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join(".*") + "$");
|
|
return re.test(needed);
|
|
});
|
|
}
|
|
const isAdmin = () => me && me.scopes.some(g => g === "admin" || g === "*");
|
|
|
|
// ---- login flow ----
|
|
function showLogin() {
|
|
clearInterval(pollTimer);
|
|
$("app").classList.add("hidden");
|
|
$("login").classList.remove("hidden");
|
|
}
|
|
|
|
async function doLogin(ev) {
|
|
ev.preventDefault();
|
|
try {
|
|
await api("/login", { method: "POST", body: JSON.stringify({
|
|
username: $("l-user").value.trim(), password: $("l-pass").value }) });
|
|
$("l-pass").value = "";
|
|
await boot();
|
|
} catch (e) { toast(e.message); }
|
|
return false;
|
|
}
|
|
|
|
async function doLogout() {
|
|
await api("/logout", { method: "POST" }).catch(() => {});
|
|
me = null;
|
|
showLogin();
|
|
}
|
|
|
|
async function boot() {
|
|
try { me = await api("/me"); } catch { return; } // api() already showed login
|
|
$("login").classList.add("hidden");
|
|
$("app").classList.remove("hidden");
|
|
$("whoami").textContent = me.name === "anonymous" ? "open mode" : me.name;
|
|
$("logout-btn").classList.toggle("hidden", me.name === "anonymous");
|
|
document.querySelector('nav [data-tab="admin"]').classList.toggle("hidden", !isAdmin());
|
|
await refreshStatus();
|
|
clearInterval(pollTimer);
|
|
pollTimer = setInterval(() => {
|
|
if (!document.hidden && !$("tab-control").classList.contains("hidden")) refreshStatus();
|
|
}, 5000);
|
|
}
|
|
|
|
// ---- tabs ----
|
|
function showTab(name) {
|
|
for (const t of ["control", "history", "admin"]) {
|
|
$("tab-" + t).classList.toggle("hidden", t !== name);
|
|
document.querySelector(`nav [data-tab="${t}"]`).classList.toggle("active", t === name);
|
|
}
|
|
if (name === "history") loadSessions();
|
|
if (name === "admin") loadAdmin();
|
|
if (name === "control") refreshStatus();
|
|
}
|
|
|
|
// ---- control tab ----
|
|
const STATUS_CHIP = {
|
|
Available: "", Preparing: "accent", Charging: "ok", SuspendedEV: "warn",
|
|
SuspendedEVSE: "warn", Finishing: "", Faulted: "bad", Unavailable: "bad", Reserved: "warn",
|
|
};
|
|
|
|
async function refreshStatus() {
|
|
try { status = await api("/status"); } catch { return; }
|
|
renderGuns();
|
|
renderRelays(null);
|
|
}
|
|
|
|
function renderGuns() {
|
|
const box = $("guns");
|
|
const cps = Object.keys(status.connected);
|
|
if (!cps.length) {
|
|
box.innerHTML = `<div class="card"><div class="offline">Charger offline — waiting for it to dial in…</div></div>`;
|
|
return;
|
|
}
|
|
// active transaction per (cp, connector)
|
|
const txByGun = {};
|
|
for (const [tx, info] of Object.entries(status.active_transactions))
|
|
txByGun[`${info.cp}/${info.connector}`] = { tx, ...info };
|
|
|
|
let html = "";
|
|
for (const cp of cps) {
|
|
const conns = Object.entries(status.connectors)
|
|
.map(([key, st]) => ({ key, st, conn: +key.split("/")[1], cpId: key.split("/")[0] }))
|
|
.filter(c => c.cpId === cp && c.conn > 0)
|
|
.sort((a, b) => a.conn - b.conn);
|
|
if (!conns.length)
|
|
html += `<div class="card"><div class="sub">${esc(cp)} connected — no gun status yet</div></div>`;
|
|
for (const { conn, st } of conns) {
|
|
const gunName = conn === 1 ? "Gun 1 · EU (CCS)" : conn === 2 ? "Gun 2 · GB/T" : `Gun ${conn}`;
|
|
const active = txByGun[`${cp}/${conn}`];
|
|
const may = scopeOk(`charger:${cp}:${conn}`);
|
|
const canStart = may && !active && (st === "Preparing" || st === "Available");
|
|
let action = "";
|
|
if (active && may)
|
|
action = `<button class="danger" onclick="stopTx(${active.tx})">Stop</button>`;
|
|
else if (!active)
|
|
action = `<button ${canStart ? "" : "disabled"} onclick="startGun('${esc(cp)}',${conn})">Start</button>`;
|
|
let sub = st === "Preparing" && !active ? "Cable plugged — ready to start" : "";
|
|
if (active) sub = `${esc(active.who || active.id_tag)} · since ${fmtTime(active.started)}`;
|
|
if (!may) sub = "No permission for this gun";
|
|
html += `<div class="card"><div class="row">
|
|
<div class="grow"><div class="title">${gunName}</div><div class="sub">${sub || " "}</div></div>
|
|
<span class="chip ${STATUS_CHIP[st] || ""}">${esc(st)}</span>${action}
|
|
</div></div>`;
|
|
}
|
|
}
|
|
box.innerHTML = html;
|
|
}
|
|
|
|
async function startGun(cp, conn) {
|
|
try {
|
|
const r = await api(`/charger/start?connector=${conn}&cp=${encodeURIComponent(cp)}`, { method: "POST" });
|
|
toast(`Start: ${r.remote_start}`);
|
|
setTimeout(refreshStatus, 1500);
|
|
} catch (e) { toast(e.message); }
|
|
}
|
|
|
|
async function stopTx(tx) {
|
|
try {
|
|
const r = await api(`/charger/stop/${tx}`, { method: "POST" });
|
|
toast(`Stop: ${r.remote_stop}`);
|
|
setTimeout(refreshStatus, 1500);
|
|
} catch (e) { toast(e.message); }
|
|
}
|
|
|
|
// ---- relays ----
|
|
let relayLive = {}; // name -> true/false/undefined, from the last live poll/switch
|
|
|
|
function renderRelays(_) {
|
|
const names = Object.keys(status.relays || {});
|
|
$("relays-card").classList.toggle("hidden", !names.length);
|
|
$("relays").innerHTML = names.map(name => {
|
|
const label = status.relays[name].label || name;
|
|
const on = relayLive[name];
|
|
const chip = on === undefined ? `<span class="chip">?</span>`
|
|
: `<span class="chip ${on ? "ok" : ""}">${on ? "ON" : "OFF"}</span>`;
|
|
return `<div class="row" style="padding:6px 0">
|
|
<div class="grow title">${esc(label)}</div>${chip}
|
|
<button class="small" onclick="toggleRelay('${esc(name)}')">Toggle</button>
|
|
</div>`;
|
|
}).join("");
|
|
}
|
|
|
|
async function toggleRelay(name) {
|
|
try {
|
|
const r = await api(`/relays/${encodeURIComponent(name)}/toggle`, { method: "POST" });
|
|
relayLive[name] = r.on;
|
|
renderRelays();
|
|
toast(`${name}: ${r.on ? "ON" : "OFF"}`);
|
|
} catch (e) { toast(e.message); }
|
|
}
|
|
|
|
async function refreshRelaysLive() {
|
|
try {
|
|
const live = await api("/relays?live=true");
|
|
for (const [name, st] of Object.entries(live))
|
|
relayLive[name] = "on" in st ? st.on : undefined;
|
|
renderRelays();
|
|
} catch (e) { toast(e.message); }
|
|
}
|
|
|
|
// ---- history tab ----
|
|
const fmtTime = (iso) => iso ? new Date(iso).toLocaleString([], { dateStyle: "short", timeStyle: "short" }) : "";
|
|
const fmtKwh = (wh) => wh == null ? "…" : (wh / 1000).toFixed(2);
|
|
|
|
function fmtDuration(a, b) {
|
|
if (!a || !b) return "";
|
|
const mins = Math.max(0, Math.round((new Date(b) - new Date(a)) / 60000));
|
|
return mins >= 60 ? `${Math.floor(mins / 60)}h${String(mins % 60).padStart(2, "0")}` : `${mins}m`;
|
|
}
|
|
|
|
async function loadSessions() {
|
|
try {
|
|
const rows = await api("/sessions?limit=100");
|
|
$("sessions").innerHTML = rows.map(s => `<tr>
|
|
<td>${esc(s.who || s.id_tag)}</td>
|
|
<td>${s.connector}</td>
|
|
<td>${fmtTime(s.started)}</td>
|
|
<td class="num"><b>${fmtKwh(s.wh)}</b></td>
|
|
<td class="sub">${s.ended ? fmtDuration(s.started, s.ended) : '<span class="chip ok">live</span>'}</td>
|
|
</tr>`).join("") || `<tr><td colspan="5" class="sub">No sessions yet</td></tr>`;
|
|
} catch (e) { toast(e.message); }
|
|
}
|
|
|
|
// ---- admin tab ----
|
|
async function loadAdmin() {
|
|
try {
|
|
const al = await api("/allowlist");
|
|
$("mode-label").textContent = al.learn_mode ? "Learn mode" : "Enforcing allowlist";
|
|
$("mode-btn").textContent = al.learn_mode ? "Enforce" : "Back to learn";
|
|
$("mode-btn").dataset.learn = al.learn_mode;
|
|
$("allowlist").innerHTML = Object.entries(al.authorized).map(([tag, e]) => `<tr>
|
|
<td class="sub">${esc(tag)}</td><td>${esc(e.name)}</td>
|
|
<td>${e.connectors ? e.connectors.join(",") : "all"}</td>
|
|
<td><button class="danger small" onclick="delAllowlist('${esc(tag)}')">✕</button></td>
|
|
</tr>`).join("");
|
|
const seen = Object.entries(al.seen || {}).filter(([tag]) => !(tag in al.authorized));
|
|
$("seen-tags").innerHTML = seen.length
|
|
? `<div class="sub" style="margin-top:8px">Seen but not enrolled:</div>` + seen.map(([tag, s]) =>
|
|
`<div class="row" style="padding:4px 0"><div class="grow sub">${esc(tag)} (×${s.count})</div>
|
|
<button class="small secondary" onclick="$('a-tag').value='${esc(tag)}';$('a-name').focus()">Enroll</button></div>`).join("")
|
|
: "";
|
|
const users = await api("/users");
|
|
$("users").innerHTML = users.map(u => `<tr>
|
|
<td>${esc(u.name)}</td><td class="sub">${esc(u.scopes.join(" "))}</td>
|
|
<td><button class="danger small" onclick="delUser('${esc(u.name)}')">✕</button></td>
|
|
</tr>`).join("") || `<tr><td colspan="3" class="sub">No users — API is open</td></tr>`;
|
|
} catch (e) { toast(e.message); }
|
|
}
|
|
|
|
async function toggleMode() {
|
|
const toLearn = $("mode-btn").dataset.learn !== "true";
|
|
if (!toLearn && !confirm("Enforce the allowlist? Unknown cards will be rejected.")) return;
|
|
try { await api(`/mode?learn=${toLearn}`, { method: "POST" }); loadAdmin(); }
|
|
catch (e) { toast(e.message); }
|
|
}
|
|
|
|
async function addAllowlist(ev) {
|
|
ev.preventDefault();
|
|
const body = { name: $("a-name").value.trim(), kind: $("a-kind").value };
|
|
const conns = $("a-conn").value.trim();
|
|
if (conns) body.connectors = conns.split(",").map(s => +s.trim()).filter(Boolean);
|
|
try {
|
|
await api(`/allowlist/${encodeURIComponent($("a-tag").value.trim())}`,
|
|
{ method: "PUT", body: JSON.stringify(body) });
|
|
$("a-tag").value = $("a-name").value = $("a-conn").value = "";
|
|
loadAdmin();
|
|
} catch (e) { toast(e.message); }
|
|
return false;
|
|
}
|
|
|
|
async function delAllowlist(tag) {
|
|
if (!confirm(`Remove ${tag} from the allowlist?`)) return;
|
|
try { await api(`/allowlist/${encodeURIComponent(tag)}`, { method: "DELETE" }); loadAdmin(); }
|
|
catch (e) { toast(e.message); }
|
|
}
|
|
|
|
async function addUser(ev) {
|
|
ev.preventDefault();
|
|
const body = {};
|
|
if ($("u-pass").value) body.password = $("u-pass").value;
|
|
if ($("u-scopes").value.trim()) body.scopes = $("u-scopes").value.trim().split(/\s+/);
|
|
try {
|
|
await api(`/users/${encodeURIComponent($("u-name").value.trim())}`,
|
|
{ method: "PUT", body: JSON.stringify(body) });
|
|
$("u-name").value = $("u-pass").value = $("u-scopes").value = "";
|
|
loadAdmin();
|
|
} catch (e) { toast(e.message); }
|
|
return false;
|
|
}
|
|
|
|
async function delUser(name) {
|
|
if (!confirm(`Delete user ${name}?`)) return;
|
|
try { await api(`/users/${encodeURIComponent(name)}`, { method: "DELETE" }); loadAdmin(); }
|
|
catch (e) { toast(e.message); }
|
|
}
|
|
|
|
// ---- go ----
|
|
if ("serviceWorker" in navigator) navigator.serviceWorker.register("/sw.js").catch(() => {});
|
|
boot();
|
|
</script>
|
|
</body>
|
|
</html>
|