This commit is contained in:
nose
2025-12-11 19:04:02 -08:00
parent 6863c6c7ea
commit 16d8a763cd
103 changed files with 4759 additions and 9156 deletions

View File

@@ -9,9 +9,9 @@ import re
import json
import sys
from helper.logger import log, debug
from SYS.logger import log, debug
from ._shared import Cmdlet, CmdletArg, get_origin, get_field, should_show_help
from ._shared import Cmdlet, CmdletArg, get_field, should_show_help
import pipeline as ctx
# Optional dependencies
@@ -27,18 +27,18 @@ except Exception: # pragma: no cover
resolve_output_dir = None # type: ignore
try:
from helper.hydrus import HydrusClient, HydrusRequestError
from API.HydrusNetwork import HydrusClient, HydrusRequestError
except ImportError: # pragma: no cover
HydrusClient = None # type: ignore
HydrusRequestError = RuntimeError # type: ignore
try:
from helper.utils import sha256_file
from SYS.utils import sha256_file
except ImportError: # pragma: no cover
sha256_file = None # type: ignore
try:
from helper.utils_constant import mime_maps
from SYS.utils_constant import mime_maps
except ImportError: # pragma: no cover
mime_maps = {} # type: ignore
@@ -48,7 +48,7 @@ class SearchRecord:
size_bytes: int | None = None
duration_seconds: str | None = None
tags: str | None = None
hash_hex: str | None = None
hash: str | None = None
def as_dict(self) -> dict[str, str]:
payload: dict[str, str] = {"path": self.path}
@@ -58,8 +58,8 @@ class SearchRecord:
payload["duration"] = self.duration_seconds
if self.tags:
payload["tags"] = self.tags
if self.hash_hex:
payload["hash"] = self.hash_hex
if self.hash:
payload["hash"] = self.hash
return payload
@@ -115,7 +115,7 @@ class Search_Store(Cmdlet):
def _ensure_storage_columns(self, payload: Dict[str, Any]) -> Dict[str, Any]:
"""Ensure storage results have the necessary fields for result_table display."""
store_value = str(get_origin(payload, "") or "").lower()
store_value = str(payload.get("store") or "").lower()
if store_value not in STORAGE_ORIGINS:
return payload
@@ -162,7 +162,7 @@ class Search_Store(Cmdlet):
while i < len(args_list):
arg = args_list[i]
low = arg.lower()
if low in {"-store", "--store", "-storage", "--storage"} and i + 1 < len(args_list):
if low in {"-store", "--store"} and i + 1 < len(args_list):
storage_backend = args_list[i + 1]
i += 2
elif low in {"-tag", "--tag"} and i + 1 < len(args_list):
@@ -199,7 +199,7 @@ class Search_Store(Cmdlet):
log("Provide a search query", file=sys.stderr)
return 1
from helper.folder_store import FolderDB
from API.folder import API_folder_store
from config import get_local_storage_path
import uuid
worker_id = str(uuid.uuid4())
@@ -209,7 +209,7 @@ class Search_Store(Cmdlet):
return 1
# Use context manager to ensure database is always closed
with FolderDB(library_root) as db:
with API_folder_store(library_root) as db:
try:
db.insert_worker(
worker_id,
@@ -231,8 +231,8 @@ class Search_Store(Cmdlet):
table = ResultTable(table_title)
from helper.store import FileStorage
storage = FileStorage(config=config or {})
from Store import Store
storage = Store(config=config or {})
backend_to_search = storage_backend or None
if backend_to_search:
@@ -242,18 +242,21 @@ class Search_Store(Cmdlet):
log(f"Backend '{backend_to_search}' does not support searching", file=sys.stderr)
db.update_worker_status(worker_id, 'error')
return 1
results = target_backend.search_file(query, limit=limit)
results = target_backend.search_store(query, limit=limit)
else:
from helper.hydrus import is_hydrus_available
from API.HydrusNetwork import is_hydrus_available
hydrus_available = is_hydrus_available(config or {})
from Store.HydrusNetwork import HydrusNetwork
all_results = []
for backend_name in storage.list_searchable_backends():
if backend_name.startswith("hydrus") and not hydrus_available:
continue
searched_backends.append(backend_name)
try:
backend_results = storage[backend_name].search_file(query, limit=limit - len(all_results))
backend = storage[backend_name]
if isinstance(backend, HydrusNetwork) and not hydrus_available:
continue
searched_backends.append(backend_name)
backend_results = backend.search_store(query, limit=limit - len(all_results))
if backend_results:
all_results.extend(backend_results)
if len(all_results) >= limit:
@@ -270,10 +273,10 @@ class Search_Store(Cmdlet):
storage_counts: OrderedDict[str, int] = OrderedDict((name, 0) for name in searched_backends)
for item in results or []:
origin = get_origin(item)
if not origin:
store = get_field(item, "store")
if not store:
continue
key = str(origin).lower()
key = str(store).lower()
if key not in storage_counts:
storage_counts[key] = 0
storage_counts[key] += 1
@@ -295,14 +298,14 @@ class Search_Store(Cmdlet):
item_dict = _as_dict(item)
if store_filter:
origin_val = str(get_origin(item_dict) or "").lower()
if store_filter != origin_val:
store_val = str(item_dict.get("store") or "").lower()
if store_filter != store_val:
continue
normalized = self._ensure_storage_columns(item_dict)
# Make hash/store available for downstream cmdlets without rerunning search
hash_val = normalized.get("hash")
store_val = normalized.get("store") or get_origin(item_dict)
store_val = normalized.get("store") or item_dict.get("store")
if hash_val and not normalized.get("hash"):
normalized["hash"] = hash_val
if store_val and not normalized.get("store"):