chore: auto release commit (2026-05-30 19:51:46)
All checks were successful
技能自动化发布 / release (push) Successful in 5s
All checks were successful
技能自动化发布 / release (push) Successful in 5s
This commit is contained in:
@@ -42,6 +42,7 @@ from db.accounts_repo import (
|
||||
update_account_last_used,
|
||||
update_account_session_status,
|
||||
update_credential_last_used,
|
||||
upsert_platform,
|
||||
)
|
||||
from db.auth_strategy import (
|
||||
ALL_AUTH_STRATEGIES,
|
||||
@@ -190,15 +191,49 @@ def _remove_profile_dir(path: str) -> None:
|
||||
|
||||
def _resolve_or_fail(input_name: str, hint: str = "") -> Optional[str]:
|
||||
"""Resolve platform key or print ERROR:INVALID_PLATFORM and return None."""
|
||||
key = resolve_platform_key((input_name or "").strip())
|
||||
if not key:
|
||||
_say(f"ERROR:INVALID_PLATFORM 无法识别的平台「{input_name}」。")
|
||||
if hint:
|
||||
_say(hint)
|
||||
else:
|
||||
_say("支持:" + _platform_list_cn_for_help())
|
||||
raw = (input_name or "").strip()
|
||||
if not raw:
|
||||
_say("ERROR:INVALID_PLATFORM 平台名不能为空。")
|
||||
return None
|
||||
return key
|
||||
|
||||
# 先尝试 platforms.py 硬编码(兼容历史)
|
||||
key = resolve_platform_key(raw)
|
||||
if key:
|
||||
return key
|
||||
|
||||
# 再查 DB(支持动态注册的平台)
|
||||
try:
|
||||
init_db()
|
||||
conn = get_conn()
|
||||
try:
|
||||
row = conn.execute(
|
||||
"SELECT platform_key FROM platforms WHERE platform_key = ? AND enabled = 1",
|
||||
(raw,),
|
||||
).fetchone()
|
||||
if row:
|
||||
return row[0]
|
||||
rows = conn.execute(
|
||||
"SELECT platform_key, aliases_json FROM platforms WHERE enabled = 1"
|
||||
).fetchall()
|
||||
raw_lower = raw.lower()
|
||||
for r in rows:
|
||||
try:
|
||||
aliases = json.loads(r[1] or "[]")
|
||||
if raw_lower in [str(a).lower() for a in aliases]:
|
||||
return r[0]
|
||||
except Exception:
|
||||
continue
|
||||
finally:
|
||||
conn.close()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
_say(f"ERROR:INVALID_PLATFORM 无法识别的平台「{input_name}」。")
|
||||
if hint:
|
||||
_say(hint)
|
||||
else:
|
||||
_say("支持:" + _platform_list_cn_for_help())
|
||||
return None
|
||||
|
||||
|
||||
# ============================================================================
|
||||
@@ -238,6 +273,55 @@ def cmd_platform_get(input_key: str) -> None:
|
||||
_say(_err_json("ERROR:INVALID_PLATFORM", f"Platform '{key}' not found in DB."))
|
||||
|
||||
|
||||
def cmd_platform_ensure(
|
||||
key: str,
|
||||
display_name: str,
|
||||
domain: str = "generic",
|
||||
url: str = "",
|
||||
auth_strategy: Optional[str] = None,
|
||||
aliases: Optional[str] = None,
|
||||
capabilities: Optional[str] = None,
|
||||
) -> int:
|
||||
"""
|
||||
幂等地注册或更新平台到 DB。
|
||||
输出单行 JSON:{"ok": true, "platform_key": "xxx", "action": "created|updated"}
|
||||
"""
|
||||
log = get_skill_logger()
|
||||
key = (key or "").strip()
|
||||
display_name = (display_name or key).strip()
|
||||
if not key:
|
||||
_say('ERROR:INVALID_ARGS platform ensure 需要 --key 参数')
|
||||
return 1
|
||||
|
||||
aliases_json = aliases if aliases else json.dumps([key, display_name], ensure_ascii=False)
|
||||
capabilities_json = capabilities if capabilities else '{"web": true, "api_key": false, "rpa": true}'
|
||||
|
||||
init_db()
|
||||
conn = get_conn()
|
||||
try:
|
||||
existed = bool(
|
||||
conn.execute(
|
||||
"SELECT 1 FROM platforms WHERE platform_key = ?", (key,)
|
||||
).fetchone()
|
||||
)
|
||||
upsert_platform(
|
||||
conn,
|
||||
key=key,
|
||||
display_name=display_name,
|
||||
domain=domain,
|
||||
default_url=url,
|
||||
aliases_json=aliases_json,
|
||||
capabilities_json=capabilities_json,
|
||||
default_auth_strategy=auth_strategy,
|
||||
)
|
||||
finally:
|
||||
conn.close()
|
||||
action = "updated" if existed else "created"
|
||||
log.info("platform_ensure key=%s action=%s", key, action)
|
||||
_say(json.dumps({"ok": True, "platform_key": key, "action": action}, ensure_ascii=False))
|
||||
return 0
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# Account add-web
|
||||
# ============================================================================
|
||||
|
||||
Reference in New Issue
Block a user