d
This commit is contained in:
@@ -691,14 +691,35 @@ class Add_File(Cmdlet):
|
||||
# Fallback: at least show the add-file payloads as a display overlay
|
||||
from SYS.result_table import ResultTable
|
||||
|
||||
table = ResultTable("Result")
|
||||
for payload in collected_payloads:
|
||||
table.add_result(payload)
|
||||
ctx.set_last_result_table_overlay(
|
||||
table,
|
||||
collected_payloads,
|
||||
subject=collected_payloads
|
||||
)
|
||||
# If this was a single-item ingest, render the detailed item display
|
||||
# directly from the payload to avoid DB refresh contention.
|
||||
detail_rendered = False
|
||||
if len(collected_payloads) == 1:
|
||||
try:
|
||||
from SYS.rich_display import render_item_details_panel
|
||||
|
||||
render_item_details_panel(collected_payloads[0])
|
||||
table = ResultTable("Result")
|
||||
table.add_result(collected_payloads[0])
|
||||
setattr(table, "_rendered_by_cmdlet", True)
|
||||
ctx.set_last_result_table_overlay(
|
||||
table,
|
||||
collected_payloads,
|
||||
subject=collected_payloads[0]
|
||||
)
|
||||
detail_rendered = True
|
||||
except Exception:
|
||||
detail_rendered = False
|
||||
|
||||
if not detail_rendered:
|
||||
table = ResultTable("Result")
|
||||
for payload in collected_payloads:
|
||||
table.add_result(payload)
|
||||
ctx.set_last_result_table_overlay(
|
||||
table,
|
||||
collected_payloads,
|
||||
subject=collected_payloads
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@@ -1875,6 +1896,12 @@ class Add_File(Cmdlet):
|
||||
except Exception:
|
||||
hydrus_like_backend = False
|
||||
|
||||
is_folder_backend = False
|
||||
try:
|
||||
is_folder_backend = type(backend).__name__ == "Folder"
|
||||
except Exception:
|
||||
is_folder_backend = False
|
||||
|
||||
# Prepare metadata from pipe_obj and sidecars
|
||||
tags, url, title, f_hash = Add_File._prepare_metadata(
|
||||
result, media_path, pipe_obj, config
|
||||
@@ -1996,7 +2023,20 @@ class Add_File(Cmdlet):
|
||||
# For Hydrus, get_file() returns a browser URL (often with an access key) and should
|
||||
# only be invoked by explicit user commands (e.g. get-file).
|
||||
try:
|
||||
if type(backend).__name__ == "Folder":
|
||||
if is_folder_backend:
|
||||
# Avoid extra DB round-trips for Folder; we can derive the stored path.
|
||||
hash_for_path: Optional[str] = None
|
||||
if isinstance(file_identifier, str) and len(file_identifier) == 64:
|
||||
hash_for_path = file_identifier
|
||||
elif f_hash and isinstance(f_hash, str) and len(f_hash) == 64:
|
||||
hash_for_path = f_hash
|
||||
if hash_for_path:
|
||||
suffix = media_path.suffix if media_path else ""
|
||||
filename = f"{hash_for_path}{suffix}" if suffix else hash_for_path
|
||||
location_path = getattr(backend, "_location", None)
|
||||
if location_path:
|
||||
stored_path = str(Path(location_path) / filename)
|
||||
else:
|
||||
maybe_path = backend.get_file(file_identifier)
|
||||
if isinstance(maybe_path, Path):
|
||||
stored_path = str(maybe_path)
|
||||
@@ -2050,7 +2090,9 @@ class Add_File(Cmdlet):
|
||||
pass
|
||||
else:
|
||||
try:
|
||||
backend.add_url(resolved_hash, list(url))
|
||||
# Folder.add_file already persists URLs, avoid extra DB traffic here.
|
||||
if not is_folder_backend:
|
||||
backend.add_url(resolved_hash, list(url))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@@ -2107,7 +2149,8 @@ class Add_File(Cmdlet):
|
||||
meta: Dict[str,
|
||||
Any] = {}
|
||||
try:
|
||||
meta = backend.get_metadata(resolved_hash) or {}
|
||||
if not is_folder_backend:
|
||||
meta = backend.get_metadata(resolved_hash) or {}
|
||||
except Exception:
|
||||
meta = {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user