This commit is contained in:
@@ -4,7 +4,7 @@ CLI entry point: argv dispatch for account-manager v2.
|
||||
|
||||
Subcommand tree:
|
||||
platform list/get/ensure
|
||||
account add-web|ensure-web|add-secret|get|get-credential|list|resolve|pick-web|mark-session|mark-error|mark-used|open
|
||||
account add-web|ensure-web|add-secret|get|get-credential|list|resolve|pick-web|mark-session|mark-error|mark-used|open|reveal-profile
|
||||
init-master-key|export-credentials|import-credentials
|
||||
credential pick|resolve
|
||||
lease release|list|cleanup
|
||||
@@ -49,7 +49,7 @@ from service.account_service import (
|
||||
cmd_platform_get,
|
||||
cmd_platform_list,
|
||||
)
|
||||
from service.browser_service import cmd_open
|
||||
from service.browser_service import cmd_open, cmd_reveal_profile
|
||||
from util.constants import LOG_LOGGER_NAME, SKILL_SLUG
|
||||
from util.logging_config import get_skill_logger, setup_skill_logging
|
||||
from util.platforms import _platform_list_cn_for_help, resolve_platform_key
|
||||
@@ -104,6 +104,7 @@ _USAGE = """account-manager v2 — Credential & Browser Profile Manager
|
||||
account mark-error <id> --code <code> --message <msg>
|
||||
account mark-used <id>
|
||||
account open <id>
|
||||
account reveal-profile <id>
|
||||
account init-master-key [--print|--from-env|--rotate]
|
||||
account export-credentials --plaintext
|
||||
account import-credentials [--replace-all] < backup.json
|
||||
@@ -118,8 +119,9 @@ _USAGE = """account-manager v2 — Credential & Browser Profile Manager
|
||||
lease list [--active]
|
||||
lease cleanup
|
||||
|
||||
浏览器:
|
||||
浏览器 / Profile:
|
||||
account open <id>
|
||||
account reveal-profile <id> # 在文件管理器中打开 profile_dir
|
||||
open <id> # 兼容别名
|
||||
|
||||
兼容入口(旧版):
|
||||
@@ -322,6 +324,11 @@ def main() -> None:
|
||||
print("ERROR:CLI_BAD_ARGS account open 需要 <id>。")
|
||||
sys.exit(1)
|
||||
cmd_open(av[3])
|
||||
elif sub == "reveal-profile":
|
||||
if len(av) < 4:
|
||||
print("ERROR:CLI_BAD_ARGS account reveal-profile 需要 <id>。")
|
||||
sys.exit(1)
|
||||
cmd_reveal_profile(av[3])
|
||||
elif sub == "init-master-key":
|
||||
cmd_account_init_master_key(av)
|
||||
elif sub == "export-credentials":
|
||||
|
||||
@@ -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