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:
12 files changed
+227
-78
No files matched your search
@@ -269,4 +269,30 @@ describe('RKeyCache remote fallback (#156)', () => {
|
||||
|
||||
expect(url).toBe(NT_IMAGE_URL);
|
||||
});
|
||||
|
||||
// Hot-reload wire: manager.reloadGlobalSettings → instance.applyGlobalSettings
|
||||
// → rkeyCache.setFallbackServers. Verify the new list actually takes effect.
|
||||
// (Fake Date so the 2nd lookup clears the empty-cache refresh cooldown.)
|
||||
it('setFallbackServers turns the fallback on for a cache that started with none', async () => {
|
||||
vi.useFakeTimers({ toFake: ['Date'] });
|
||||
try {
|
||||
vi.setSystemTime(new Date(1_700_000_000_000));
|
||||
const fetchSpy = stubFetch({ group_rkey: '&rkey=HOTGROUP', expired_time: 1_700_000_000 + 3600 });
|
||||
const { bridge } = makeBridge(async () => []);
|
||||
const cache = new RKeyCache(); // starts OFF (no servers)
|
||||
|
||||
const before = await cache.resolveImageUrl(bridge as never, imageEl(), true);
|
||||
expect(before).toBe(NT_IMAGE_URL); // bare — fallback off
|
||||
expect(fetchSpy).not.toHaveBeenCalled();
|
||||
|
||||
cache.setFallbackServers([SERVER]); // hot-reload pushes a new endpoint
|
||||
vi.setSystemTime(new Date(1_700_000_000_000 + 11_000)); // clear the 10s empty-cooldown
|
||||
|
||||
const after = await cache.resolveImageUrl(bridge as never, imageEl(), true);
|
||||
expect(after).toBe(`${NT_IMAGE_URL}&rkey=HOTGROUP`);
|
||||
expect(fetchSpy).toHaveBeenCalledWith(SERVER, expect.anything());
|
||||
} finally {
|
||||
vi.useRealTimers();
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user