feat(webui): show saved and applied config state
Surface whether a OneBot configuration was persisted, applied live, or left degraded. Keep failed adapters and apply errors visible in the config and overview pages instead of reporting a false success.
This commit is contained in:
7 files changed
+145
-24
No files matched your search
@@ -86,14 +86,49 @@ class HttpApiClient implements ApiClient {
|
||||
},
|
||||
save: async (uin, config) => {
|
||||
const url = `/api/config/${encodeURIComponent(uin)}`;
|
||||
// POST returns { success, reloaded, message } — no config body. To
|
||||
// honour the "save returns canonical server view" contract, refetch
|
||||
// after a successful POST.
|
||||
await this.fetchJson<unknown>(url, {
|
||||
const result = await this.fetchJson<{
|
||||
success?: boolean;
|
||||
saved?: boolean;
|
||||
applied?: boolean;
|
||||
online?: boolean;
|
||||
reloaded?: boolean;
|
||||
errors?: Array<{
|
||||
name: string;
|
||||
kind?: 'httpServer' | 'httpClient' | 'wsServer' | 'wsClient';
|
||||
phase: string;
|
||||
message: string;
|
||||
at: number;
|
||||
restored?: boolean;
|
||||
}>;
|
||||
config?: unknown;
|
||||
message?: string;
|
||||
}>(url, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(config),
|
||||
});
|
||||
return this.config.get(uin);
|
||||
// Refetch the canonical persisted view after the save. Runtime apply
|
||||
// is a separate fact and is preserved alongside that config.
|
||||
let canonical = result.config === undefined
|
||||
? null
|
||||
: normalizeOneBotConfig(result.config);
|
||||
if (canonical === null) {
|
||||
try {
|
||||
canonical = await this.config.get(uin);
|
||||
} catch (error) {
|
||||
// Legacy servers omit `config`. Their POST still confirmed the
|
||||
// save, so a follow-up GET failure must not become "保存失败".
|
||||
console.warn('config saved but canonical refetch failed', error);
|
||||
canonical = config;
|
||||
}
|
||||
}
|
||||
return {
|
||||
config: canonical,
|
||||
saved: result.saved ?? result.success === true,
|
||||
applied: result.applied ?? result.reloaded === true,
|
||||
online: result.online ?? result.reloaded === true,
|
||||
errors: Array.isArray(result.errors) ? result.errors : [],
|
||||
message: result.message ?? '配置保存成功',
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -69,6 +69,24 @@ export type ProcessActionResult = {
|
||||
process?: HookProcessInfo & { error?: string };
|
||||
};
|
||||
|
||||
export interface ConfigApplyError {
|
||||
name: string;
|
||||
kind?: 'httpServer' | 'httpClient' | 'wsServer' | 'wsClient';
|
||||
phase: string;
|
||||
message: string;
|
||||
at: number;
|
||||
restored?: boolean;
|
||||
}
|
||||
|
||||
export interface ConfigSaveResult {
|
||||
config: OneBotConfig;
|
||||
saved: boolean;
|
||||
applied: boolean;
|
||||
online: boolean;
|
||||
errors: ConfigApplyError[];
|
||||
message: string;
|
||||
}
|
||||
|
||||
export type StreamStatus = 'open' | 'reconnecting' | 'closed';
|
||||
|
||||
export interface LogsStreamOptions {
|
||||
@@ -134,7 +152,7 @@ export interface ApiClient {
|
||||
// ---- OneBotInstance per-UIN config ----
|
||||
config: {
|
||||
get(uin: string): Promise<OneBotConfig>;
|
||||
save(uin: string, config: OneBotConfig): Promise<OneBotConfig>;
|
||||
save(uin: string, config: OneBotConfig): Promise<ConfigSaveResult>;
|
||||
};
|
||||
|
||||
// ---- WebUI listener self-config (port / host / TLS / trust-proxy) ----
|
||||
|
||||
Reference in new issue
Block a user