feat(common): updateRuntimeConfig(patch) for the WebUI settings panel

Persist a partial RuntimeConfig update, merging onto the on-disk config (not
the env-merged view) so an env override is never baked into runtime.json.
Tested: patch merge + the env-not-persisted invariant (chdir to a temp cwd).
This commit is contained in:
DrSmoothl committed 2026-06-18 14:28:31 +08:00
1 parent ad21e19dc8
commit 9a455b30c6
2 files changed
+55 -1

No files matched your search

+13
View File
@@ -77,6 +77,19 @@ export function loadRuntimeConfig(): RuntimeConfig {
return { ...normalized, ...resolveRuntimeEnvOverrides(process.env) };
}
/**
* Persist a partial update. Merges onto the ON-DISK config (not the env-merged
* runtime view) so an env override (e.g. SNOWLUMA_WEBUI_PORT) is never baked
* into runtime.json. Returns the new persisted config (without env overrides).
*/
export function updateRuntimeConfig(patch: Partial<RuntimeConfig>): RuntimeConfig {
fs.mkdirSync(CONFIG_DIR, { recursive: true });
const onDisk = normalizeRuntimeConfig(tryLoadRuntimeConfig() ?? {});
const next = normalizeRuntimeConfig({ ...onDisk, ...patch });
saveRuntimeConfig(next);
return next;
}
function tryLoadRuntimeConfig(): Record<string, unknown> | null {
if (!fs.existsSync(RUNTIME_CONFIG_PATH)) return null;
try {