Refactor OneBot networks and event dispatch
Unify per-adapter network configuration into a single `networks` structure and add migration/normalization for legacy on-disk formats. Introduce per-adapter options (messageFormat, reportSelfMessage, enabled, name) and stronger typing in types.ts. Add event-filter utilities to prebuild two serialized payload variants and pick the right one per adapter to avoid repeated JSON.stringify calls. Update HTTP/WS transports to use adapter names/signatures for hot-reload, respect per-adapter options, and improve logging; WS transport also improves client/server lifecycle/reconnect handling. Mark self-sent messages as `message_sent` in the event converter and wire instance dispatch to use the new DispatchPayload. Misc: README edits and accompanying tests added/updated for the refactor.
This commit is contained in:
1 parent
19a564991c
commit
2a4ca46a99
14 files changed
+1732
-758
No files matched your search
@@ -175,11 +175,22 @@ function AppInner() {
|
||||
const data = await res.json();
|
||||
const loaded = data?.config ?? data;
|
||||
if (cancelled) return;
|
||||
const nets = loaded?.networks ?? {};
|
||||
const legacyFormat = loaded?.messageFormat === 'string' ? 'string' : 'array';
|
||||
const legacyReport = !!loaded?.reportSelfMessage;
|
||||
const normalizeNetwork = <T extends Record<string, unknown>>(item: T) => ({
|
||||
...item,
|
||||
messageFormat: item.messageFormat === 'string' ? 'string' : legacyFormat,
|
||||
reportSelfMessage:
|
||||
typeof item.reportSelfMessage === 'boolean' ? item.reportSelfMessage : legacyReport,
|
||||
});
|
||||
setConfig({
|
||||
httpServers: loaded?.httpServers || [],
|
||||
httpPostEndpoints: loaded?.httpPostEndpoints || [],
|
||||
wsServers: loaded?.wsServers || [],
|
||||
wsClients: loaded?.wsClients || [],
|
||||
networks: {
|
||||
httpServers: Array.isArray(nets.httpServers) ? nets.httpServers.map(normalizeNetwork) : [],
|
||||
httpClients: Array.isArray(nets.httpClients) ? nets.httpClients.map(normalizeNetwork) : [],
|
||||
wsServers: Array.isArray(nets.wsServers) ? nets.wsServers.map(normalizeNetwork) : [],
|
||||
wsClients: Array.isArray(nets.wsClients) ? nets.wsClients.map(normalizeNetwork) : [],
|
||||
},
|
||||
musicSignUrl: loaded?.musicSignUrl,
|
||||
});
|
||||
} catch (e) {
|
||||
|
||||
Reference in new issue
Block a user