feat: 综合平台services多服务支持+SW网络优先缓存修复+适配层/定时任务完善
This commit is contained in:
+35
-5
@@ -100,11 +100,41 @@ class OpenAIAdapter(_AIBase):
|
||||
|
||||
@register("minimax-api")
|
||||
class MinimaxAdapter(_AIBase):
|
||||
# Minimax 需 group_id,余额接口因账号类型而异,此处为骨架待完善
|
||||
required_config = ["api_key", "group_id"]
|
||||
"""Minimax 适配器(余额查询)
|
||||
|
||||
接口:GET https://api.minimax.chat/v1/balance
|
||||
认证:Bearer api_key(group_id 仅部分旧接口需要,余额查询非必需)
|
||||
响应示例:{"balance": 123.45, "currency": "CNY", ...}
|
||||
注:Minimax 国内版端点为 api.minimaxi.com,国际版为 api.minimax.chat,
|
||||
两者 API Key 不通用;默认使用国际版端点,可通过 config["base_url"] 覆盖。
|
||||
"""
|
||||
|
||||
required_config = ["api_key"]
|
||||
BASE = "https://api.minimax.chat/v1"
|
||||
|
||||
def _base_url(self) -> str:
|
||||
return (self.config.get("base_url") or self.BASE).rstrip("/")
|
||||
|
||||
def _balance(self) -> AccountInfo:
|
||||
data = self._get(self._base_url() + "/balance")
|
||||
balance = data.get("balance")
|
||||
try:
|
||||
balance = float(balance) if balance is not None else None
|
||||
except (TypeError, ValueError):
|
||||
balance = None
|
||||
currency = data.get("currency") or "CNY"
|
||||
return AccountInfo(balance=balance, currency=currency, raw=data)
|
||||
|
||||
def test_connection(self) -> dict:
|
||||
if not self.config.get("group_id"):
|
||||
return {"ok": False, "message": "Minimax 需配置 group_id(适配器余额接口待完善)"}
|
||||
return {"ok": False, "message": "Minimax 适配器余额接口待完善(请提供具体接口文档)"}
|
||||
try:
|
||||
acc = self._balance()
|
||||
if acc.balance is not None:
|
||||
return {"ok": True, "message": f"连接成功,余额 {acc.balance} {acc.currency}"}
|
||||
return {"ok": True, "message": "连接成功(未返回余额字段)"}
|
||||
except httpx.HTTPStatusError as e:
|
||||
return self._http_error(e)
|
||||
except Exception as e: # noqa: BLE001
|
||||
return {"ok": False, "message": str(e)}
|
||||
|
||||
def get_account(self) -> AccountInfo:
|
||||
return self._balance()
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
"""Cloudflare 适配器(REST API v4,Bearer Token)
|
||||
|
||||
API 文档:https://developers.cloudflare.com/api/
|
||||
所需配置:{"api_token": "..."}(建议用 API Token,权限含 Zone:Read / Account:Read)
|
||||
所需配置:{"api_token": "..."}(建议用 API Token,权限含 Zone:Read / Account:Read / Registrar:Read)
|
||||
Cloudflare 无传统 VPS,主要同步托管域名(zones);Workers/R2/Tunnel 子资产留待后续阶段。
|
||||
域名到期日通过 Registrar API(/accounts/{id}/registrar/domains)补充获取。
|
||||
"""
|
||||
|
||||
import httpx
|
||||
@@ -42,16 +43,21 @@ class CloudflareAdapter(BaseAdapter):
|
||||
return {"ok": False, "message": str(e)}
|
||||
|
||||
def list_domains(self) -> list:
|
||||
# 先拉取 Registrar 域名到期日映射(domain_name -> expires_at ISO 日期)
|
||||
expiry_map = self._registrar_expiry_map()
|
||||
|
||||
result = []
|
||||
page = 1
|
||||
while True:
|
||||
data = self._get(f"/zones?per_page=50&page={page}")
|
||||
for z in data.get("result", []):
|
||||
name = z.get("name")
|
||||
result.append(
|
||||
NormalizedDomain(
|
||||
external_id=z.get("id"),
|
||||
domain_name=z.get("name"),
|
||||
domain_name=name,
|
||||
registrar="cloudflare",
|
||||
expiry_date=expiry_map.get(name),
|
||||
status="active" if z.get("status") == "active" else (z.get("status") or "unknown"),
|
||||
raw=z,
|
||||
)
|
||||
@@ -61,3 +67,31 @@ class CloudflareAdapter(BaseAdapter):
|
||||
break
|
||||
page += 1
|
||||
return result
|
||||
|
||||
def _registrar_expiry_map(self) -> dict:
|
||||
"""拉取 Cloudflare Registrar 域名到期日映射 {domain_name: YYYY-MM-DD}
|
||||
|
||||
流程:/accounts → 对每个 account 调 /accounts/{id}/registrar/domains。
|
||||
若 Token 无 Registrar 权限或账号无 Registrar 域名,静默返回空映射。
|
||||
"""
|
||||
expiry = {}
|
||||
try:
|
||||
accounts = self._get("/accounts?per_page=50").get("result", [])
|
||||
except Exception: # noqa: BLE001
|
||||
return expiry
|
||||
for acc in accounts:
|
||||
acc_id = acc.get("id")
|
||||
if not acc_id:
|
||||
continue
|
||||
try:
|
||||
domains = self._get(f"/accounts/{acc_id}/registrar/domains").get("result", [])
|
||||
except Exception: # noqa: BLE001
|
||||
continue
|
||||
for d in domains:
|
||||
# Registrar API 返回的 id 是域名本身(如 example.com)
|
||||
name = d.get("id") or d.get("domain_name") or ""
|
||||
expires_at = d.get("expires_at")
|
||||
if name and expires_at:
|
||||
# expires_at 为 ISO8601 时间戳,截取日期部分
|
||||
expiry[name] = expires_at[:10]
|
||||
return expiry
|
||||
|
||||
Reference in New Issue
Block a user