refactor(download): remove ProviderCore/download.py, move sanitize_filename to SYS.utils, replace callers to use API.HTTP.HTTPClient

This commit is contained in:
2026-01-06 01:38:59 -08:00
parent 3b363dd536
commit 41c11d39fd
38 changed files with 2640 additions and 526 deletions

View File

@@ -1,5 +1,6 @@
from __future__ import annotations
import sys
from typing import Any, Dict, List, Sequence
from . import _shared as sh
from SYS.logger import log, debug
@@ -89,28 +90,22 @@ def _run(result: Any, args: Sequence[str], config: Dict[str, Any]) -> int:
log("No input provided to select; pipe provider-table output or use a cmdlet that emits items.", file=sys.stderr)
return 1
first_src = inputs[0].get("source") if isinstance(inputs[0], dict) else None
if not first_src:
log("Input items must include 'source' to resolve provider for selection.", file=sys.stderr)
return 1
try:
provider = get_provider(first_src)
except Exception:
log(f"Unknown provider: {first_src}", file=sys.stderr)
return 1
# Model-ize items
rows = [_dict_to_result_model(item if isinstance(item, dict) else item) for item in inputs]
# Attempt to detect provider from first item
provider = None
first_src = inputs[0].get("source") if isinstance(inputs[0], dict) else None
if first_src:
try:
provider = get_provider(first_src)
except Exception:
provider = None
# Columns: ask provider for column spec if available, else build minimal columns
if provider:
cols = provider.get_columns(rows)
else:
# Minimal columns built from available keys
from SYS.result_table_api import title_column, ext_column
cols = [title_column()]
if any(r.ext for r in rows):
cols.append(ext_column())
# Columns: provider must supply them (no legacy defaults)
cols = provider.get_columns(rows)
# Render table to console
try:
@@ -172,26 +167,19 @@ def _run(result: Any, args: Sequence[str], config: Dict[str, Any]) -> int:
"source": raw.source,
}
else:
# try to call to_dict or fallback
try:
selected = raw.to_dict()
except Exception:
selected = {"title": getattr(raw, "title", str(raw))}
# Ensure selection args exist
# Ensure selection args exist using provider's selector only
if not selected.get("_selection_args"):
if provider:
try:
sel_args = provider.selection_args(rows[idx])
selected["_selection_args"] = sel_args
except Exception:
selected["_selection_args"] = []
else:
# fallback
if selected.get("path"):
selected["_selection_args"] = ["-path", selected.get("path")]
else:
selected["_selection_args"] = ["-title", selected.get("title") or ""]
try:
sel_args = provider.selection_args(rows[idx])
selected["_selection_args"] = sel_args
except Exception:
log("Selection args missing and provider selector failed.", file=sys.stderr)
return 1
selected_items.append(selected)
except Exception: