Reverting back to json for server side storage
This commit is contained in:
Binary file not shown.
11
main.py
11
main.py
@@ -85,16 +85,15 @@ async def sync_state_from_file(path: Path, kind: str):
|
|||||||
# -----------------------------
|
# -----------------------------
|
||||||
@app.post("/api/populate_friendly")
|
@app.post("/api/populate_friendly")
|
||||||
async def api_populate_friendly(data: FactionRequest):
|
async def api_populate_friendly(data: FactionRequest):
|
||||||
# call the Torn populater (should write data/friendly_faction.json)
|
|
||||||
await populate_friendly(data.faction_id)
|
await populate_friendly(data.faction_id)
|
||||||
# sync STATE from file
|
# 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}
|
return {"status": "friendly populated", "id": data.faction_id}
|
||||||
|
|
||||||
@app.post("/api/populate_enemy")
|
@app.post("/api/populate_enemy")
|
||||||
async def api_populate_enemy(data: FactionRequest):
|
async def api_populate_enemy(data: FactionRequest):
|
||||||
await populate_enemy(data.faction_id)
|
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}
|
return {"status": "enemy populated", "id": data.faction_id}
|
||||||
|
|
||||||
# -----------------------------
|
# -----------------------------
|
||||||
@@ -121,14 +120,14 @@ async def get_friendly_members():
|
|||||||
if STATE.friendly:
|
if STATE.friendly:
|
||||||
return [m.model_dump() for m in STATE.friendly.values()]
|
return [m.model_dump() for m in STATE.friendly.values()]
|
||||||
# fallback to file
|
# fallback to file
|
||||||
path = Path("data/friendly_faction.json")
|
path = Path("data/friendly_members.json")
|
||||||
return _load_json_list(path)
|
return _load_json_list(path)
|
||||||
|
|
||||||
@app.get("/api/enemy_members")
|
@app.get("/api/enemy_members")
|
||||||
async def get_enemy_members():
|
async def get_enemy_members():
|
||||||
if STATE.enemy:
|
if STATE.enemy:
|
||||||
return [m.model_dump() for m in STATE.enemy.values()]
|
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)
|
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
|
coll = STATE.friendly if kind == "friendly" else STATE.enemy
|
||||||
if member_id not in coll:
|
if member_id not in coll:
|
||||||
# Try to load members from file into STATE and re-check
|
# 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)
|
await sync_state_from_file(file_path, kind)
|
||||||
if member_id not in coll:
|
if member_id not in coll:
|
||||||
raise HTTPException(status_code=404, detail="member not found")
|
raise HTTPException(status_code=404, detail="member not found")
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user