fdf
This commit is contained in:
@@ -12,7 +12,9 @@ from urllib.parse import urlparse
|
||||
from SYS import models
|
||||
from SYS import pipeline as ctx
|
||||
from SYS.logger import log, debug, is_debug_enabled
|
||||
from SYS.payload_builders import build_table_result_payload
|
||||
from SYS.pipeline_progress import PipelineProgress
|
||||
from SYS.result_publication import overlay_existing_result_table, publish_result_table
|
||||
from SYS.utils_constant import ALL_SUPPORTED_EXTENSIONS
|
||||
from Store import Store
|
||||
from API.HTTP import _download_direct_file
|
||||
@@ -444,27 +446,18 @@ class Add_File(Cmdlet):
|
||||
ext = str(file_info.get("ext") or "").lstrip(".")
|
||||
size = file_info.get("size", 0)
|
||||
|
||||
row_item = {
|
||||
"path":
|
||||
str(p) if p is not None else "",
|
||||
"hash":
|
||||
hp,
|
||||
"title":
|
||||
clean_title,
|
||||
"columns": [
|
||||
("Title",
|
||||
clean_title),
|
||||
("Hash",
|
||||
hp),
|
||||
("Size",
|
||||
size),
|
||||
("Ext",
|
||||
ext),
|
||||
row_item = build_table_result_payload(
|
||||
title=clean_title,
|
||||
columns=[
|
||||
("Title", clean_title),
|
||||
("Hash", hp),
|
||||
("Size", size),
|
||||
("Ext", ext),
|
||||
],
|
||||
# Used by @N replay (CLI will combine selected rows into -path file1,file2,...)
|
||||
"_selection_args": ["-path",
|
||||
str(p) if p is not None else ""],
|
||||
}
|
||||
selection_args=["-path", str(p) if p is not None else ""],
|
||||
path=str(p) if p is not None else "",
|
||||
hash=hp,
|
||||
)
|
||||
rows.append(row_item)
|
||||
table.add_result(row_item)
|
||||
|
||||
@@ -537,8 +530,7 @@ class Add_File(Cmdlet):
|
||||
else:
|
||||
pipe_obj.extra = {}
|
||||
|
||||
merged_urls.extend(cli_urls)
|
||||
merged_urls = normalize_urls(merged_urls)
|
||||
merged_urls = sh.merge_urls(merged_urls, cli_urls)
|
||||
if merged_urls:
|
||||
pipe_obj.extra["url"] = merged_urls
|
||||
except Exception:
|
||||
@@ -827,13 +819,15 @@ class Add_File(Cmdlet):
|
||||
except Exception as exc:
|
||||
debug(f"[add-file] Item details render failed: {exc}")
|
||||
|
||||
ctx.set_last_result_table_overlay(
|
||||
publish_result_table(
|
||||
ctx,
|
||||
table,
|
||||
items,
|
||||
subject={
|
||||
"store": store,
|
||||
"hash": hashes
|
||||
}
|
||||
},
|
||||
overlay=True,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
@@ -1673,7 +1667,7 @@ class Add_File(Cmdlet):
|
||||
table = Table("Result")
|
||||
table.add_result(payload)
|
||||
# Overlay so @1 refers to this add-file result without overwriting search history
|
||||
ctx.set_last_result_table_overlay(table, [payload], subject=payload)
|
||||
publish_result_table(ctx, table, [payload], subject=payload, overlay=True)
|
||||
except Exception:
|
||||
# If table rendering fails, still keep @ selection items
|
||||
try:
|
||||
@@ -1734,15 +1728,13 @@ class Add_File(Cmdlet):
|
||||
try:
|
||||
table = ctx.get_last_result_table()
|
||||
items = ctx.get_last_result_items()
|
||||
if table is not None and items:
|
||||
ctx.set_last_result_table_overlay(
|
||||
table,
|
||||
items,
|
||||
subject={
|
||||
"store": store,
|
||||
"hash": hash_value
|
||||
}
|
||||
)
|
||||
overlay_existing_result_table(
|
||||
ctx,
|
||||
subject={
|
||||
"store": store,
|
||||
"hash": hash_value
|
||||
},
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@@ -2484,58 +2476,36 @@ class Add_File(Cmdlet):
|
||||
if not pairs:
|
||||
continue
|
||||
try:
|
||||
backend = store[backend_name]
|
||||
backend, store, _exc = sh.get_store_backend(
|
||||
config,
|
||||
backend_name,
|
||||
store_registry=store,
|
||||
)
|
||||
if backend is None:
|
||||
continue
|
||||
|
||||
items = sh.coalesce_hash_value_pairs(pairs)
|
||||
if not items:
|
||||
continue
|
||||
|
||||
bulk = getattr(backend, "add_url_bulk", None)
|
||||
if callable(bulk):
|
||||
try:
|
||||
bulk(items)
|
||||
continue
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
single = getattr(backend, "add_url", None)
|
||||
if callable(single):
|
||||
for h, u in items:
|
||||
try:
|
||||
single(h, u)
|
||||
except Exception:
|
||||
continue
|
||||
except Exception:
|
||||
continue
|
||||
|
||||
# Merge URLs per hash and de-duplicate.
|
||||
merged: Dict[str,
|
||||
List[str]] = {}
|
||||
for file_hash, urls in pairs:
|
||||
h = str(file_hash or "").strip().lower()
|
||||
if len(h) != 64:
|
||||
continue
|
||||
url_list: List[str] = []
|
||||
try:
|
||||
for u in urls or []:
|
||||
s = str(u or "").strip()
|
||||
if s:
|
||||
url_list.append(s)
|
||||
except Exception:
|
||||
url_list = []
|
||||
if not url_list:
|
||||
continue
|
||||
|
||||
bucket = merged.setdefault(h, [])
|
||||
seen = set(bucket)
|
||||
for u in url_list:
|
||||
if u in seen:
|
||||
continue
|
||||
seen.add(u)
|
||||
bucket.append(u)
|
||||
|
||||
items: List[tuple[str,
|
||||
List[str]]] = [(h,
|
||||
u) for h, u in merged.items() if u]
|
||||
if not items:
|
||||
continue
|
||||
|
||||
bulk = getattr(backend, "add_url_bulk", None)
|
||||
if callable(bulk):
|
||||
try:
|
||||
bulk(items)
|
||||
continue
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
single = getattr(backend, "add_url", None)
|
||||
if callable(single):
|
||||
for h, u in items:
|
||||
try:
|
||||
single(h, u)
|
||||
except Exception:
|
||||
continue
|
||||
|
||||
@staticmethod
|
||||
def _apply_pending_tag_associations(
|
||||
pending: Dict[str,
|
||||
@@ -2552,30 +2522,15 @@ class Add_File(Cmdlet):
|
||||
except Exception:
|
||||
return
|
||||
|
||||
for backend_name, pairs in (pending or {}).items():
|
||||
if not pairs:
|
||||
continue
|
||||
try:
|
||||
backend = store[backend_name]
|
||||
except Exception:
|
||||
continue
|
||||
|
||||
# Try bulk variant first
|
||||
bulk = getattr(backend, "add_tags_bulk", None)
|
||||
if callable(bulk):
|
||||
try:
|
||||
bulk([(h, t) for h, t in pairs])
|
||||
continue
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
single = getattr(backend, "add_tag", None)
|
||||
if callable(single):
|
||||
for h, t in pairs:
|
||||
try:
|
||||
single(h, t)
|
||||
except Exception:
|
||||
continue
|
||||
sh.run_store_hash_value_batches(
|
||||
config,
|
||||
pending or {},
|
||||
bulk_method_name="add_tags_bulk",
|
||||
single_method_name="add_tag",
|
||||
store_registry=store,
|
||||
pass_config_to_bulk=False,
|
||||
pass_config_to_single=False,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _load_sidecar_bundle(
|
||||
|
||||
Reference in New Issue
Block a user