This commit is contained in:
@@ -114,6 +114,58 @@ def resolve_account_browser_url(account: dict, conn=None) -> str:
|
||||
return (PLATFORMS.get(pk, {}).get("default_url") or "").strip()
|
||||
|
||||
|
||||
def cmd_reveal_profile(account_id):
|
||||
"""
|
||||
在系统文件管理器中打开该账号的 profile_dir。
|
||||
不写数据库、不启动浏览器。
|
||||
"""
|
||||
log = get_skill_logger()
|
||||
init_db()
|
||||
log.info("reveal_profile_start account_id=%r", account_id)
|
||||
|
||||
target = get_account_by_id(account_id)
|
||||
if not target:
|
||||
log.warning("reveal_profile_error account_id=%r not_found", account_id)
|
||||
print("ERROR:ACCOUNT_NOT_FOUND")
|
||||
sys.exit(1)
|
||||
|
||||
profile_dir = (target.get("profile_dir") or "").strip()
|
||||
if not profile_dir:
|
||||
log.warning("reveal_profile_error account_id=%s profile_dir_missing", account_id)
|
||||
print("ERROR:PROFILE_DIR_MISSING 账号中 profile_dir 为空。")
|
||||
sys.exit(1)
|
||||
|
||||
profile_abs = os.path.abspath(profile_dir)
|
||||
os.makedirs(profile_abs, exist_ok=True)
|
||||
|
||||
try:
|
||||
if sys.platform == "win32":
|
||||
# explorer 即使成功也常返回非 0;用 startfile 打开目录更稳妥
|
||||
os.startfile(profile_abs) # type: ignore[attr-defined]
|
||||
elif sys.platform == "darwin":
|
||||
subprocess.run(["open", profile_abs], check=False)
|
||||
else:
|
||||
subprocess.run(["xdg-open", profile_abs], check=False)
|
||||
except OSError as exc:
|
||||
log.error("reveal_profile_error account_id=%s error=%s", account_id, str(exc))
|
||||
print(f"ERROR:REVEAL_PROFILE_FAILED {exc}")
|
||||
sys.exit(1)
|
||||
|
||||
log.info("reveal_profile_ok account_id=%s profile_dir=%s", account_id, profile_abs)
|
||||
print(
|
||||
json.dumps(
|
||||
{
|
||||
"success": True,
|
||||
"data": {
|
||||
"account_id": int(target["id"]) if target.get("id") is not None else account_id,
|
||||
"profile_dir": profile_abs,
|
||||
},
|
||||
},
|
||||
ensure_ascii=False,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def cmd_open(account_id):
|
||||
"""
|
||||
打开该账号的持久化浏览器,仅用于肉眼核对。
|
||||
|
||||
Reference in New Issue
Block a user