Discord: log node-reported stream state; remove a radio channel or a server

- handle_actual logs every node-reported state TRANSITION (not heartbeats)
  with stream/node/guild/channel/token ids and the node's error text: info
  for connected/connecting/stopped, warning for error, and a dedicated
  "radio bot X failed to log in on node N: <reason>" line for login_failed.
  The node's reason code is now stored in actual.code and shown next to the
  error on Settings > Discord and the node page.
- Remove a radio channel permanently: streams.delete_stream stops it through
  desired state first (node republished without it, token -> releasing per
  #216, freed on the node's ack), then deletes the doc in a transaction that
  refuses if the channel was restarted in between. DELETE
  /discord/streams/{id} (platform admin) and DELETE
  /discord/nodes/{node}/streams/{id} (admin or org owner, same org + node
  only; operators can still stop, not remove). Audited.
- Remove a server: DELETE /discord/guilds/{id} (admin) deletes every radio
  channel in it the same way, then tombstones discord_guilds (org_id None +
  unlinked_at, #218 semantics, plus removed_at) so it never falls back to
  DISCORD_UNLINKED_GUILD_ORG_ID; the admin page hides it, and /drb link or the
  admin link brings it back. Optional leave_radio_bots makes pool bots and the
  server's org's own BYO bots leave via Discord REST; the DRB server bot stays
  until kicked, and the UI says so. Audited.
- UI: Remove (with confirm) on Radio channels, Servers and the node page list.

Refs #213, #221

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Logan Cusano
2026-10-04 22:40:43 -04:00
co-authored by Claude Opus 5.5
parent fabdf5839e
commit c92bdfe841
13 changed files with 836 additions and 25 deletions
+43 -12
View File
@@ -354,8 +354,24 @@ export function NodeDiscordRadio({ nodeId }: { nodeId: string }) {
}
}
async function remove(s: DiscordStreamView) {
const name = s.channel_name ?? "this channel";
if (!confirm(`Remove radio from ${name} permanently? It is stopped first (the node logs its radio bot out), then deleted from DRB.`)) return;
setBusy(`rm:${s.stream_id}`);
setActionError(null);
try {
await c2api.removeNodeDiscordStream(nodeId, s.stream_id);
await load();
} catch (err) {
setActionError(parseC2Error(err).message);
} finally {
setBusy(null);
}
}
const streams = options?.streams ?? [];
const canControl = options?.can_control ?? false;
const canRemove = options?.can_remove ?? false;
return (
<section className="bg-surface border border-line rounded-lg overflow-hidden">
@@ -405,7 +421,7 @@ export function NodeDiscordRadio({ nodeId }: { nodeId: string }) {
<th className="px-4 py-2 text-left font-medium">Server · channel</th>
<th className="px-4 py-2 text-left font-medium">Mode</th>
<th className="px-4 py-2 text-left font-medium">Desired → actual</th>
{canControl && <th className="px-4 py-2" />}
{(canControl || canRemove) && <th className="px-4 py-2" />}
</tr>
</thead>
<tbody>
@@ -419,19 +435,34 @@ export function NodeDiscordRadio({ nodeId }: { nodeId: string }) {
<td className="px-4 py-2.5">
<StatePill s={s} />
{s.actual?.error && (
<div className="text-xs text-ink-muted mt-1 max-w-xs">{s.actual.error}</div>
<div className="text-xs text-ink-muted mt-1 max-w-xs">
{s.actual.error}
{s.actual.code && <span className="font-mono"> [{s.actual.code}]</span>}
</div>
)}
</td>
{canControl && (
<td className="px-4 py-2.5 text-right">
<button
type="button"
disabled={busy !== null}
onClick={() => stop(s.stream_id)}
className="bg-raised border border-line hover:brightness-110 disabled:opacity-50 text-ink-2 rounded-md px-2 py-0.5 text-xs"
>
{busy === s.stream_id ? "Stopping…" : "Stop"}
</button>
{(canControl || canRemove) && (
<td className="px-4 py-2.5 text-right whitespace-nowrap">
{canControl && (
<button
type="button"
disabled={busy !== null}
onClick={() => stop(s.stream_id)}
className="bg-raised border border-line hover:brightness-110 disabled:opacity-50 text-ink-2 rounded-md px-2 py-0.5 text-xs"
>
{busy === s.stream_id ? "Stopping…" : "Stop"}
</button>
)}
{canRemove && (
<button
type="button"
disabled={busy !== null}
onClick={() => remove(s)}
className="ml-1 bg-sev-major hover:brightness-110 disabled:opacity-50 text-white rounded-md px-2 py-0.5 text-xs"
>
{busy === `rm:${s.stream_id}` ? "Removing…" : "Remove"}
</button>
)}
</td>
)}
</tr>