Commit acac322d authored by 郭阔's avatar 郭阔

fix: login preflight auto-launches the source browser instance

nh_login_preflight assumed the per-source Chromium was already running
(panel login-test failed silently for sources whose window had been
closed); extract nh_ensure_instance (no-op when alive) and use it in
both preflight and autodiscover. Harvests were unaffected — harvest.js
already runs ensure-chromium itself.
parent 55ca6d6f
...@@ -381,6 +381,17 @@ nh_skill_bootstrap() { # clone(可选)+ 依赖安装 + 全量 bundle 导入 + v ...@@ -381,6 +381,17 @@ nh_skill_bootstrap() { # clone(可选)+ 依赖安装 + 全量 bundle 导入 + v
# 凭据文件:$CONF_DIR/logins/<source>.json({"url":…,"user":…,"password":…},建议 600)。 # 凭据文件:$CONF_DIR/logins/<source>.json({"url":…,"user":…,"password":…},建议 600)。
# 配方与浏览器自动化在技能仓 login-tools.js;本层只做编排,登录失败不中断采集 # 配方与浏览器自动化在技能仓 login-tools.js;本层只做编排,登录失败不中断采集
# (结果契约会如实标记付费墙)。 # (结果契约会如实标记付费墙)。
nh_ensure_instance() { # <source> 确保该源专属浏览器实例在线(已在线为无操作)
local source="$1"
if nh_is_darwin && [ -z "${CDP_PORT_OVERRIDE:-}" ]; then
export CDP_PORT_OVERRIDE="$(nh_cdp_port "$source")"
export CDP_PROFILE_OVERRIDE="$HOME/.news-harvester/profiles/${source}"
fi
[ -f "$(nh_skill_dir)/scripts/ensure-chromium.js" ] || return 0
(cd "$(nh_skill_dir)" && node scripts/ensure-chromium.js >/dev/null 2>&1 || true)
return 0
}
nh_login_preflight() { # <source> nh_login_preflight() { # <source>
local source="$1" creds tools_dir local source="$1" creds tools_dir
creds="$CONF_DIR/logins/${source}.json" creds="$CONF_DIR/logins/${source}.json"
...@@ -390,11 +401,7 @@ nh_login_preflight() { # <source> ...@@ -390,11 +401,7 @@ nh_login_preflight() { # <source>
echo "⚠️ 已配置 $source 的登录凭据,但技能缺少 login-tools.js,跳过预检" >&2 echo "⚠️ 已配置 $source 的登录凭据,但技能缺少 login-tools.js,跳过预检" >&2
return 0 return 0
fi fi
# 未显式指定浏览器实例时,自动使用该源的专属实例(darwin 隔离布局) nh_ensure_instance "$source"
if nh_is_darwin && [ -z "${CDP_PORT_OVERRIDE:-}" ]; then
export CDP_PORT_OVERRIDE="$(nh_cdp_port "$source")"
export CDP_PROFILE_OVERRIDE="$HOME/.news-harvester/profiles/${source}"
fi
export NH_LOGIN_USER="$(jq -r '.user // empty' "$creds" 2>/dev/null)" export NH_LOGIN_USER="$(jq -r '.user // empty' "$creds" 2>/dev/null)"
export NH_LOGIN_PASS="$(jq -r '.password // empty' "$creds" 2>/dev/null)" export NH_LOGIN_PASS="$(jq -r '.password // empty' "$creds" 2>/dev/null)"
if (cd "$tools_dir" && node scripts/login-tools.js check "$source") >/dev/null 2>&1; then if (cd "$tools_dir" && node scripts/login-tools.js check "$source") >/dev/null 2>&1; then
...@@ -416,15 +423,7 @@ nh_login_autodiscover() { # <source> 自动发现登录流程生成配方,并 ...@@ -416,15 +423,7 @@ nh_login_autodiscover() { # <source> 自动发现登录流程生成配方,并
[ -f "$creds" ] || { echo "❌ 未配置 $source 的凭据(看板「站点登录」页维护)" >&2; return 1; } [ -f "$creds" ] || { echo "❌ 未配置 $source 的凭据(看板「站点登录」页维护)" >&2; return 1; }
tools_dir="$(nh_skill_dir)" tools_dir="$(nh_skill_dir)"
[ -f "$tools_dir/scripts/login-tools.js" ] || { echo "❌ 技能缺少 login-tools.js" >&2; return 1; } [ -f "$tools_dir/scripts/login-tools.js" ] || { echo "❌ 技能缺少 login-tools.js" >&2; return 1; }
[ -f "$tools_dir/scripts/ensure-chromium.js" ] && { nh_ensure_instance "$source"
# 确保该源的专属浏览器实例在线(darwin 隔离布局)
(cd "$tools_dir" && { [ -z "${CDP_PORT_OVERRIDE:-}" ] && nh_is_darwin && export CDP_PORT_OVERRIDE="$(nh_cdp_port "$source")" CDP_PROFILE_OVERRIDE="$HOME/.news-harvester/profiles/${source}"; \
node scripts/ensure-chromium.js >/dev/null 2>&1; })
}
if nh_is_darwin && [ -z "${CDP_PORT_OVERRIDE:-}" ]; then
export CDP_PORT_OVERRIDE="$(nh_cdp_port "$source")"
export CDP_PROFILE_OVERRIDE="$HOME/.news-harvester/profiles/${source}"
fi
export NH_LOGIN_USER="$(jq -r '.user // empty' "$creds" 2>/dev/null)" export NH_LOGIN_USER="$(jq -r '.user // empty' "$creds" 2>/dev/null)"
export NH_LOGIN_PASS="$(jq -r '.password // empty' "$creds" 2>/dev/null)" export NH_LOGIN_PASS="$(jq -r '.password // empty' "$creds" 2>/dev/null)"
(cd "$tools_dir" && node scripts/login-tools.js discover "$source") (cd "$tools_dir" && node scripts/login-tools.js discover "$source")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment