feat: safely merge partial persistent updates and update hide ui script
This commit is contained in:
1 parent
332171cafb
commit
83fa8c7d44
3 files changed
+115
-56
No files matched your search
@@ -312,7 +312,16 @@ func apiPersistentData(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
out, _ := json.MarshalIndent(parsed, "", " ")
|
||||
// Merge into existing persistent file so partial updates (e.g. lineups or switches) preserve other settings
|
||||
existing := make(map[string]any)
|
||||
if raw, err := os.ReadFile("persistent"); err == nil {
|
||||
_ = json.Unmarshal(raw, &existing)
|
||||
}
|
||||
for k, v := range parsed {
|
||||
existing[k] = v
|
||||
}
|
||||
|
||||
out, _ := json.MarshalIndent(existing, "", " ")
|
||||
if err := os.WriteFile("persistent", out, 0o644); err != nil {
|
||||
writeJSON(w, map[string]any{"error": "failed to write persistent: " + err.Error(), "status": 500})
|
||||
return
|
||||
|
||||
Reference in new issue
Block a user