mirror of
https://github.com/calibrain/shelfmark.git
synced 2026-11-16 02:18:14 +00:00
fix(sources): take the retry download URL from the release cache only (#1597)
Newznab and Jackett fell back to the download URL sent with the queue request when the release was no longer in the cache. Prowlarr already returns no URL in that case, so this makes the other two match it: the retry URL comes from the cache and nothing else. A request for a release that has expired from the cache now fails with "Release not found in cache" instead of being queued with whatever URL came along. The new tests cover both handlers on a cache miss and with no source_id, and they fail on main. Full suite, ruff and basedpyright pass.
This commit is contained in:
1 parent
8b80f32476
commit
e8b28d05e0
3 files changed
+36
-6
No files matched your search
@@ -86,7 +86,8 @@ class JackettHandler(ExternalClientHandler):
|
||||
source_id = normalize_optional_text(release_data.get("source_id"))
|
||||
result = get_release(source_id) if source_id else None
|
||||
if result is None:
|
||||
return {}
|
||||
# Never fall back to the URL the client sent along with the request.
|
||||
return {"retry_download_url": None, "retry_download_protocol": None}
|
||||
|
||||
protocol = get_protocol(result)
|
||||
return {
|
||||
|
||||
@@ -93,12 +93,10 @@ class NewznabHandler(ExternalClientHandler):
|
||||
|
||||
def build_retry_resolution_fields(self, release_data: dict) -> dict:
|
||||
source_id = normalize_optional_text(release_data.get("source_id"))
|
||||
if source_id is None:
|
||||
return {}
|
||||
|
||||
result = get_release(source_id)
|
||||
result = get_release(source_id) if source_id else None
|
||||
if result is None:
|
||||
return {}
|
||||
# Never fall back to the URL the client sent along with the request.
|
||||
return {"retry_download_url": None, "retry_download_protocol": None}
|
||||
|
||||
protocol = _get_protocol(result)
|
||||
return {
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
"""The retry URL comes from server data, never from the queue request."""
|
||||
|
||||
import pytest
|
||||
|
||||
from shelfmark.download import orchestrator
|
||||
|
||||
|
||||
@pytest.mark.parametrize("source", ["newznab", "jackett"])
|
||||
def test_cache_miss_drops_client_supplied_download_url(source):
|
||||
fields = orchestrator._build_retry_resolution_fields(
|
||||
{
|
||||
"source": source,
|
||||
"source_id": "not-in-the-cache",
|
||||
"download_url": "http://169.254.169.254/latest/meta-data/",
|
||||
"protocol": "torrent",
|
||||
"title": "Some Book",
|
||||
}
|
||||
)
|
||||
|
||||
assert fields["retry_download_url"] is None
|
||||
assert fields["retry_download_protocol"] is None
|
||||
|
||||
|
||||
@pytest.mark.parametrize("source", ["newznab", "jackett"])
|
||||
def test_missing_source_id_drops_client_supplied_download_url(source):
|
||||
fields = orchestrator._build_retry_resolution_fields(
|
||||
{"source": source, "download_url": "http://10.0.0.1/x", "protocol": "usenet"}
|
||||
)
|
||||
|
||||
assert fields["retry_download_url"] is None
|
||||
assert fields["retry_download_protocol"] is None
|
||||
Reference in new issue
Block a user