vivekchakraverty commited on
Commit
822d3cc
·
verified ·
1 Parent(s): 4cf533e

Enforce monthly request cap (12000/mo plan) via RapidAPI quota headers; optional MONTHLY_DOWNLOAD_LIMIT self-cap; show quota in health check

Browse files
Files changed (1) hide show
  1. app.py +7 -0
app.py CHANGED
@@ -147,6 +147,13 @@ def check_access():
147
  if r.status_code == 200:
148
  api_ok = True
149
  lines.append("- ✅ Download API reachable and key valid (HTTP 200)")
 
 
 
 
 
 
 
150
  elif r.status_code in (401, 403):
151
  api_ok = False
152
  lines.append(f"- ❌ Download API rejected the key (HTTP {r.status_code}) — "
 
147
  if r.status_code == 200:
148
  api_ok = True
149
  lines.append("- ✅ Download API reachable and key valid (HTTP 200)")
150
+ downloader_mod._update_quota(r.headers) # prime the monthly-cap tracker
151
+ q = downloader_mod.quota_status()
152
+ if q.get("limit") is not None and q.get("remaining") is not None:
153
+ days = (q["reset"] // 86400) if q.get("reset") else "?"
154
+ cap = f" · self-cap {q['self_cap']}" if q.get("self_cap") else ""
155
+ lines.append(f"- 📊 Monthly requests: **{q['remaining']} / {q['limit']} left** "
156
+ f"({q.get('used', 0)} used, resets in ~{days} days){cap}")
157
  elif r.status_code in (401, 403):
158
  api_ok = False
159
  lines.append(f"- ❌ Download API rejected the key (HTTP {r.status_code}) — "