Skip to content

The only downloader you need. 下载器的集大成者。

fix(client): 修正模拟身份的默认回落

XiaoYouChR3ca698c00e69
diff --git a/app/client.py b/app/client.py
index 0bed6028..9e1cb376 100644
--- a/app/client.py
+++ b/app/client.py
@@ -19,7 +19,8 @@ if TYPE_CHECKING:
from collections.abc import Callable
from wreq import ClientConfig
-FALLBACK_PROFILE = "chrome"
+# 公共镜像站按 UA 拦截下载器,Chrome 140 是目前实测仍放行的最新 Chrome
+FALLBACK_EMULATION = Emulation.Chrome140
FETCH_READ_TIMEOUT = 30
FAMILY_BY_PREFIX = {
@@ -60,9 +61,7 @@ def toEmulation(profile: str, sourceUa: str = "") -> Emulation | None:
return None
if profile == "auto":
- return matchEmulation(sourceUa, host) or Emulation(
- profile=PROFILES_BY_FAMILY["chrome"][0][2], platform=host,
- )
+ return matchEmulation(sourceUa, host) or Emulation(profile=FALLBACK_EMULATION, platform=host)
if profile in PROFILES_BY_FAMILY:
return Emulation(
@@ -78,7 +77,7 @@ def toEmulation(profile: str, sourceUa: str = "") -> Emulation | None:
return Emulation(profile=pinned, platform=PLATFORM_BY_FAMILY.get(fam, host))
logger.warning("未知的模拟身份 {}, 退回默认", profile)
- return Emulation(profile=PROFILES_BY_FAMILY["chrome"][0][2], platform=host)
+ return Emulation(profile=FALLBACK_EMULATION, platform=host)
def matchIdentityPreset(host: str) -> dict | None:
@@ -141,13 +140,6 @@ def buildClient(
else:
if userAgent:
headers = {**headers, "user-agent": userAgent}
- elif not any(k.lower() == "user-agent" for k in headers):
- major = PROFILES_BY_FAMILY["chrome"][0][1][0]
- headers = {
- **headers,
- "user-agent": f"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
- f"(KHTML, like Gecko) Chrome/{major}.0.0.0 Safari/537.36",
- }
config["headers"] = headers
elif userAgent:
config["headers"] = {"user-agent": userAgent}