Kerikim commited on
Commit
b1305d1
·
1 Parent(s): 3f81033

elkay: api.py

Browse files
Files changed (1) hide show
  1. utils/api.py +8 -17
utils/api.py CHANGED
@@ -93,15 +93,10 @@ def health():
93
  API_PREFIX_ENV = (os.getenv("BACKEND_API_PREFIX") or "").strip().rstrip("/")
94
 
95
  def _prefixes():
96
- # Try configured prefix first, then common fallbacks
97
- seen, out = set(), []
98
- for p in [API_PREFIX_ENV, "", "/api", "/v1", "/api/v1"]:
99
- p = (p or "").strip()
100
- p = "" if p == "" else ("/" + p.strip("/"))
101
- if p not in seen:
102
- out.append(p)
103
- seen.add(p)
104
- return out
105
 
106
  def _try_candidates(method: str, candidates: list[tuple[str, dict]]):
107
  """
@@ -631,8 +626,6 @@ def record_debt_dilemma_play(user_id: int, loans_cleared: int,
631
  }
632
  return _try_candidates("POST", [
633
  ("/games/debt_dilemma/record", {"json": payload}),
634
- ("/api/games/debt_dilemma/record", {"json": payload}),
635
- ("/api/v1/games/debt_dilemma/record", {"json": payload}),
636
  ])
637
 
638
 
@@ -656,11 +649,10 @@ def generate_quiz(*, lesson_id: int | None, level_slug: str | None, lesson_title
656
  }
657
 
658
  resp = _try_candidates("POST", [
659
- ("/quiz/auto", {"json": payload}),
660
- # optional alias if you add one later:
661
- ("/api/quiz/auto", {"json": payload}),
662
  ])
663
 
 
664
  # Normalize shapes: {"items":[...]} or just [...]
665
  if isinstance(resp, dict):
666
  return resp.get("items") or resp.get("quiz") or []
@@ -682,12 +674,11 @@ def submit_quiz(*, lesson_id: int | None, level_slug: str | None,
682
  }
683
 
684
  return _try_candidates("POST", [
685
- ("/quiz/grade", {"json": payload}),
686
- # optional alias if you add one later:
687
- ("/api/quiz/grade", {"json": payload}),
688
  ])
689
 
690
 
 
691
  def tutor_explain(lesson_id: int, level_slug: str, wrong: list[dict]):
692
  r = requests.post(f"{BACKEND}/tutor/explain", json={
693
  "lesson_id": lesson_id,
 
93
  API_PREFIX_ENV = (os.getenv("BACKEND_API_PREFIX") or "").strip().rstrip("/")
94
 
95
  def _prefixes():
96
+ """Try only the configured prefix (if any) and the bare root."""
97
+ if API_PREFIX_ENV:
98
+ return ["/" + API_PREFIX_ENV.strip("/"), ""]
99
+ return [""]
 
 
 
 
 
100
 
101
  def _try_candidates(method: str, candidates: list[tuple[str, dict]]):
102
  """
 
626
  }
627
  return _try_candidates("POST", [
628
  ("/games/debt_dilemma/record", {"json": payload}),
 
 
629
  ])
630
 
631
 
 
649
  }
650
 
651
  resp = _try_candidates("POST", [
652
+ ("/quiz/auto", {"json": payload}), # only this
 
 
653
  ])
654
 
655
+
656
  # Normalize shapes: {"items":[...]} or just [...]
657
  if isinstance(resp, dict):
658
  return resp.get("items") or resp.get("quiz") or []
 
674
  }
675
 
676
  return _try_candidates("POST", [
677
+ ("/quiz/grade", {"json": payload}), # only this
 
 
678
  ])
679
 
680
 
681
+
682
  def tutor_explain(lesson_id: int, level_slug: str, wrong: list[dict]):
683
  r = requests.post(f"{BACKEND}/tutor/explain", json={
684
  "lesson_id": lesson_id,