fdf
This commit is contained in:
@@ -16,7 +16,11 @@ from ._shared import (
|
||||
normalize_hash,
|
||||
)
|
||||
from . import _shared as sh
|
||||
from SYS.detail_view_helpers import create_detail_view, prepare_detail_metadata
|
||||
from SYS.item_accessors import get_extension_field, get_int_field, get_result_title
|
||||
from SYS.logger import log
|
||||
from SYS.payload_builders import build_file_result_payload
|
||||
from SYS.result_publication import publish_result_table
|
||||
from SYS.result_table import Table
|
||||
from Store import Store
|
||||
from SYS import pipeline as ctx
|
||||
@@ -221,52 +225,15 @@ class Get_Url(Cmdlet):
|
||||
|
||||
@staticmethod
|
||||
def _extract_title_from_result(result: Any) -> Optional[str]:
|
||||
# Prefer explicit title field.
|
||||
# Fall back to ResultTable-style columns list.
|
||||
cols = None
|
||||
if isinstance(result, dict):
|
||||
cols = result.get("columns")
|
||||
else:
|
||||
cols = getattr(result, "columns", None)
|
||||
if isinstance(cols, list):
|
||||
for pair in cols:
|
||||
try:
|
||||
if isinstance(pair, (list, tuple)) and len(pair) == 2:
|
||||
k, v = pair
|
||||
if str(k or "").strip().lower() in {"title", "name"}:
|
||||
if isinstance(v, str) and v.strip():
|
||||
return v.strip()
|
||||
except Exception:
|
||||
continue
|
||||
return None
|
||||
return get_result_title(result, "title", "name", "filename")
|
||||
|
||||
@staticmethod
|
||||
def _extract_size_from_hit(hit: Any) -> int | None:
|
||||
for key in ("size", "file_size", "filesize", "size_bytes"):
|
||||
try:
|
||||
val = get_field(hit, key)
|
||||
except Exception:
|
||||
val = None
|
||||
if val is None:
|
||||
continue
|
||||
if isinstance(val, (int, float)):
|
||||
return int(val)
|
||||
try:
|
||||
return int(val)
|
||||
except Exception:
|
||||
continue
|
||||
return None
|
||||
return get_int_field(hit, "size", "file_size", "filesize", "size_bytes")
|
||||
|
||||
@staticmethod
|
||||
def _extract_ext_from_hit(hit: Any) -> str:
|
||||
for key in ("ext", "extension"):
|
||||
try:
|
||||
ext_val = get_field(hit, key)
|
||||
except Exception:
|
||||
ext_val = None
|
||||
if isinstance(ext_val, str) and ext_val.strip():
|
||||
return ext_val.strip().lstrip(".")
|
||||
return ""
|
||||
return get_extension_field(hit, "ext", "extension")
|
||||
|
||||
def _search_urls_across_stores(self,
|
||||
pattern: str,
|
||||
@@ -488,27 +455,25 @@ class Get_Url(Cmdlet):
|
||||
table.set_source_command("get-url", ["-url", search_pattern])
|
||||
|
||||
for item in items:
|
||||
payload: Dict[str, Any] = {
|
||||
# Keep fields for downstream cmdlets.
|
||||
"hash": item.hash,
|
||||
"store": item.store,
|
||||
"url": item.url,
|
||||
"title": item.title,
|
||||
"size": item.size,
|
||||
"ext": item.ext,
|
||||
# Force the visible table columns + ordering.
|
||||
"columns": [
|
||||
payload = build_file_result_payload(
|
||||
title=item.title,
|
||||
hash_value=item.hash,
|
||||
store=item.store,
|
||||
url=item.url,
|
||||
ext=item.ext,
|
||||
columns=[
|
||||
("Title", item.title),
|
||||
("Url", item.url),
|
||||
("Size", item.size),
|
||||
("Ext", item.ext),
|
||||
("Store", item.store),
|
||||
],
|
||||
}
|
||||
size=item.size,
|
||||
)
|
||||
display_items.append(payload)
|
||||
table.add_result(payload)
|
||||
|
||||
ctx.set_last_result_table(table if display_items else None, display_items, subject=result)
|
||||
publish_result_table(ctx, table if display_items else None, display_items, subject=result)
|
||||
|
||||
# Emit after table state is finalized to prevent side effects in TUI rendering
|
||||
for d in display_items:
|
||||
@@ -520,9 +485,11 @@ class Get_Url(Cmdlet):
|
||||
return 0
|
||||
|
||||
# Original mode: Get URLs for a specific file by hash+store
|
||||
query_hash = sh.parse_single_hash_query(parsed.get("query"))
|
||||
if parsed.get("query") and not query_hash:
|
||||
log("Error: -query must be of the form hash:<sha256>")
|
||||
query_hash, query_valid = sh.require_single_hash_query(
|
||||
parsed.get("query"),
|
||||
"Error: -query must be of the form hash:<sha256>",
|
||||
)
|
||||
if not query_valid:
|
||||
return 1
|
||||
|
||||
# Extract hash and store from result or args
|
||||
@@ -550,10 +517,9 @@ class Get_Url(Cmdlet):
|
||||
from SYS.metadata import normalize_urls
|
||||
urls = normalize_urls(urls)
|
||||
|
||||
from SYS.result_table import ItemDetailView, extract_item_metadata
|
||||
|
||||
# Prepare metadata for the detail view
|
||||
metadata = extract_item_metadata(result)
|
||||
metadata = prepare_detail_metadata(result)
|
||||
tag_values = None
|
||||
|
||||
# Enrich the metadata with tags if missing
|
||||
if not metadata.get("Tags"):
|
||||
@@ -577,24 +543,24 @@ class Get_Url(Cmdlet):
|
||||
pass
|
||||
|
||||
if row_tags:
|
||||
row_tags = sorted(list(set(row_tags)))
|
||||
metadata["Tags"] = ", ".join(row_tags)
|
||||
tag_values = sorted(list(set(row_tags)))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if file_hash:
|
||||
metadata["Hash"] = file_hash
|
||||
if store_name:
|
||||
metadata["Store"] = store_name
|
||||
|
||||
table = (
|
||||
ItemDetailView(
|
||||
"Urls",
|
||||
item_metadata=metadata,
|
||||
max_columns=1
|
||||
)._perseverance(True).set_table("url").set_value_case("preserve")
|
||||
metadata = prepare_detail_metadata(
|
||||
result,
|
||||
hash_value=file_hash,
|
||||
store=store_name,
|
||||
tags=tag_values,
|
||||
)
|
||||
|
||||
table = create_detail_view(
|
||||
"Urls",
|
||||
metadata,
|
||||
max_columns=1,
|
||||
table_name="url",
|
||||
source_command=("get-url", []),
|
||||
)
|
||||
table.set_source_command("get-url", [])
|
||||
|
||||
items: List[UrlItem] = []
|
||||
for u in list(urls or []):
|
||||
@@ -609,7 +575,7 @@ class Get_Url(Cmdlet):
|
||||
# Use overlay mode to avoid "merging" with the previous status/table state.
|
||||
# This is idiomatic for detail views and prevents the search table from being
|
||||
# contaminated by partial re-renders.
|
||||
ctx.set_last_result_table_overlay(table, items, subject=result)
|
||||
publish_result_table(ctx, table, items, subject=result, overlay=True)
|
||||
|
||||
# Emit items at the end for pipeline continuity
|
||||
for item in items:
|
||||
|
||||
Reference in New Issue
Block a user