fix(fetch): AList download route authenticates with x-api-token

This AList deployment (sales.dobotoa.cn family) only recognizes x-api-token on
the /p/ download route; an Authorization header gets 302'd to login.dingtalk.com.
Probe x-api-token first, fall back to Authorization, then fail-closed.
This commit is contained in:
姚章浩
2026-09-13 23:49:01 +08:00
parent fad8b10247
commit c2d093bc90
+9 -1
View File
@@ -201,9 +201,17 @@ def alist_download(manifest, max_bytes):
if manifest.get("size_bytes") in (None, 0) and data.get("size"):
manifest["size_bytes"] = int(data["size"])
download_url = urllib.parse.urljoin(base_url + "/", raw_url.lstrip("/"))
# This AList deployment gates the download route with x-api-token (the
# Authorization header is NOT recognized there): wrong auth yields a 302
# to the DingTalk login page instead of bytes.
try:
return http_get(download_url, {"Authorization": token}, 180, max_bytes)
return http_get(download_url, {"x-api-token": token}, 180, max_bytes)
except FetchError as error:
if error.code == "source_auth_required":
try:
return http_get(download_url, {"Authorization": token}, 180, max_bytes)
except FetchError:
raise error
if error.code == "redirect":
# Same-origin /d/ route 302s to a signed external URL: follow once
# WITHOUT the source token (never forward credentials cross-origin).