From aa9820398dd850145e7995e4435f8ebde79c14f6 Mon Sep 17 00:00:00 2001 From: Nose Date: Thu, 22 Jan 2026 04:17:27 -0800 Subject: [PATCH] f --- Store/HydrusNetwork.py | 13 ++++++++++++- cmdlet/get_file.py | 8 ++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Store/HydrusNetwork.py b/Store/HydrusNetwork.py index c2e84f9..1343ed8 100644 --- a/Store/HydrusNetwork.py +++ b/Store/HydrusNetwork.py @@ -1272,8 +1272,19 @@ class HydrusNetwork(Store): IMPORTANT: this method must be side-effect free (do not auto-open a browser). 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')})") - debug(f"{self._log_prefix()} get_file: start hash={file_hash[:12]}...") + # 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. + if kwargs.get("url"): + base_url = str(self.URL).rstrip("/") + access_key = str(self.API) + 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}") + return browser_url # Try to get the local disk path if possible (works if Hydrus is on same machine) server_path = None diff --git a/cmdlet/get_file.py b/cmdlet/get_file.py index 3005cdb..831d0a2 100644 --- a/cmdlet/get_file.py +++ b/cmdlet/get_file.py @@ -139,8 +139,12 @@ class Get_File(sh.Cmdlet): debug(f"[get-file] Calling backend.get_file({file_hash})") - # Get file from backend (may return Path or URL string depending on backend) - source_path = backend.get_file(file_hash) + # Get file from backend (may return Path or URL string depending on backend). + # We pass url=True if no explicit path was provided, which hints the backend + # (specifically Hydrus) to return a browser-friendly URL instead of a local path. + want_url = (output_path is None) + debug(f"[get-file] Requesting file from backend (url_hint={want_url})...") + source_path = backend.get_file(file_hash, url=want_url) debug(f"[get-file] backend.get_file returned: {source_path}")