- c2-core routers/discord_web.py:
PUT /discord/guilds/{id}/directory (service key): the server bot pushes each
server's name + voice channels; merged onto discord_guilds, never touches org_id.
GET /discord/nodes/{id}/join-options: the node org's servers (same
resolve rule as the bot), their voice channels with any live stream,
radio-bot readiness + invite links, and this node's streams. No tokens.
POST /discord/nodes/{id}/streams: stream pinned to the node; server must be
the node org's, channel must be in the bot's directory, guild + node caps.
POST /discord/nodes/{id}/streams/stop: one stream on this node, or all.
Control = platform admin, org owner, or operator owning the node.
- nodes.py: legacy raw-ID discord_join now refuses a server outside the node's org.
- discord bot: DirectorySync cog pushes on ready (15-min loop), join/leave,
rename, voice/category channel changes (debounced).
- frontend: NodeDiscordRadio panel + picker replaces DiscordJoinModal and the
admin-only Join/Leave buttons.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
91 lines
2.5 KiB
TypeScript
91 lines
2.5 KiB
TypeScript
// Node-page Discord picker (server-26#213 item 3, #109 item 13).
|
|
// Shapes returned by c2-core app/routers/discord_web.py. No token strings —
|
|
// the server never sends them to the browser.
|
|
|
|
export type StreamState =
|
|
| "pending"
|
|
| "connecting"
|
|
| "connected"
|
|
| "error"
|
|
| "stopping"
|
|
| "stopped"
|
|
| "node_offline"
|
|
| "paused_locally";
|
|
|
|
export interface DiscordStreamView {
|
|
stream_id: string;
|
|
guild_id: string;
|
|
channel_id: string;
|
|
guild_name: string | null;
|
|
channel_name: string | null;
|
|
system_name: string | null;
|
|
mode: "persistent" | "adhoc" | null;
|
|
node_id: string | null;
|
|
node_name: string | null;
|
|
actual: { state: StreamState; error: string | null; since?: string; at?: string } | null;
|
|
updated_at: string | null;
|
|
}
|
|
|
|
export interface DiscordInvite {
|
|
name: string;
|
|
invite_url: string;
|
|
}
|
|
|
|
export interface DiscordVoiceChannel {
|
|
channel_id: string;
|
|
name: string;
|
|
category: string | null;
|
|
stream: DiscordStreamView | null;
|
|
}
|
|
|
|
export interface DiscordGuildOption {
|
|
guild_id: string;
|
|
name: string | null;
|
|
linked: boolean;
|
|
synced: boolean;
|
|
synced_at: string | null;
|
|
voice_channels: DiscordVoiceChannel[];
|
|
streams_on: number;
|
|
bot: { ok: boolean; code: string | null; message: string | null; invite: DiscordInvite[] };
|
|
}
|
|
|
|
export interface DiscordJoinOptions {
|
|
node_id: string;
|
|
node_name: string | null;
|
|
node_online: boolean;
|
|
system_id: string | null;
|
|
system_name: string | null;
|
|
can_control: boolean;
|
|
limits: { node_max: number; node_used: number; guild_max: number };
|
|
guilds: DiscordGuildOption[];
|
|
streams: DiscordStreamView[];
|
|
}
|
|
|
|
export interface DiscordStartResult {
|
|
ok: boolean;
|
|
stream_id: string;
|
|
token_id: string | null;
|
|
delivered: boolean | null;
|
|
reused: boolean | null;
|
|
}
|
|
|
|
/** c2api's request() throws `C2 API error <status>: <body>`. Pull the
|
|
* detail + invite links back out of a JSON body when there is one. */
|
|
export function parseC2Error(err: unknown): { message: string; invite: DiscordInvite[] } {
|
|
const raw = err instanceof Error ? err.message : String(err);
|
|
const idx = raw.indexOf(": ");
|
|
if (idx >= 0) {
|
|
try {
|
|
const body = JSON.parse(raw.slice(idx + 2));
|
|
const detail = typeof body?.detail === "string" ? body.detail : null;
|
|
const invite = Array.isArray(body?.invite)
|
|
? (body.invite as DiscordInvite[]).filter((i) => i && typeof i.invite_url === "string")
|
|
: [];
|
|
if (detail) return { message: detail, invite };
|
|
} catch {
|
|
/* not JSON — fall through */
|
|
}
|
|
}
|
|
return { message: raw, invite: [] };
|
|
}
|