This commit is contained in:
Your Name
2026-08-27 18:32:03 +08:00
parent 4ac6990efe
commit 1f3addcf79
50 changed files with 9145 additions and 1760 deletions
+23
View File
@@ -128,6 +128,10 @@ def _parse_tea_from_ls(origins: list) -> tuple[str, str]:
parsed = json.loads(entry.get("value") or "{}")
except Exception:
continue
# __tea_cache_first_6383 等条目的值是纯数字(如 1),json.loads 返回 int
# 不是 dict,必须跳过,否则 parsed.get() 抛 AttributeError 导致保存凭证 500。
if not isinstance(parsed, dict):
continue
uid = str(parsed.get("user_unique_id") or "").strip()
wid = str(parsed.get("web_id") or "").strip()
if uid and wid and uid == wid and len(uid) > 12:
@@ -233,6 +237,25 @@ def validate_cookie_json(cookie_data: str) -> dict:
return normalize_storage_state_for_im(data)
def extract_user_agent_from_cookie_data(cookie_data: Optional[str]) -> str:
"""从已保存的 Cookie JSON 提取顶层 user_agent(登录头)。
Playwright storage_state 导出时顶层带 user_agent(采集浏览器当前 UA);
DYCRED 凭证经 convert_dycred_to_storage_state 后也统一落到 user_agent。
返回完整 UA 字符串;缺失/无效时返回空串,由调用方决定是否回填账号。
"""
if not cookie_data:
return ""
try:
data = json.loads(cookie_data)
except Exception:
return ""
if not isinstance(data, dict):
return ""
ua = str(data.get("user_agent") or data.get("ua") or "").strip()
return ua
def write_cookie_file(account_id: int, cookie_data: str) -> str:
data = validate_cookie_json(cookie_data)
path = get_cookie_path(account_id)