Update GaCy-GO
This commit is contained in:
1 parent
da8a32f60d
commit
0cbe460e49
345 files changed
+98202
-77559
No files matched your search
+10
-45
@@ -49,6 +49,10 @@ func registerAPIRoutes(mux *http.ServeMux) {
|
||||
mux.HandleFunc("/api/tool-session", corsWrapper(apiToolSession))
|
||||
mux.HandleFunc("/api/status", corsWrapper(apiStatus))
|
||||
mux.HandleFunc("/api/technique", corsWrapper(apiTechnique))
|
||||
mux.HandleFunc("/api/aha-help", corsWrapper(apiAhaHelp))
|
||||
mux.HandleFunc("/api/camera", corsWrapper(apiCamera))
|
||||
mux.HandleFunc("/api/monster-settings/catalog", corsWrapper(apiMonsterSettingsCatalog))
|
||||
mux.HandleFunc("/api/monster-settings/aa-round", corsWrapper(apiAARoundSelection))
|
||||
mux.HandleFunc("/api/freesr", corsWrapper(apiFreesrData))
|
||||
mux.HandleFunc("/api/inventory/materials", corsWrapper(apiInventoryMaterials))
|
||||
mux.HandleFunc("/api/freesr/avatars", corsWrapper(apiFreesrAvatars))
|
||||
@@ -318,45 +322,16 @@ func apiInventoryMaterials(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
seen[update.ItemID] = struct{}{}
|
||||
}
|
||||
materials, err := readInventory()
|
||||
if err != nil {
|
||||
writeInventoryError(w, http.StatusInternalServerError, "failed to read inventory: "+err.Error())
|
||||
return
|
||||
}
|
||||
updates := make(map[uint32]*uint32, len(req.Updates))
|
||||
for _, update := range req.Updates {
|
||||
key := strconv.FormatUint(uint64(update.ItemID), 10)
|
||||
if update.Reset {
|
||||
delete(materials, key)
|
||||
updates[update.ItemID] = nil
|
||||
} else {
|
||||
materials[key] = *update.Count
|
||||
updates[update.ItemID] = update.Count
|
||||
}
|
||||
}
|
||||
raw, err := os.ReadFile("freesr-data.json")
|
||||
materials, err := common.PatchMaterialOverrides(updates)
|
||||
if err != nil {
|
||||
writeInventoryError(w, http.StatusInternalServerError, "failed to read freesr-data.json: "+err.Error())
|
||||
return
|
||||
}
|
||||
var data map[string]json.RawMessage
|
||||
if err := json.Unmarshal(raw, &data); err != nil {
|
||||
writeInventoryError(w, http.StatusInternalServerError, "freesr-data.json is invalid: "+err.Error())
|
||||
return
|
||||
}
|
||||
if data == nil {
|
||||
writeInventoryError(w, http.StatusInternalServerError, "freesr-data.json must contain a JSON object")
|
||||
return
|
||||
}
|
||||
materialJSON, err := json.Marshal(materials)
|
||||
if err != nil {
|
||||
writeInventoryError(w, http.StatusInternalServerError, "failed to encode inventory: "+err.Error())
|
||||
return
|
||||
}
|
||||
data["materials"] = materialJSON
|
||||
output, err := json.MarshalIndent(data, "", " ")
|
||||
if err != nil {
|
||||
writeInventoryError(w, http.StatusInternalServerError, "failed to encode freesr-data.json: "+err.Error())
|
||||
return
|
||||
}
|
||||
if err := os.WriteFile("freesr-data.json", output, 0o644); err != nil {
|
||||
writeInventoryError(w, http.StatusInternalServerError, "failed to save inventory: "+err.Error())
|
||||
return
|
||||
}
|
||||
@@ -482,23 +457,13 @@ func apiPersistentData(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
var parsed map[string]any
|
||||
var parsed map[string]json.RawMessage
|
||||
if err := json.Unmarshal(body, &parsed); err != nil {
|
||||
writeJSON(w, map[string]any{"error": "invalid json: " + err.Error(), "status": 400})
|
||||
return
|
||||
}
|
||||
|
||||
// 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 {
|
||||
if err := common.PatchPersistentFields(parsed); err != nil {
|
||||
writeJSON(w, map[string]any{"error": "failed to write persistent: " + err.Error(), "status": 500})
|
||||
return
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user