refactor(onebot): move rkey fallback from per-UIN to a global config store

The rkey fallback endpoint is deployment infra (one self-hosted server serves
all accounts; fallback rkeys are fungible), so it doesn't belong in per-UIN
onebot_<uin>.json. Introduce config/snowluma.json — a generic home for small
all-accounts SnowLuma settings — and move rkey.fallbackServers there.

- New onebot/global-config.ts: load/save/normalize with section-merge + atomic
  write; http(s)+host URL validation; default [] (off). Lives in onebot (not
  core) because the onebot manager constructs instances and must not depend on
  core.
- OneBotInstance takes globalSettings; manager loads it on session start and
  exposes reloadGlobalSettings() to hot-push edits to every live instance via
  applyGlobalSettings → RKeyCache.setFallbackServers.
- Remove rkey from per-UIN OneBotConfig + the WebUI per-UIN round-trip (never
  released, so no migration). Register snowluma.json in the backup allowlist.

Reworks the per-UIN rkey from 12b0190. Phase 1 of the global-settings split.
This commit is contained in:
DrSmoothl committed 2026-06-28 20:52:07 +08:00
1 parent 5d39cf5782
commit 659970077a
12 files changed
+227 -78

No files matched your search

-33
View File
@@ -9,7 +9,6 @@ import type {
MessageFormat,
OneBotConfig,
OneBotNetworks,
RKeyConfig,
StatusCommandConfig,
WsClientNetwork,
WsRole,
@@ -65,7 +64,6 @@ export function makeDefaultOneBotConfig(): OneBotConfig {
musicSignUrl: '',
statusCommand: makeDefaultStatusCommand(),
notifications: { channelIds: [] },
rkey: { fallbackServers: [] },
};
}
@@ -125,7 +123,6 @@ function toJsonObject(config: OneBotConfig): JsonObject {
trigger: config.statusCommand.trigger,
},
notifications: { channelIds: config.notifications?.channelIds ?? [] },
rkey: { fallbackServers: config.rkey?.fallbackServers ?? [] },
};
}
@@ -214,39 +211,9 @@ function fromJson(sources: JsonObject[], freshInstall: boolean): OneBotConfig {
musicSignUrl,
statusCommand: parseStatusCommand(sources),
notifications: parseNotifications(sources),
rkey: parseRKeyConfig(sources),
};
}
/** Last-write-wins merge of `rkey.fallbackServers` across config sources. Only
* http(s) URLs are kept; the list is deduped. Default empty (feature off). */
function parseRKeyConfig(sources: JsonObject[]): RKeyConfig {
let fallbackServers: string[] = [];
for (const src of sources) {
const raw = src.rkey;
if (!isObject(raw)) continue;
if (Array.isArray(raw.fallbackServers)) {
fallbackServers = normalizeRkeyServers(raw.fallbackServers);
}
}
return { fallbackServers };
}
function normalizeRkeyServers(value: unknown): string[] {
if (!Array.isArray(value)) return [];
const seen = new Set<string>();
const out: string[] = [];
for (const item of value) {
if (typeof item !== 'string') continue;
const v = item.trim();
if (!v || !/^https?:\/\//i.test(v)) continue;
if (seen.has(v)) continue;
seen.add(v);
out.push(v);
}
return out;
}
/** Last-write-wins merge of `notifications.channelIds` across config sources,
* each id validated as a slug + deduped. Mirrors the channel-id rule in
* packages/core/src/notifications/config.ts (CHANNEL_ID_RE) — duplicated