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

@@ -7,7 +7,7 @@ renderers must use. It intentionally refuses to accept legacy dicts/strings/objs
from __future__ import annotations
from dataclasses import dataclass, field
from typing import Any, Callable, Dict, Iterable, Optional, Protocol
from typing import Any, Callable, Dict, Iterable, List, Optional, Protocol
@dataclass(frozen=True)
@@ -33,6 +33,48 @@ class ResultModel:
source: Optional[str] = None
@dataclass(frozen=True)
class ResultTable:
"""Concrete, provider-owned table of rows/columns.
This is intentionally minimal: it only stores rows, column specs, and
optional metadata used by renderers. It does not auto-normalize legacy
objects or infer columns.
"""
provider: str
rows: List[ResultModel]
columns: List[ColumnSpec]
meta: Dict[str, Any] = field(default_factory=dict)
def __post_init__(self) -> None:
if not str(self.provider or "").strip():
raise ValueError("provider required for ResultTable")
object.__setattr__(self, "rows", [ensure_result_model(r) for r in self.rows])
if not self.columns:
raise ValueError("columns are required for ResultTable")
object.__setattr__(self, "columns", list(self.columns))
object.__setattr__(self, "meta", dict(self.meta or {}))
def serialize_row(self, row: ResultModel, selection: Optional[List[str]] = None) -> Dict[str, Any]:
"""Convert a row into pipeline-friendly dict (with selection args).
Selection args must be precomputed by the provider; this method only
copies them into the serialized dict.
"""
r = ensure_result_model(row)
return {
"title": r.title,
"path": r.path,
"ext": r.ext,
"size_bytes": r.size_bytes,
"metadata": r.metadata or {},
"source": r.source or self.provider,
"_selection_args": list(selection or []),
}
@dataclass(frozen=True)
class ColumnSpec:
"""Specification for a column that renderers will use.
@@ -100,6 +142,7 @@ def metadata_column(key: str, header: Optional[str] = None, format_fn: Optional[
__all__ = [
"ResultModel",
"ResultTable",
"ColumnSpec",
"ProviderAdapter",
"Renderer",