Spaces:
Runtime error
Runtime error
Update bot/integrations/cf_worker1.py
Browse files
bot/integrations/cf_worker1.py
CHANGED
|
@@ -1,4 +1,6 @@
|
|
| 1 |
# PATH: bot/integrations/cf_worker1.py
|
|
|
|
|
|
|
| 2 |
from bot.config import Workers
|
| 3 |
from bot.integrations.http import post_json
|
| 4 |
|
|
@@ -19,7 +21,6 @@ def _unwrap(r: dict) -> dict:
|
|
| 19 |
"""
|
| 20 |
if isinstance(r, dict) and isinstance(r.get("data"), dict):
|
| 21 |
data = r["data"]
|
| 22 |
-
# keep fallback ok/status for debugging if you want
|
| 23 |
if "ok" not in data and "ok" in r:
|
| 24 |
data["ok"] = r["ok"]
|
| 25 |
return data
|
|
@@ -47,6 +48,7 @@ async def profile_add(
|
|
| 47 |
return _unwrap(r)
|
| 48 |
|
| 49 |
|
|
|
|
| 50 |
async def profile_list(tg_id: int) -> dict:
|
| 51 |
r = await post_json(
|
| 52 |
f"{Workers.WORKER1_URL}/api/profile/list",
|
|
@@ -56,10 +58,31 @@ async def profile_list(tg_id: int) -> dict:
|
|
| 56 |
return _unwrap(r)
|
| 57 |
|
| 58 |
|
|
|
|
| 59 |
async def profile_set_default(tg_id: int, profile_id: str) -> dict:
|
| 60 |
r = await post_json(
|
| 61 |
f"{Workers.WORKER1_URL}/api/profile/set_default",
|
| 62 |
_h(),
|
| 63 |
{"tg_id": str(tg_id), "profile_id": profile_id},
|
| 64 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
return _unwrap(r)
|
|
|
|
| 1 |
# PATH: bot/integrations/cf_worker1.py
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
from bot.config import Workers
|
| 5 |
from bot.integrations.http import post_json
|
| 6 |
|
|
|
|
| 21 |
"""
|
| 22 |
if isinstance(r, dict) and isinstance(r.get("data"), dict):
|
| 23 |
data = r["data"]
|
|
|
|
| 24 |
if "ok" not in data and "ok" in r:
|
| 25 |
data["ok"] = r["ok"]
|
| 26 |
return data
|
|
|
|
| 48 |
return _unwrap(r)
|
| 49 |
|
| 50 |
|
| 51 |
+
# existing (kept)
|
| 52 |
async def profile_list(tg_id: int) -> dict:
|
| 53 |
r = await post_json(
|
| 54 |
f"{Workers.WORKER1_URL}/api/profile/list",
|
|
|
|
| 58 |
return _unwrap(r)
|
| 59 |
|
| 60 |
|
| 61 |
+
# existing (kept)
|
| 62 |
async def profile_set_default(tg_id: int, profile_id: str) -> dict:
|
| 63 |
r = await post_json(
|
| 64 |
f"{Workers.WORKER1_URL}/api/profile/set_default",
|
| 65 |
_h(),
|
| 66 |
{"tg_id": str(tg_id), "profile_id": profile_id},
|
| 67 |
)
|
| 68 |
+
return _unwrap(r)
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
# ✅ Added: handlers.py expects this name
|
| 72 |
+
async def profile_check_auth(tg_id: int, profile_id: str, ttl_sec: int = 600, force: bool = False) -> dict:
|
| 73 |
+
r = await post_json(
|
| 74 |
+
f"{Workers.WORKER1_URL}/api/profile/login_link",
|
| 75 |
+
_h(),
|
| 76 |
+
{"tg_id": str(tg_id), "profile_id": str(profile_id), "ttl_sec": int(ttl_sec), "force": bool(force)},
|
| 77 |
+
)
|
| 78 |
+
return _unwrap(r)
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
# ✅ Added: handlers.py expects this name
|
| 82 |
+
async def profile_delete(tg_id: int, profile_id: str) -> dict:
|
| 83 |
+
r = await post_json(
|
| 84 |
+
f"{Workers.WORKER1_URL}/api/profile/remove",
|
| 85 |
+
_h(),
|
| 86 |
+
{"tg_id": str(tg_id), "profile_id": str(profile_id)},
|
| 87 |
+
)
|
| 88 |
return _unwrap(r)
|