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
@@ -138,8 +138,12 @@ func TestGatewayHandshakeAndLogin(t *testing.T) {
|
||||
if cmdID != 4112 {
|
||||
t.Fatalf("unexpected GetUnreleasedBlockInfoScRsp id: got %d want 4112", cmdID)
|
||||
}
|
||||
if len(body) != 2 || body[0] != 0x70 || body[1] != 0x00 {
|
||||
t.Fatalf("unexpected UnreleasedBlockInfo body: %x", body)
|
||||
blockRsp := &goproto.GetUnreleasedBlockInfoScRsp{}
|
||||
if err := proto.Unmarshal(body, blockRsp); err != nil {
|
||||
t.Fatalf("unmarshal GetUnreleasedBlockInfo: %v", err)
|
||||
}
|
||||
if blockRsp.Retcode != 0 {
|
||||
t.Fatalf("unexpected UnreleasedBlockInfo retcode: %d", blockRsp.Retcode)
|
||||
}
|
||||
t.Log("GetUnreleasedBlockInfo verified: 4190 -> 4112 retcode 0")
|
||||
|
||||
|
||||
@@ -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