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

+9 -2
View File
@@ -7,6 +7,7 @@ import type { ConverterContext } from './event-converter';
import { registerEventPipeline } from './event-pipeline';
import { buildApiContext, type OneBotInstanceContext } from './instance-context';
import { RKeyCache } from './instance-rkey';
import type { GlobalSettings } from './global-config';
import { MediaIndexer } from './media-indexer';
import { MediaStore } from './media-store';
import { MediaUrlResolver } from './media-url-resolver';
@@ -73,7 +74,7 @@ export class OneBotInstance {
return this.apiHandler.handle(action, params);
}
constructor(uin: string, bridge: BridgeInterface, config: OneBotConfig) {
constructor(uin: string, bridge: BridgeInterface, config: OneBotConfig, globalSettings: GlobalSettings) {
this.uin = uin;
this.bridge = bridge;
const uinNum = Number.parseInt(uin, 10);
@@ -81,7 +82,7 @@ export class OneBotInstance {
? moduleLog.child({ uin: uinNum })
: moduleLog;
this.rkeyCache = new RKeyCache(config.rkey);
this.rkeyCache = new RKeyCache(globalSettings.rkey);
this.mediaStore = new MediaStore(path.join('data', this.uin, 'media.db'));
this.messageStore = new MessageStore(path.join('data', this.uin, 'messages.json'));
this.reactionStore = new ReactionStore(path.join('data', this.uin, 'reactions.db'));
@@ -134,6 +135,12 @@ export class OneBotInstance {
});
}
/** Apply edited global (all-accounts) settings without a restart. Called by
* the manager when config/snowluma.json is saved from the WebUI. */
applyGlobalSettings(globalSettings: GlobalSettings): void {
this.rkeyCache.setFallbackServers(globalSettings.rkey.fallbackServers);
}
dispose(): void {
this.online = false;
this.stopHeartbeat();