d
This commit is contained in:
@@ -1229,7 +1229,7 @@ class Add_File(Cmdlet):
|
||||
hash_hint = get_field(result, "hash") or get_field(result, "file_hash") or getattr(pipe_obj, "hash", None)
|
||||
return candidate, hash_hint, None
|
||||
|
||||
downloaded_path, hash_hint, tmp_dir = Add_File._maybe_download_alldebrid_result(
|
||||
downloaded_path, hash_hint, tmp_dir = Add_File._maybe_download_provider_result(
|
||||
result,
|
||||
pipe_obj,
|
||||
config,
|
||||
@@ -1257,7 +1257,7 @@ class Add_File(Cmdlet):
|
||||
return normalized
|
||||
|
||||
@staticmethod
|
||||
def _maybe_download_alldebrid_result(
|
||||
def _maybe_download_provider_result(
|
||||
result: Any,
|
||||
pipe_obj: models.PipeObject,
|
||||
config: Dict[str, Any],
|
||||
@@ -1272,19 +1272,27 @@ class Add_File(Cmdlet):
|
||||
if candidate:
|
||||
provider_key = candidate
|
||||
break
|
||||
if provider_key != "alldebrid":
|
||||
|
||||
if not provider_key:
|
||||
return None, None, None
|
||||
|
||||
try:
|
||||
from Provider.alldebrid import AllDebrid
|
||||
except Exception:
|
||||
provider = get_search_provider(provider_key, config)
|
||||
if provider is None:
|
||||
return None, None, None
|
||||
|
||||
try:
|
||||
return AllDebrid.download_for_pipe_result(result, pipe_obj, config)
|
||||
except Exception as exc:
|
||||
debug(f"[add-file] AllDebrid download helper failed: {exc}")
|
||||
return None, None, None
|
||||
# Check for specialized download helper (used by AllDebrid and potentially others)
|
||||
handler = getattr(provider, "download_for_pipe_result", None)
|
||||
if not callable(handler):
|
||||
# Fallback: check class if it's a classmethod and instance didn't have it (unlikely but safe)
|
||||
handler = getattr(type(provider), "download_for_pipe_result", None)
|
||||
|
||||
if callable(handler):
|
||||
try:
|
||||
return handler(result, pipe_obj, config)
|
||||
except Exception as exc:
|
||||
debug(f"[add-file] Provider '{provider_key}' download helper failed: {exc}")
|
||||
|
||||
return None, None, None
|
||||
|
||||
@staticmethod
|
||||
def _download_provider_source(
|
||||
@@ -2098,18 +2106,11 @@ class Add_File(Cmdlet):
|
||||
store = store_instance if store_instance is not None else Store(config)
|
||||
backend = store[backend_name]
|
||||
|
||||
hydrus_like_backend = False
|
||||
try:
|
||||
hydrus_like_backend = str(type(backend).__name__ or "").lower().startswith("hydrus")
|
||||
except Exception:
|
||||
hydrus_like_backend = False
|
||||
|
||||
is_folder_backend = False
|
||||
try:
|
||||
is_folder_backend = type(backend).__name__ == "Folder"
|
||||
except Exception:
|
||||
is_folder_backend = False
|
||||
# Use backend properties to drive metadata deferral behavior.
|
||||
is_remote_backend = getattr(backend, "is_remote", False)
|
||||
prefer_defer_tags = getattr(backend, "prefer_defer_tags", False)
|
||||
|
||||
# ...
|
||||
# Prepare metadata from pipe_obj and sidecars
|
||||
tags, url, title, f_hash = Add_File._prepare_metadata(
|
||||
result, media_path, pipe_obj, config
|
||||
@@ -2203,9 +2204,9 @@ class Add_File(Cmdlet):
|
||||
return 1
|
||||
|
||||
upload_tags = tags
|
||||
if hydrus_like_backend and upload_tags:
|
||||
if prefer_defer_tags and upload_tags:
|
||||
upload_tags = []
|
||||
debug("[add-file] Deferring tag application until after Hydrus upload")
|
||||
debug(f"[add-file] Deferring tag application for {backend_name} (backend preference)")
|
||||
|
||||
debug(
|
||||
f"[add-file] Storing into backend '{backend_name}' path='{media_path}' title='{title}' hash='{f_hash[:12] if f_hash else 'N/A'}'"
|
||||
@@ -2227,24 +2228,11 @@ class Add_File(Cmdlet):
|
||||
##log(f"✓ File added to '{backend_name}': {file_identifier}", file=sys.stderr)
|
||||
|
||||
stored_path: Optional[str] = None
|
||||
# IMPORTANT: avoid calling get_file() for remote backends.
|
||||
# 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).
|
||||
# IMPORTANT: avoid calling get_file() for remote backends by default to avoid
|
||||
# unintended network activity or credential exposure in result payloads.
|
||||
try:
|
||||
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:
|
||||
if not is_remote_backend:
|
||||
# For local backends, resolving the path is cheap and useful.
|
||||
maybe_path = backend.get_file(file_identifier)
|
||||
if isinstance(maybe_path, Path):
|
||||
stored_path = str(maybe_path)
|
||||
@@ -2275,7 +2263,7 @@ class Add_File(Cmdlet):
|
||||
# Keep hash/store for downstream commands (get-tag, get-file, etc.).
|
||||
resolved_hash = chosen_hash
|
||||
|
||||
if hydrus_like_backend and tags:
|
||||
if prefer_defer_tags and tags:
|
||||
# Support deferring tag application for batching bulk operations
|
||||
if defer_tag_association and pending_tag_associations is not None:
|
||||
try:
|
||||
@@ -2287,11 +2275,11 @@ class Add_File(Cmdlet):
|
||||
adder = getattr(backend, "add_tag", None)
|
||||
if callable(adder):
|
||||
debug(
|
||||
f"[add-file] Applying {len(tags)} tag(s) post-upload to Hydrus"
|
||||
f"[add-file] Applying {len(tags)} tag(s) post-upload to {backend_name}"
|
||||
)
|
||||
adder(resolved_hash, list(tags))
|
||||
except Exception as exc:
|
||||
log(f"[add-file] Hydrus post-upload tagging failed: {exc}", file=sys.stderr)
|
||||
log(f"[add-file] Post-upload tagging failed for {backend_name}: {exc}", file=sys.stderr)
|
||||
|
||||
# If we have url(s), ensure they get associated with the destination file.
|
||||
# This mirrors `add-url` behavior but avoids emitting extra pipeline noise.
|
||||
|
||||
Reference in New Issue
Block a user