Reverting back to json for server side storage

This commit is contained in:
2025-12-01 20:49:53 -05:00
parent 27d4a87249
commit c9808759f0
4 changed files with 5 additions and 6 deletions

Binary file not shown.

11
main.py
View File

@@ -85,16 +85,15 @@ async def sync_state_from_file(path: Path, kind: str):
# -----------------------------
@app.post("/api/populate_friendly")
async def api_populate_friendly(data: FactionRequest):
# call the Torn populater (should write data/friendly_faction.json)
await populate_friendly(data.faction_id)
# sync STATE from file
await sync_state_from_file(Path("data/friendly_faction.json"), "friendly")
await sync_state_from_file(Path("data/friendly_members.json"), "friendly")
return {"status": "friendly populated", "id": data.faction_id}
@app.post("/api/populate_enemy")
async def api_populate_enemy(data: FactionRequest):
await populate_enemy(data.faction_id)
await sync_state_from_file(Path("data/enemy_faction.json"), "enemy")
await sync_state_from_file(Path("data/enemy_memberes.json"), "enemy")
return {"status": "enemy populated", "id": data.faction_id}
# -----------------------------
@@ -121,14 +120,14 @@ async def get_friendly_members():
if STATE.friendly:
return [m.model_dump() for m in STATE.friendly.values()]
# fallback to file
path = Path("data/friendly_faction.json")
path = Path("data/friendly_members.json")
return _load_json_list(path)
@app.get("/api/enemy_members")
async def get_enemy_members():
if STATE.enemy:
return [m.model_dump() for m in STATE.enemy.values()]
path = Path("data/enemy_faction.json")
path = Path("data/enemy_members.json")
return _load_json_list(path)
# =============================
@@ -179,7 +178,7 @@ async def api_assign_member(req: AssignMemberRequest):
coll = STATE.friendly if kind == "friendly" else STATE.enemy
if member_id not in coll:
# Try to load members from file into STATE and re-check
file_path = Path("data/friendly_faction.json") if kind == "friendly" else Path("data/enemy_faction.json")
file_path = Path("data/friendly_members.json") if kind == "friendly" else Path("data/enemy_members.json")
await sync_state_from_file(file_path, kind)
if member_id not in coll:
raise HTTPException(status_code=404, detail="member not found")