The only downloader you need. 下载器的集大成者。
TypeScript asyncasynciobittorentbtcross-platformdownload-managerdownloaderfluent-designftphttp3magnetpyqtpyside6pythonqtquicreactsoftwarestreaming
fix(github): 代理站挂了不会卡死,自动换下一个
XiaoYouChRc67db63457d6
diff --git a/features/github_pack/pack.py b/features/github_pack/pack.pyindex 72f94c3a..69c9302d 100644--- a/features/github_pack/pack.py+++ b/features/github_pack/pack.py@@ -8,6 +8,7 @@ from app.client import buildClientfrom app.models.pack import FeaturePack, TaskParserfrom app.models.task import Task, TaskError, TaskOptions, ResourceTaskOptionsfrom http_pack.cards import HttpTaskCard+from http_pack.pack import HttpParserfrom http_pack.task import HttpTask, HttpTaskStepfrom .config import githubConfig, selectedProxySite, GITHUB_PROXY_SITES@@ -64,8 +65,6 @@ class GitHubHttpTaskStep(HttpTaskStep):returnexcept CancelledError:raise- except TaskError:- raiseexcept Exception:if not self.fallbackUrls:raise@@ -77,17 +76,17 @@ class GitHubHttpTaskStep(HttpTaskStep):self.progress = 0self.speed = 0self.error = None+ self.canUseRangeRequests = True+ self.isAccelerated = Falseself._deleteRecord()class GitHubParser(TaskParser):priority = 90- _isFallingBack = Falsedef match(self, options: TaskOptions) -> bool:return (- not self._isFallingBack- and githubConfig.enabled.value+ githubConfig.enabled.valueand bool(selectedProxySite())and isGitHubFileUrl(options.url))@@ -103,8 +102,10 @@ class GitHubParser(TaskParser):if isResourceWithName and not isDirectUrl:await self._probeProxy(url, options.headers)- self._isFallingBack = isDirectUrl- task = await self.delegate(replace(options, url=url))+ if isDirectUrl:+ task = await HttpParser().parse(options)+ else:+ task = await self.delegate(replace(options, url=url))remaining = fallbackUrls[i + 1:]if remaining:@@ -120,8 +121,6 @@ class GitHubParser(TaskParser):except Exception as e:lastError = elogger.warning("GitHub proxy 不可用 {}: {}", url, e)- finally:- self._isFallingBack = Falseraise lastErrordiff --git a/tests/test_github_fallback.py b/tests/test_github_fallback.pyindex 44aa0431..d7e9200d 100644--- a/tests/test_github_fallback.py+++ b/tests/test_github_fallback.py@@ -77,7 +77,7 @@ class TestDownloadTimeFallback:assert (tmp_path / "test.bin").read_bytes() == contentassert step.url == okUrl- async def test_no_fallback_on_permanent_error(self, server, tmp_path):+ async def test_fallback_on_proxy_http_error(self, server, tmp_path):content = buildFileContent(100)async def forbidden(request):@@ -91,6 +91,22 @@ class TestDownloadTimeFallback:)task.setStatus(TaskStatus.RUNNING)+ await runStep(step)++ assert (tmp_path / "test.bin").read_bytes() == content+ assert step.url == okUrl++ async def test_permanent_error_without_fallback(self, server, tmp_path):+ async def forbidden(request):+ return web.Response(status=403, text="Forbidden")++ forbiddenUrl = await server(forbidden)++ task, step = makeGitHubStep(+ forbiddenUrl, tmp_path, fileSize=100,+ )+ task.setStatus(TaskStatus.RUNNING)+with pytest.raises(TaskError, match="403"):await runStep(step)@@ -108,6 +124,29 @@ class TestDownloadTimeFallback:assert (tmp_path / "test.bin").read_bytes() == contentassert step.url == okUrl+ async def test_fallback_restores_range_support(self, server, tmp_path):+ content = buildFileContent(200)++ async def rangeDegradeThenReject(request):+ if request.headers.get("Range"):+ return web.Response(status=200, body=b"x")+ return web.Response(status=403, text="Forbidden")++ firstUrl = await server(rangeDegradeThenReject)+ okUrl = await server(buildRangeHandler(content))++ task, step = makeGitHubStep(+ firstUrl, tmp_path, fileSize=200,+ fallbackUrls=[okUrl], canUseRangeRequests=True,+ )+ task.setStatus(TaskStatus.RUNNING)++ await runStep(step)++ assert (tmp_path / "test.bin").read_bytes() == content+ assert step.url == okUrl+ assert step.canUseRangeRequests is True+async def test_all_fallbacks_exhausted(self, tmp_path, deadUrl):task, step = makeGitHubStep(deadUrl, tmp_path, fileSize=100,@@ -167,6 +206,35 @@ class TestParseTimeFallback:assert "proxy2.com" in step.fallbackUrls[0]assert step.fallbackUrls[1] == options.url+ async def test_direct_url_bypasses_delegate(self, monkeypatch):+ from http_pack.pack import HttpParser++ parser = GitHubParser()++ delegateUrls = []+ async def trackingDelegate(options):+ delegateUrls.append(options.url)+ if "dead-proxy.com" in options.url:+ raise ConnectionError("refused")+ return await passThroughDelegate(options)++ parser.delegate = trackingDelegate+ monkeypatch.setattr("github_pack.pack.selectedProxySite", lambda: "https://dead-proxy.com")+ monkeypatch.setattr("github_pack.pack.GITHUB_PROXY_SITES", ("https://dead-proxy.com",))++ async def fakeHttpParse(self, options):+ return await passThroughDelegate(options)+ monkeypatch.setattr(HttpParser, "parse", fakeHttpParse)++ options = TaskOptions(url="https://github.com/user/repo/releases/download/v1.0/file.zip")+ task = await parser.parse(options)++ assert task.packId == "github"+ assert task.url == options.url+ assert all("dead-proxy.com" in u for u in delegateUrls), (+ "direct URL should not go through delegate"+ )+async def test_resource_options_probes_proxy(self, monkeypatch):parser = GitHubParser()probedUrls = []