28 lines
888 B
Python
28 lines
888 B
Python
|
|
import httpx
|
||
|
|
|
||
|
|
from yuxi.channel.extensions.tlon.auth import authenticate
|
||
|
|
|
||
|
|
|
||
|
|
async def probe_tlon_account(ship_url: str, code: str) -> dict:
|
||
|
|
try:
|
||
|
|
cookie = await authenticate(ship_url, code, timeout=30.0)
|
||
|
|
async with httpx.AsyncClient(base_url=ship_url, timeout=15.0) as client:
|
||
|
|
response = await client.get(
|
||
|
|
"/~/name",
|
||
|
|
headers={"Cookie": cookie},
|
||
|
|
)
|
||
|
|
response.raise_for_status()
|
||
|
|
return {"ok": True, "name": response.text.strip()}
|
||
|
|
except Exception as e:
|
||
|
|
return {"ok": False, "error": str(e)}
|
||
|
|
|
||
|
|
|
||
|
|
async def probe_tlon_config(account: dict) -> dict:
|
||
|
|
ship = account.get("ship")
|
||
|
|
url = account.get("url")
|
||
|
|
code = account.get("code")
|
||
|
|
|
||
|
|
if not all([ship, url, code]):
|
||
|
|
return {"ok": False, "error": "Missing ship/url/code"}
|
||
|
|
|
||
|
|
return await probe_tlon_account(url, code)
|