This commit is contained in:
2026-02-11 19:06:38 -08:00
parent 1d0de1118b
commit ba623cb992
20 changed files with 848 additions and 247 deletions

View File

@@ -10,6 +10,7 @@ from typing import Any, Dict, List, Literal, Optional, Sequence, Tuple
from urllib.parse import quote
import httpx
from API.httpx_shared import get_shared_httpx_client
from SYS.logger import debug, log
from SYS.utils_constant import mime_maps
@@ -198,29 +199,28 @@ class HydrusNetwork(Store):
api_version_url = f"{self.URL}/api_version"
verify_key_url = f"{self.URL}/verify_access_key"
try:
with httpx.Client(timeout=5.0,
verify=False,
follow_redirects=True) as client:
version_resp = client.get(api_version_url)
version_resp.raise_for_status()
version_payload = version_resp.json()
if not isinstance(version_payload, dict):
raise RuntimeError(
"Hydrus /api_version returned an unexpected response"
)
verify_resp = client.get(
verify_key_url,
headers={
"Hydrus-Client-API-Access-Key": self.API
},
client = get_shared_httpx_client(timeout=5.0, verify_ssl=False)
version_resp = client.get(api_version_url, follow_redirects=True)
version_resp.raise_for_status()
version_payload = version_resp.json()
if not isinstance(version_payload, dict):
raise RuntimeError(
"Hydrus /api_version returned an unexpected response"
)
verify_resp = client.get(
verify_key_url,
headers={
"Hydrus-Client-API-Access-Key": self.API
},
follow_redirects=True,
)
verify_resp.raise_for_status()
verify_payload = verify_resp.json()
if not isinstance(verify_payload, dict):
raise RuntimeError(
"Hydrus /verify_access_key returned an unexpected response"
)
verify_resp.raise_for_status()
verify_payload = verify_resp.json()
if not isinstance(verify_payload, dict):
raise RuntimeError(
"Hydrus /verify_access_key returned an unexpected response"
)
_HYDRUS_INIT_CHECK_CACHE[cache_key] = (True, None)
except Exception as exc:
@@ -294,12 +294,10 @@ class HydrusNetwork(Store):
"Hydrus-Client-API-Access-Key": self.API,
"Accept": "application/json",
}
with httpx.Client(timeout=5.0,
verify=False,
follow_redirects=True) as client:
resp = client.get(url, params=params, headers=headers)
resp.raise_for_status()
payload = resp.json()
client = get_shared_httpx_client(timeout=5.0, verify_ssl=False)
resp = client.get(url, params=params, headers=headers, follow_redirects=True)
resp.raise_for_status()
payload = resp.json()
count_val = None
if isinstance(payload, dict):
@@ -1587,13 +1585,13 @@ class HydrusNetwork(Store):
file_url = f"{self.URL.rstrip('/')}/get_files/file?hash={quote(h)}"
dest_path = base_tmp / fname
with httpx.stream(
stream_client = get_shared_httpx_client(timeout=60.0, verify_ssl=False)
with stream_client.stream(
"GET",
file_url,
headers={"Hydrus-Client-API-Access-Key": self.API},
follow_redirects=True,
timeout=60.0,
verify=False,
) as resp:
resp.raise_for_status()
with dest_path.open("wb") as fh: