update
This commit is contained in:
+67
-9
@@ -13,7 +13,7 @@ from urllib.parse import quote, parse_qsl, urlencode, urlsplit, urlunsplit
|
||||
import httpx
|
||||
from API.httpx_shared import get_shared_httpx_client
|
||||
|
||||
from SYS.logger import debug, log
|
||||
from SYS.logger import debug, debug_panel, log
|
||||
from SYS.utils_constant import mime_maps
|
||||
|
||||
_KNOWN_EXTS = {
|
||||
@@ -1533,7 +1533,17 @@ class HydrusNetwork(Store):
|
||||
Only explicit user actions (e.g. the get-file cmdlet) should open files.
|
||||
"""
|
||||
file_hash = str(file_hash or "").strip().lower()
|
||||
debug(f"{self._log_prefix()} get_file(hash={file_hash[:12]}..., url={kwargs.get('url')})")
|
||||
try:
|
||||
debug_panel(
|
||||
"Hydrus get_file",
|
||||
[
|
||||
("hash", file_hash),
|
||||
("prefer_url", bool(kwargs.get("url"))),
|
||||
],
|
||||
border_style="blue",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# If 'url=True' is passed, we preference the browser URL even if a local path is available.
|
||||
# This is typically used by the 'get-file' cmdlet for interactive viewing.
|
||||
@@ -1543,7 +1553,17 @@ class HydrusNetwork(Store):
|
||||
browser_url = (
|
||||
f"{base_url}/get_files/file?hash={file_hash}&Hydrus-Client-API-Access-Key={access_key}"
|
||||
)
|
||||
debug(f"{self._log_prefix()} get_file: returning browser URL per request: {browser_url}")
|
||||
try:
|
||||
debug_panel(
|
||||
"Hydrus get_file",
|
||||
[
|
||||
("mode", "browser-url"),
|
||||
("url", browser_url),
|
||||
],
|
||||
border_style="blue",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
return browser_url
|
||||
|
||||
# Try to get the local disk path if possible (works if Hydrus is on same machine)
|
||||
@@ -1555,18 +1575,46 @@ class HydrusNetwork(Store):
|
||||
if server_path:
|
||||
local_path = Path(server_path)
|
||||
if local_path.exists():
|
||||
debug(f"{self._log_prefix()} get_file: found local path: {local_path}")
|
||||
try:
|
||||
debug_panel(
|
||||
"Hydrus get_file",
|
||||
[
|
||||
("mode", "local-path"),
|
||||
("path", local_path),
|
||||
],
|
||||
border_style="green",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
return local_path
|
||||
except Exception as e:
|
||||
debug(f"{self._log_prefix()} get_file: could not resolve path from API: {e}")
|
||||
try:
|
||||
debug_panel(
|
||||
"Hydrus get_file",
|
||||
[
|
||||
("mode", "path-lookup-error"),
|
||||
("error", e),
|
||||
],
|
||||
border_style="yellow",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# If we found a path on the server but it's not locally accessible,
|
||||
# keep it for logging but continue to the browser URL fallback so the UI
|
||||
# can still open the file via the Hydrus web UI.
|
||||
if server_path:
|
||||
debug(
|
||||
f"{self._log_prefix()} get_file: server path not locally accessible, falling back to HTTP: {server_path}"
|
||||
)
|
||||
try:
|
||||
debug_panel(
|
||||
"Hydrus get_file fallback",
|
||||
[
|
||||
("mode", "remote-http"),
|
||||
("server_path", server_path),
|
||||
],
|
||||
border_style="yellow",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Fallback to browser URL with access key
|
||||
base_url = str(self.URL).rstrip("/")
|
||||
@@ -1574,7 +1622,17 @@ class HydrusNetwork(Store):
|
||||
browser_url = (
|
||||
f"{base_url}/get_files/file?hash={file_hash}&Hydrus-Client-API-Access-Key={access_key}"
|
||||
)
|
||||
debug(f"{self._log_prefix()} get_file: falling back to url={browser_url}")
|
||||
try:
|
||||
debug_panel(
|
||||
"Hydrus get_file fallback",
|
||||
[
|
||||
("mode", "remote-http"),
|
||||
("url", browser_url),
|
||||
],
|
||||
border_style="yellow",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
return browser_url
|
||||
|
||||
def download_to_temp(
|
||||
|
||||
Reference in New Issue
Block a user