更新
This commit is contained in:
@@ -10,6 +10,33 @@ from utils.cookie_store import analyze_cookie
|
||||
|
||||
logger = logging.getLogger("credential")
|
||||
|
||||
CREDENTIAL_EGRESS_PUBLIC_IP_KEY = "credential_egress_public_ip"
|
||||
|
||||
|
||||
def credential_egress_mismatch(
|
||||
cookie_data: Optional[str],
|
||||
selected_public_ip: str = "",
|
||||
) -> bool:
|
||||
"""Compare historical browser egress metadata for diagnostics only.
|
||||
|
||||
This is not an authentication check: a different or missing local marker
|
||||
cannot prove that cookies are invalid. Callers must keep the credentials
|
||||
and use normal validation instead of forcing a reset or browser login.
|
||||
"""
|
||||
if not cookie_data:
|
||||
return False
|
||||
try:
|
||||
storage = json.loads(cookie_data)
|
||||
except (TypeError, ValueError):
|
||||
return False
|
||||
if not isinstance(storage, dict):
|
||||
return False
|
||||
selected = str(selected_public_ip or "").strip()
|
||||
if CREDENTIAL_EGRESS_PUBLIC_IP_KEY not in storage:
|
||||
return bool(selected)
|
||||
stored = str(storage.get(CREDENTIAL_EGRESS_PUBLIC_IP_KEY) or "").strip()
|
||||
return stored != selected
|
||||
|
||||
|
||||
def _should_reset_credentials(assessment: dict) -> bool:
|
||||
"""凭证全面失效时需清空 Cookie/IM 数据并重新登录。"""
|
||||
@@ -202,6 +229,7 @@ async def assess_account_credential(
|
||||
im_session_data: Optional[str] = None,
|
||||
*,
|
||||
startup_priority: bool = False,
|
||||
egress_public_ip: str = "",
|
||||
) -> dict:
|
||||
cookie_info = analyze_cookie(cookie_data)
|
||||
result = {
|
||||
@@ -227,6 +255,18 @@ async def assess_account_credential(
|
||||
return result
|
||||
|
||||
session = build_im_session_from_storage(storage, im_session_data)
|
||||
selected_public_ip = str(egress_public_ip or "").strip()
|
||||
if selected_public_ip:
|
||||
try:
|
||||
from rpa_engine.egress_channels import resolve_fixed_channel
|
||||
|
||||
route = await resolve_fixed_channel(selected_public_ip)
|
||||
session.egress_public_ip = selected_public_ip
|
||||
session.egress_source_ip = str(route.source_ip or "")
|
||||
except Exception as exc:
|
||||
result["message"] = f"指定公网通道 {selected_public_ip} 当前不可用:{exc}"
|
||||
result["login_mode"] = "browser"
|
||||
return result
|
||||
result["has_sessionid"] = has_im_session_token(session)
|
||||
|
||||
if not cookie_info.get("cookie_valid"):
|
||||
|
||||
Reference in New Issue
Block a user