Compare commits

..

3 Commits

Author SHA1 Message Date
baiiylu
9ff014a1f7 fix(networking): remove timeout settings; 2026-03-10 14:30:16 +00:00
zsbai
b0060eee35 feat: Retry added for network request; 2026-02-12 21:43:26 +00:00
baiiylu
09f7e5317b refactor: rewrite in Python (#7)
* refactor: rewrite destVersionForMac in python; remove redundant code & files; new workflow parameter: Force create release using latest WeChat dmg;

* misc: update README file;
2026-02-13 05:39:14 +08:00

View File

@@ -76,7 +76,7 @@ def fetch_download_link() -> str:
str: 下载链接 URL
"""
# Fetch HTML and extract the first download link on the page.
with urllib.request.urlopen(WEBSITE_URL, timeout=30) as response:
with urllib.request.urlopen(WEBSITE_URL) as response:
html = response.read().decode("utf-8", errors="replace")
parser = DownloadLinkParser()
parser.feed(html)
@@ -92,11 +92,22 @@ def fetch_head_metadata(url: str) -> dict[str, str]:
Returns:
dict[str, str]: 从 HEAD 响应中提取的元数据字典,键为小写字符串,值为对应的响应头值
"""
# Use HEAD request to read metadata from the direct file link.
request = urllib.request.Request(url, method="HEAD")
with urllib.request.urlopen(request, timeout=30) as response:
return {key.lower(): value.strip() for key, value in response.headers.items()}
attempts = 2
last_error: Exception | None = None
for attempt in range(1, attempts + 1):
try:
request = urllib.request.Request(url, method="HEAD")
with urllib.request.urlopen(request) as response:
return {key.lower(): value.strip() for key, value in response.headers.items()}
except Exception as exc:
last_error = exc
if attempt < attempts:
log(f"HEAD request failed (attempt {attempt}). Waiting before retry...")
time.sleep(10)
if last_error:
log(f"HEAD request failed after {attempts} attempts: {last_error}")
return {}
def download_with_retry(url: str, dest: Path) -> None:
"""
@@ -121,8 +132,6 @@ def download_with_retry(url: str, dest: Path) -> None:
"--waitretry",
"5",
"--retry-connrefused",
"--timeout",
"30",
url,
"-O",
str(dest),