diff --git a/scripts/cli/app.py b/scripts/cli/app.py index 5fb1934..ea20a33 100644 --- a/scripts/cli/app.py +++ b/scripts/cli/app.py @@ -32,7 +32,7 @@ def _cli_print_full_usage() -> None: print(" python main.py set-login-status <0|1> # 跨技能回写登录态") print(" python main.py open ") print(" python main.py login ") - print(" python main.py wait-login # 跨技能:限时内等待网页登录(默认 180s)") + print(" python main.py wait-login [--force] # 跨技能:限时内等待网页登录(默认 180s);--force 忽略库内已登录标记") print(" python main.py delete id ") print(" python main.py delete platform <平台>") print(" python main.py delete platform <平台> <手机号>") @@ -153,12 +153,16 @@ def main() -> None: sys.exit(1) cmd_open(sys.argv[2]) elif cmd == "wait-login": - if len(sys.argv) < 3: + av = [a for a in sys.argv[2:] if a] + force = "--force" in av or "-f" in av + av = [a for a in av if a not in ("--force", "-f")] + if len(av) < 1: print("ERROR:CLI_WAIT_LOGIN_MISSING_ID") - print("用法:python main.py wait-login <账号 id>") - print("说明:供 llm-manager 等编排;未登录时打开浏览器,限时内等待登录或用户关窗即结束。") + print("用法:python main.py wait-login <账号 id> [--force]") + print("说明:供 llm-manager / 搜狐发布等编排;未登录时打开浏览器,限时内等待登录或用户关窗即结束。") + print("--force:即使库内已标为登录也重新打开浏览器检测(Cookie 失效时用)。") sys.exit(1) - sys.exit(cmd_wait_login(sys.argv[2])) + sys.exit(cmd_wait_login(av[0], force=force)) elif cmd == "login": if len(sys.argv) < 3: _cli_fail_need_account_id("login") diff --git a/scripts/service/browser_service.py b/scripts/service/browser_service.py index 813a158..91ba241 100644 --- a/scripts/service/browser_service.py +++ b/scripts/service/browser_service.py @@ -294,21 +294,23 @@ def cmd_login(account_id): print(f"ℹ️ 详细轮询日志见:{log_file}(可将 JIANGCHANG_LOG_LEVEL=DEBUG 打开更细粒度)") -def cmd_wait_login(account_id) -> int: +def cmd_wait_login(account_id, force: bool = False) -> int: """ 跨技能编排:若未登录则打开浏览器并在限时内等待登录。 返回 0:已登录(原本已登录或本次登录成功);1:失败(超时 / 用户关浏览器 / 其它)。 - stdout 首行:OK:WAIT_LOGIN 或 ERROR:WAIT_LOGIN_*。 + stdout 含 OK:WAIT_LOGIN 或 ERROR:WAIT_LOGIN_*。 + + force=True:即使库内 login_status=1 也仍打开浏览器并限时检测(供搜狐发布等「页面仍要求登录」场景)。 """ log = get_skill_logger() - log.info("wait_login_command account_id=%r", account_id) + log.info("wait_login_command account_id=%r force=%s", account_id, force) target = get_account_by_id(account_id) if not target: log.warning("wait_login_aborted account_not_found account_id=%r", account_id) print("ERROR:ACCOUNT_NOT_FOUND") return 1 - # 库内 login_status=1 时跳过开窗(仅性能提示;与真实 Cookie 可能不同步,此时应再执行 wait-login 覆盖) - if int(target.get("login_status") or 0) == 1: + # 库内 login_status=1 时跳过开窗(与真实 Cookie 可能不同步时用 force=True) + if int(target.get("login_status") or 0) == 1 and not force: print("OK:WAIT_LOGIN") return 0