feat: wait-login 支持 --force,供搜狐发布等 Cookie 失效仍开窗检测
All checks were successful
技能自动化发布 / release (push) Successful in 31s

Made-with: Cursor
This commit is contained in:
2026-04-06 17:30:50 +08:00
parent c83841cf90
commit ac76f89dc8
2 changed files with 16 additions and 10 deletions

View File

@@ -32,7 +32,7 @@ def _cli_print_full_usage() -> None:
print(" python main.py set-login-status <id> <0|1> # 跨技能回写登录态") print(" python main.py set-login-status <id> <0|1> # 跨技能回写登录态")
print(" python main.py open <id>") print(" python main.py open <id>")
print(" python main.py login <id>") print(" python main.py login <id>")
print(" python main.py wait-login <id> # 跨技能:限时内等待网页登录(默认 180s") print(" python main.py wait-login <id> [--force] # 跨技能:限时内等待网页登录(默认 180s--force 忽略库内已登录标记")
print(" python main.py delete id <id>") print(" python main.py delete id <id>")
print(" python main.py delete platform <平台>") print(" python main.py delete platform <平台>")
print(" python main.py delete platform <平台> <手机号>") print(" python main.py delete platform <平台> <手机号>")
@@ -153,12 +153,16 @@ def main() -> None:
sys.exit(1) sys.exit(1)
cmd_open(sys.argv[2]) cmd_open(sys.argv[2])
elif cmd == "wait-login": 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("ERROR:CLI_WAIT_LOGIN_MISSING_ID")
print("用法python main.py wait-login <账号 id>") print("用法python main.py wait-login <账号 id> [--force]")
print("说明:供 llm-manager 等编排;未登录时打开浏览器,限时内等待登录或用户关窗即结束。") print("说明:供 llm-manager / 搜狐发布等编排;未登录时打开浏览器,限时内等待登录或用户关窗即结束。")
print("--force即使库内已标为登录也重新打开浏览器检测Cookie 失效时用)。")
sys.exit(1) sys.exit(1)
sys.exit(cmd_wait_login(sys.argv[2])) sys.exit(cmd_wait_login(av[0], force=force))
elif cmd == "login": elif cmd == "login":
if len(sys.argv) < 3: if len(sys.argv) < 3:
_cli_fail_need_account_id("login") _cli_fail_need_account_id("login")

View File

@@ -294,21 +294,23 @@ def cmd_login(account_id):
print(f" 详细轮询日志见:{log_file}(可将 JIANGCHANG_LOG_LEVEL=DEBUG 打开更细粒度)") 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失败超时 / 用户关浏览器 / 其它)。 返回 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 = 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) target = get_account_by_id(account_id)
if not target: if not target:
log.warning("wait_login_aborted account_not_found account_id=%r", account_id) log.warning("wait_login_aborted account_not_found account_id=%r", account_id)
print("ERROR:ACCOUNT_NOT_FOUND") print("ERROR:ACCOUNT_NOT_FOUND")
return 1 return 1
# 库内 login_status=1 时跳过开窗(仅性能提示;与真实 Cookie 可能不同步,此时应再执行 wait-login 覆盖 # 库内 login_status=1 时跳过开窗(与真实 Cookie 可能不同步时用 force=True
if int(target.get("login_status") or 0) == 1: if int(target.get("login_status") or 0) == 1 and not force:
print("OK:WAIT_LOGIN") print("OK:WAIT_LOGIN")
return 0 return 0