diff options
Diffstat (limited to 'packages/meshbay-hub/src/meshbay_hub/static/node-page.js')
| -rw-r--r-- | packages/meshbay-hub/src/meshbay_hub/static/node-page.js | 74 |
1 files changed, 36 insertions, 38 deletions
diff --git a/packages/meshbay-hub/src/meshbay_hub/static/node-page.js b/packages/meshbay-hub/src/meshbay_hub/static/node-page.js index 7fd7ab1..f940934 100644 --- a/packages/meshbay-hub/src/meshbay_hub/static/node-page.js +++ b/packages/meshbay-hub/src/meshbay_hub/static/node-page.js @@ -10,7 +10,7 @@ import { HUB } from './hub-client.js'; // ── Node management (D5) ──────────────────────────────────────────────────── // // Electron-only: talks to the local node daemon via its loopback HTTP API -// (platform.node.call), not over MNP/WebRTC. The MNP protocol types remain +// (platform.node.op), not over MNP/WebRTC. The MNP protocol types remain // for potential future browser-side use. // true / false from a node that has read its roster, null from one that has @@ -163,8 +163,8 @@ function NodeServicePanel({ onChanged, token, username }) { </div>`; } -async function nodeCall(method, path, body) { - return platform.node.call(method, path, body); +async function nodeOp(name, args) { + return platform.node.op(name, args); } // Hand a generated file to the user: native Save As on the desktop, a blob @@ -237,11 +237,11 @@ export function NodePage({ groups, token, username }) { setStatus('error'); return; } - const result = await nodeCall('GET', '/api/groups'); + const result = await nodeOp('groups'); setNodeGroups(result.groups || []); setOperatorPaired(pairedFrom(result)); setNodeSettings(result.settings || null); - try { setNodeInfo(await nodeCall('GET', '/api/status')); } catch {} + try { setNodeInfo(await nodeOp('status')); } catch {} setStatus('connected'); } catch (err) { setError(platform.bridgeMessage(err)); @@ -259,11 +259,11 @@ export function NodePage({ groups, token, username }) { const refresh = useCallback(async () => { try { - const result = await nodeCall('GET', '/api/groups'); + const result = await nodeOp('groups'); setNodeGroups(result.groups || []); setOperatorPaired(pairedFrom(result)); setNodeSettings(result.settings || null); - try { setNodeInfo(await nodeCall('GET', '/api/status')); } catch {} + try { setNodeInfo(await nodeOp('status')); } catch {} } catch {} }, []); @@ -283,8 +283,8 @@ export function NodePage({ groups, token, username }) { setBusy(true); setActionMsg(''); try { - await nodeCall('POST', `/api/groups/${groupId}/roots`, { path: chosen.path }); - await nodeCall('POST', '/api/reload'); + await nodeOp('addRoot', { groupId, path: chosen.path }); + await nodeOp('reload'); await refresh(); setActionMsg(t('node.root_added')); } catch (err) { @@ -299,8 +299,8 @@ export function NodePage({ groups, token, username }) { setBusy(true); setActionMsg(''); try { - await nodeCall('DELETE', `/api/groups/${groupId}/roots/${encodeURIComponent(rootName)}`); - await nodeCall('POST', '/api/reload'); + await nodeOp('removeRoot', { groupId, rootName }); + await nodeOp('reload'); await refresh(); setActionMsg(t('node.root_removed')); } catch (err) { @@ -313,7 +313,7 @@ export function NodePage({ groups, token, username }) { const loadRoster = useCallback(async (groupId) => { setBusy(true); try { - const result = await nodeCall('GET', `/api/roster?group_id=${groupId}`); + const result = await nodeOp('roster', { groupId }); setRoster(result); setRosterGroup(groupId); } catch (err) { @@ -328,7 +328,7 @@ export function NodePage({ groups, token, username }) { setBusy(true); setActionMsg(''); try { - await nodeCall('POST', `/api/members/${userId}/unpin`); + await nodeOp('unpinMember', { userId }); setActionMsg(t('node.unpin_done')); if (rosterGroup) await loadRoster(rosterGroup); } catch (err) { @@ -338,12 +338,13 @@ export function NodePage({ groups, token, username }) { } }, [rosterGroup, loadRoster]); + // No confirmation drawn here: replacing the key is asked natively by the + // app itself (node:op), which a script in this page cannot answer. const rotateGek = useCallback(async (groupId) => { - if (!await ask(t('node.gek_rotate_confirm'))) return; setBusy(true); setActionMsg(''); try { - await nodeCall('POST', `/api/groups/${groupId}/gek?rotate=true`); + await nodeOp('initGek', { groupId, rotate: true }); setActionMsg(t('node.gek_rotated')); } catch (err) { setActionMsg(platform.bridgeMessage(err)); @@ -355,7 +356,7 @@ export function NodePage({ groups, token, username }) { const loadDenylist = useCallback(async () => { setBusy(true); try { - const result = await nodeCall('GET', '/api/denylist'); + const result = await nodeOp('denylist'); setDenylist(result); setShowDenylist(true); } catch (err) { @@ -366,12 +367,11 @@ export function NodePage({ groups, token, username }) { }, []); const clearDenylist = useCallback(async (subject) => { - const label = subject || t('node.denylist_clear_all'); - if (!await ask(t('node.denylist_clear_confirm', { subject: label }))) return; + // Asked natively by the app (node:op): it re-admits whoever it kept out. setBusy(true); setActionMsg(''); try { - await nodeCall('POST', `/api/denylist/clear?subject=${encodeURIComponent(subject)}`); + await nodeOp('clearDenylist', { subject }); setActionMsg(t('node.denylist_cleared')); await loadDenylist(); } catch (err) { @@ -386,8 +386,8 @@ export function NodePage({ groups, token, username }) { setBusy(true); setActionMsg(''); try { - await nodeCall('POST', '/api/groups/detach', { name }); - await nodeCall('POST', '/api/reload'); + await nodeOp('detachGroup', { name }); + await nodeOp('reload'); setActionMsg(t('node.detached')); await refresh(); } catch (err) { @@ -401,7 +401,7 @@ export function NodePage({ groups, token, username }) { setBusy(true); setActionMsg(''); try { - await nodeCall('POST', '/api/reload'); + await nodeOp('reload'); setActionMsg(t('node.reloaded')); await refresh(); } catch (err) { @@ -416,7 +416,7 @@ export function NodePage({ groups, token, username }) { setSavingSettings(true); setActionMsg(''); try { - await nodeCall('PUT', '/api/node-settings', editSettings); + await nodeOp('setNodeSettings', { settings: editSettings }); setNodeSettings({ ...editSettings }); setActionMsg(t('node.settings_saved')); } catch (err) { @@ -431,7 +431,7 @@ export function NodePage({ groups, token, username }) { setSavingStun(true); setActionMsg(''); try { - await nodeCall('PUT', '/api/node-settings', { stun_servers: editStun }); + await nodeOp('setNodeSettings', { settings: { stun_servers: editStun } }); setNodeSettings(s => s ? { ...s, stun_servers: [...editStun] } : s); setActionMsg(t('node.stun_saved')); } catch (err) { @@ -486,7 +486,7 @@ export function NodePage({ groups, token, username }) { setSavingIce(true); setActionMsg(''); try { - await nodeCall('PUT', '/api/node-settings', { ice_interfaces: editIce }); + await nodeOp('setNodeSettings', { settings: { ice_interfaces: editIce } }); setNodeSettings(s => s ? { ...s, ice_interfaces: [...editIce] } : s); setActionMsg(t('node.ice_saved')); } catch (err) { @@ -521,7 +521,7 @@ export function NodePage({ groups, token, username }) { setPairBusy(true); setPairStatus(''); try { - const result = await nodeCall('POST', '/api/operator/pair'); + const result = await nodeOp('pairOperator'); if (result && result.code) { await platform.node.setPairingCode(result.code); } @@ -538,7 +538,7 @@ export function NodePage({ groups, token, username }) { const loadPeers = useCallback(async () => { setBusy(true); try { - const r = await nodeCall('GET', '/api/peers'); + const r = await nodeOp('peers'); setPeers(r.peers || []); } catch (err) { setActionMsg(platform.bridgeMessage(err)); @@ -551,9 +551,8 @@ export function NodePage({ groups, token, username }) { setBusy(true); try { const offset = auditPage * auditPageSize; - let path = `/api/audit?limit=${auditPageSize}&offset=${offset}`; - if (auditEvent) path += `&event=${encodeURIComponent(auditEvent)}`; - const r = await nodeCall('GET', path); + const r = await nodeOp('audit', { limit: auditPageSize, offset, + event: auditEvent || undefined }); setAudit(r.entries || []); setAuditHasMore(!!r.has_more); } catch (err) { @@ -572,12 +571,11 @@ export function NodePage({ groups, token, username }) { // mid-export (which shifts rows to a higher offset) cannot duplicate one. const PAGE = 1000; const MAX_PAGES = 1000; // 1M-row stop, so a bug cannot spin forever - const evq = auditEvent ? `&event=${encodeURIComponent(auditEvent)}` : ''; const seen = new Set(); const rows = []; for (let page = 0; page < MAX_PAGES; page++) { - const r = await nodeCall( - 'GET', `/api/audit?limit=${PAGE}&offset=${page * PAGE}${evq}`); + const r = await nodeOp('audit', { limit: PAGE, offset: page * PAGE, + event: auditEvent || undefined }); const batch = r.entries || []; for (const e of batch) { if (!seen.has(e.id)) { seen.add(e.id); rows.push(e); } @@ -613,7 +611,7 @@ export function NodePage({ groups, token, username }) { const loadCache = useCallback(async () => { setBusy(true); try { - const r = await nodeCall('GET', '/api/index-cache'); + const r = await nodeOp('indexCache'); setCacheCount(r.count ?? 0); } catch (err) { setActionMsg(platform.bridgeMessage(err)); @@ -626,7 +624,7 @@ export function NodePage({ groups, token, username }) { setBusy(true); setActionMsg(''); try { - const r = await nodeCall('POST', '/api/index-cache/prune'); + const r = await nodeOp('pruneIndexCache'); setCacheCount(r.kept ?? null); setActionMsg(t('node.maintenance_pruned', { n: r.removed ?? 0 })); } catch (err) { @@ -639,7 +637,7 @@ export function NodePage({ groups, token, username }) { const loadNodeRoster = useCallback(async () => { setBusy(true); try { - const r = await nodeCall('GET', '/api/roster'); + const r = await nodeOp('roster'); setNodeRoster(r); } catch (err) { setActionMsg(platform.bridgeMessage(err)); @@ -653,7 +651,7 @@ export function NodePage({ groups, token, username }) { setBusy(true); setActionMsg(''); try { - await nodeCall('POST', `/api/members/${userId}/unpin`); + await nodeOp('unpinMember', { userId }); setActionMsg(t('node.unpin_done')); await loadNodeRoster(); } catch (err) { @@ -668,7 +666,7 @@ export function NodePage({ groups, token, username }) { setUnlinkBusy(true); setActionMsg(''); try { - await nodeCall('DELETE', '/api/unlink'); + await nodeOp('unlink'); setActionMsg(t('node.unlink_done')); await refresh(); } catch (err) { |