feat: use system curl for cmhub image downloads

This commit is contained in:
chengma
2026-07-08 09:26:25 +08:00
parent 4a499a17d1
commit cff61edce4
11 changed files with 355 additions and 9 deletions
+16
View File
@@ -83,6 +83,7 @@ DEFAULT_CONFIG = {
"image_alias": "",
"connect_timeout": 10,
"use_system_proxy": False,
"download_with_curl": "auto",
"check_balance_before_batch": False,
},
"title_concurrency": 4,
@@ -375,6 +376,9 @@ def _normalize_config_values(config):
cmhub = ai.get("cmhub")
if isinstance(cmhub, dict):
cmhub["base_url"] = normalize_cmhub_base_url(cmhub.get("base_url", ""))
cmhub["download_with_curl"] = _normalize_cmhub_download_with_curl(
cmhub.get("download_with_curl", "auto")
)
return config
@@ -386,6 +390,15 @@ def _clamp_int(value, minimum, maximum, default):
return min(int(maximum), max(int(minimum), number))
def _normalize_cmhub_download_with_curl(value):
if isinstance(value, bool):
return "true" if value else "false"
text = str(value or "auto").strip().lower()
if text in {"auto", "true", "false"}:
return text
return "auto"
def _assert_no_secrets(config):
def visit(value, path):
if isinstance(value, dict):
@@ -621,6 +634,9 @@ def cmhub_config(config=None) -> dict:
merged["title_alias"] = str(merged.get("title_alias", "") or "").strip()
merged["image_alias"] = str(merged.get("image_alias", "") or "").strip()
merged["connect_timeout"] = int(merged.get("connect_timeout", 10) or 10)
merged["download_with_curl"] = _normalize_cmhub_download_with_curl(
merged.get("download_with_curl", "auto")
)
merged["check_balance_before_batch"] = bool(merged.get("check_balance_before_batch", False))
if merged["connect_timeout"] <= 0:
raise ConfigError("ai.cmhub.connect_timeout 必须大于 0")