diff --git a/admin.html b/admin.html index ce75d1b..07e0588 100644 --- a/admin.html +++ b/admin.html @@ -1335,7 +1335,13 @@ async function loadTotpStatus() { } async function startEnableTotp() { - const res = await api("/admin/api/2fa/setup", { method: "POST" }); + let res; + try { + res = await api("/admin/api/2fa/setup", { method: "POST" }); + } catch (e) { + alert("Не получилось: " + e.message); + return; + } document.getElementById("totp-secret-display").textContent = res.secret; document.getElementById("totp-setup-box").dataset.secret = res.secret; document.getElementById("totp-setup-box").style.display = "block"; @@ -1525,7 +1531,11 @@ async function grantSubscription() { const node = DD.ucGrantNode.getValue(); const plan = DD.ucGrantPlan.getValue(); if (!node || !plan) return; - await api(`/admin/api/users/${devicesTgId}/grant`, { method: "POST", body: JSON.stringify({ node, plan }) }); + try { + await api(`/admin/api/users/${devicesTgId}/grant`, { method: "POST", body: JSON.stringify({ node, plan }) }); + } catch (e) { + alert("Не получилось: " + e.message); + } openUserCard(devicesTgId, document.getElementById("devices-title").textContent.replace("Карточка: ", "")); } function renderDevices(devices) { @@ -1541,28 +1551,48 @@ function renderDevices(devices) { `).join("") : '
Не получилось: ' + esc(e.message) + '
'; + } } function copyText(t) { navigator.clipboard.writeText(t); } @@ -1720,12 +1755,20 @@ async function saveEditNode() { } async function toggleNode(code, enabled) { - await api(`/admin/api/nodes/${code}`, { method: "PATCH", body: JSON.stringify({ enabled }) }); + try { + await api(`/admin/api/nodes/${code}`, { method: "PATCH", body: JSON.stringify({ enabled }) }); + } catch (e) { + alert("Не получилось: " + e.message); + } loadNodes(); } async function deleteNode(code) { if (!confirm("Удалить ноду?")) return; - await api(`/admin/api/nodes/${code}`, { method: "DELETE" }); + try { + await api(`/admin/api/nodes/${code}`, { method: "DELETE" }); + } catch (e) { + alert("Не получилось: " + e.message); + } loadNodes(); } @@ -1745,8 +1788,15 @@ async function generateGuide() { const include_hysteria2 = document.getElementById("ng-hy").checked; const hysteria_port = parseInt(document.getElementById("ng-hy-port").value || "443"); if (!label || !address) return; - const res = await api("/admin/api/nodes/provision-guide", { method: "POST", body: JSON.stringify({ label, address, port, sni, include_ws, include_hysteria2, hysteria_port }) }); - document.getElementById("guide-result").innerHTML = ` + const guideResult = document.getElementById("guide-result"); + let res; + try { + res = await api("/admin/api/nodes/provision-guide", { method: "POST", body: JSON.stringify({ label, address, port, sni, include_ws, include_hysteria2, hysteria_port }) }); + } catch (e) { + guideResult.innerHTML = 'Не получилось: ' + esc(e.message) + '
'; + return; + } + guideResult.innerHTML = `Выполни на новом сервере:
Ожидаю установки…
@@ -1774,9 +1824,14 @@ async function createManualNode() { shared_uuid: document.getElementById("nm-uuid").value.trim() || null, kind: document.getElementById("nm-uuid").value.trim() ? "external" : "managed", }; - await api("/admin/api/nodes", { method: "POST", body: JSON.stringify(body) }); - document.getElementById("manual-result").innerHTML = 'Нода добавлена.
'; - loadNodes(); + const result = document.getElementById("manual-result"); + try { + await api("/admin/api/nodes", { method: "POST", body: JSON.stringify(body) }); + result.innerHTML = 'Нода добавлена.
'; + loadNodes(); + } catch (e) { + result.innerHTML = 'Не получилось: ' + esc(e.message) + '
'; + } } function applyBrandName(name) {