refactor still on going
This commit is contained in:
+11
-5
@@ -41,6 +41,11 @@ class Get_File(sh.Cmdlet):
|
||||
"name",
|
||||
description="Output filename (default: from metadata title)"
|
||||
),
|
||||
sh.CmdletArg(
|
||||
"browser",
|
||||
flag=True,
|
||||
description="Open file in browser instead of saving to disk"
|
||||
),
|
||||
],
|
||||
detail=[
|
||||
"- Exports file from storage backend to local path",
|
||||
@@ -78,6 +83,7 @@ class Get_File(sh.Cmdlet):
|
||||
store_name = parsed.get("instance") or sh.get_field(result, "store")
|
||||
output_path = parsed.get("path")
|
||||
output_name = parsed.get("name")
|
||||
browser_flag = bool(parsed.get("browser"))
|
||||
|
||||
if not file_hash:
|
||||
log(
|
||||
@@ -150,9 +156,9 @@ class Get_File(sh.Cmdlet):
|
||||
return ""
|
||||
|
||||
# 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)
|
||||
# If -browser is given, request a URL (for Hydrus viewer). If -path is given,
|
||||
# always retrieve a local file. Otherwise default to local export.
|
||||
want_url = browser_flag
|
||||
source_path = backend.get_file(file_hash, url=want_url)
|
||||
|
||||
download_url = None
|
||||
@@ -175,8 +181,8 @@ class Get_File(sh.Cmdlet):
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if download_url and output_path is None:
|
||||
# Hydrus backend returns a URL; open it only when no output path
|
||||
if download_url and (browser_flag or output_path is None):
|
||||
# Open in browser: explicit -browser flag, or Hydrus returned a URL with no output path
|
||||
try:
|
||||
webbrowser.open(download_url)
|
||||
except Exception as exc:
|
||||
|
||||
Reference in New Issue
Block a user