Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e3da478116 | |||
| ac76f89dc8 |
@@ -32,7 +32,7 @@ def _cli_print_full_usage() -> None:
|
||||
print(" python main.py set-login-status <id> <0|1> # 跨技能回写登录态")
|
||||
print(" python main.py open <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 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")
|
||||
|
||||
@@ -18,6 +18,9 @@ DEFAULT_LOCAL_USER_ID = "10032"
|
||||
|
||||
import sys
|
||||
|
||||
|
||||
|
||||
# 发版/嵌入宿主前改为 False,或仅通过环境变量 JIANGCHANG_CLI_LOCAL_DEV=1 开启
|
||||
|
||||
CLI_LOCAL_DEV_ENABLED = True
|
||||
|
||||
@@ -36,6 +39,77 @@ def get_user_id() -> str:
|
||||
|
||||
|
||||
# 匠厂桌面宿主应用根(未设置 JIANGCHANG_APP_ROOT 时 Windows 兜底;技能一般在 {APP}/skills/ 下并列)
|
||||
|
||||
WIN_DEFAULT_JIANGCHANG_APP_ROOT = r"D:\AI\jiangchang"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def platform_default_data_root() -> str:
|
||||
|
||||
if sys.platform == "win32":
|
||||
|
||||
return WIN_DEFAULT_DATA_ROOT
|
||||
|
||||
return os.path.join(os.path.expanduser("~"), ".jiangchang-data")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def get_data_root() -> str:
|
||||
|
||||
env = (os.getenv("JIANGCHANG_DATA_ROOT") or "").strip()
|
||||
|
||||
if env:
|
||||
|
||||
return env
|
||||
|
||||
return platform_default_data_root()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def get_user_id() -> str:
|
||||
|
||||
return (os.getenv("JIANGCHANG_USER_ID") or "").strip() or "_anon"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def _looks_like_skills_root(path: str) -> bool:
|
||||
|
||||
if not path or not os.path.isdir(path):
|
||||
|
||||
return False
|
||||
|
||||
for marker in (
|
||||
|
||||
"llm-manager",
|
||||
|
||||
"content-manager",
|
||||
|
||||
"account-manager",
|
||||
|
||||
"sohu-publisher",
|
||||
|
||||
"api-key-vault",
|
||||
|
||||
):
|
||||
|
||||
if os.path.isdir(os.path.join(path, marker)):
|
||||
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def get_skills_root() -> str:
|
||||
|
||||
"""
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user