updated plugin refactor and added FTP and SCP plugins , also hydrusnetwork plugin migration
This commit is contained in:
+25
-96
@@ -7,9 +7,9 @@ import sys
|
||||
from pathlib import Path
|
||||
|
||||
from SYS.logger import debug, log
|
||||
from ProviderCore.registry import get_plugin
|
||||
from Store import Store
|
||||
from . import _shared as sh
|
||||
from API import HydrusNetwork as hydrus_wrapper
|
||||
from SYS import pipeline as ctx
|
||||
from SYS.result_table_helpers import add_row_columns
|
||||
from SYS.result_table import Table, _format_size
|
||||
@@ -129,6 +129,7 @@ class Delete_File(sh.Cmdlet):
|
||||
store = sh.get_field(item, "store")
|
||||
|
||||
store_lower = str(store).lower() if store else ""
|
||||
hydrus_provider = get_plugin("hydrusnetwork", config)
|
||||
|
||||
backend = None
|
||||
try:
|
||||
@@ -144,18 +145,17 @@ class Delete_File(sh.Cmdlet):
|
||||
# so checking only the store name is unreliable.
|
||||
is_hydrus_store = False
|
||||
try:
|
||||
if backend is not None:
|
||||
from Store.HydrusNetwork import HydrusNetwork as HydrusStore
|
||||
|
||||
is_hydrus_store = isinstance(backend, HydrusStore)
|
||||
if hydrus_provider is not None and backend is not None:
|
||||
is_hydrus_store = bool(hydrus_provider.is_backend(backend, str(store or "")))
|
||||
except Exception:
|
||||
is_hydrus_store = False
|
||||
|
||||
# Backwards-compatible fallback heuristic (older items might only carry a name).
|
||||
if ((not is_hydrus_store) and bool(store_lower)
|
||||
and ("hydrus" in store_lower or store_lower in {"home",
|
||||
"work"})):
|
||||
is_hydrus_store = True
|
||||
if (not is_hydrus_store) and hydrus_provider is not None and bool(store_lower):
|
||||
try:
|
||||
is_hydrus_store = bool(hydrus_provider.is_store_name(store_lower))
|
||||
except Exception:
|
||||
is_hydrus_store = False
|
||||
store_label = str(store) if store else "default"
|
||||
hydrus_prefix = f"[hydrusnetwork:{store_label}]"
|
||||
|
||||
@@ -318,18 +318,20 @@ class Delete_File(sh.Cmdlet):
|
||||
should_try_hydrus = False
|
||||
|
||||
if should_try_hydrus and hash_hex:
|
||||
# Prefer deleting via the resolved store backend when it is a HydrusNetwork store.
|
||||
# This ensures store-specific post-delete hooks run (e.g., clearing Hydrus deletion records).
|
||||
did_backend_delete = False
|
||||
did_hydrus_delete = False
|
||||
try:
|
||||
if backend is not None:
|
||||
deleter = getattr(backend, "delete_file", None)
|
||||
if callable(deleter):
|
||||
did_backend_delete = bool(deleter(hash_hex, reason=reason))
|
||||
if hydrus_provider is not None:
|
||||
did_hydrus_delete = bool(
|
||||
hydrus_provider.delete_hash(
|
||||
hash_hex,
|
||||
store_name=str(store) if store else None,
|
||||
reason=reason or None,
|
||||
)
|
||||
)
|
||||
except Exception:
|
||||
did_backend_delete = False
|
||||
did_hydrus_delete = False
|
||||
|
||||
if did_backend_delete:
|
||||
if did_hydrus_delete:
|
||||
hydrus_deleted = True
|
||||
title_str = str(title_val).strip() if title_val else ""
|
||||
if title_str:
|
||||
@@ -340,85 +342,12 @@ class Delete_File(sh.Cmdlet):
|
||||
else:
|
||||
debug(f"{hydrus_prefix} Deleted hash:{hash_hex}", file=sys.stderr)
|
||||
else:
|
||||
# Fallback to direct client calls.
|
||||
client = None
|
||||
if store:
|
||||
# Store specified: do not fall back to a global/default Hydrus client.
|
||||
try:
|
||||
registry = Store(config)
|
||||
backend = registry[str(store)]
|
||||
candidate = getattr(backend, "_client", None)
|
||||
if candidate is not None and hasattr(candidate, "_post"):
|
||||
client = candidate
|
||||
except Exception as exc:
|
||||
if not local_deleted:
|
||||
log(
|
||||
f"Hydrus client unavailable for store '{store}': {exc}",
|
||||
file=sys.stderr,
|
||||
)
|
||||
return False
|
||||
if client is None:
|
||||
if not local_deleted:
|
||||
log(
|
||||
f"Hydrus client unavailable for store '{store}'",
|
||||
file=sys.stderr
|
||||
)
|
||||
return False
|
||||
else:
|
||||
# No store context; use default Hydrus client.
|
||||
try:
|
||||
client = hydrus_wrapper.get_client(config)
|
||||
except Exception as exc:
|
||||
if not local_deleted:
|
||||
log(f"Hydrus client unavailable: {exc}", file=sys.stderr)
|
||||
return False
|
||||
if client is None:
|
||||
if not local_deleted:
|
||||
log("Hydrus client unavailable", file=sys.stderr)
|
||||
return False
|
||||
|
||||
payload: Dict[str,
|
||||
Any] = {
|
||||
"hashes": [hash_hex]
|
||||
}
|
||||
if reason:
|
||||
payload["reason"] = reason
|
||||
try:
|
||||
client._post(
|
||||
"/add_files/delete_files",
|
||||
data=payload
|
||||
) # type: ignore[attr-defined]
|
||||
# Best-effort clear deletion record if supported by this client.
|
||||
try:
|
||||
clearer = getattr(client, "clear_file_deletion_record", None)
|
||||
if callable(clearer):
|
||||
clearer([hash_hex])
|
||||
else:
|
||||
client._post(
|
||||
"/add_files/clear_file_deletion_record",
|
||||
data={
|
||||
"hashes": [hash_hex]
|
||||
}
|
||||
) # type: ignore[attr-defined]
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
hydrus_deleted = True
|
||||
title_str = str(title_val).strip() if title_val else ""
|
||||
if title_str:
|
||||
debug(
|
||||
f"{hydrus_prefix} Deleted title:{title_str} hash:{hash_hex}",
|
||||
file=sys.stderr,
|
||||
)
|
||||
if not local_deleted:
|
||||
if store:
|
||||
log(f"Hydrus store unavailable for '{store}'", file=sys.stderr)
|
||||
else:
|
||||
debug(
|
||||
f"{hydrus_prefix} Deleted hash:{hash_hex}",
|
||||
file=sys.stderr
|
||||
)
|
||||
except Exception:
|
||||
# If it's not in Hydrus (e.g. 404 or similar), that's fine
|
||||
if not local_deleted:
|
||||
return []
|
||||
log("Hydrus delete failed", file=sys.stderr)
|
||||
return []
|
||||
|
||||
if hydrus_deleted and hash_hex:
|
||||
size_hint = None
|
||||
|
||||
Reference in New Issue
Block a user