This commit is contained in:
nose
2025-12-19 02:29:42 -08:00
parent d637532237
commit 52cf3f5c9f
24 changed files with 1284 additions and 176 deletions

View File

@@ -39,14 +39,26 @@ class SearchResult:
}
class SearchProvider(ABC):
"""Base class for search providers."""
class Provider(ABC):
"""Unified provider base class.
This replaces the older split between "search providers" and "file providers".
Concrete providers may implement any subset of:
- search(query, ...)
- download(result, output_dir)
- upload(file_path, ...)
- login(...)
- validate()
"""
def __init__(self, config: Optional[Dict[str, Any]] = None):
self.config = config or {}
self.name = self.__class__.__name__.lower()
@abstractmethod
# Standard lifecycle/auth hook.
def login(self, **_kwargs: Any) -> bool:
return True
def search(
self,
query: str,
@@ -55,30 +67,46 @@ class SearchProvider(ABC):
**kwargs: Any,
) -> List[SearchResult]:
"""Search for items matching the query."""
raise NotImplementedError(f"Provider '{self.name}' does not support search")
def download(self, result: SearchResult, output_dir: Path) -> Optional[Path]:
"""Download an item from a search result."""
return None
def upload(self, file_path: str, **kwargs: Any) -> str:
"""Upload a file and return a URL or identifier."""
raise NotImplementedError(f"Provider '{self.name}' does not support upload")
def validate(self) -> bool:
"""Check if provider is available and properly configured."""
return True
def selector(self, selected_items: List[Any], *, ctx: Any, stage_is_last: bool = True, **_kwargs: Any) -> bool:
"""Optional hook for handling `@N` selection semantics.
class FileProvider(ABC):
"""Base class for file upload providers."""
The CLI can delegate selection behavior to a provider/store instead of
applying the default selection filtering.
def __init__(self, config: Optional[Dict[str, Any]] = None):
self.config = config or {}
self.name = self.__class__.__name__.lower()
Return True if the selection was handled and default behavior should be skipped.
"""
@abstractmethod
def upload(self, file_path: str, **kwargs: Any) -> str:
"""Upload a file and return the URL."""
_ = selected_items
_ = ctx
_ = stage_is_last
return False
def validate(self) -> bool:
"""Check if provider is available/configured."""
return True
class SearchProvider(Provider):
"""Compatibility alias for older code.
Prefer inheriting from Provider directly.
"""
class FileProvider(Provider):
"""Compatibility alias for older code.
Prefer inheriting from Provider directly.
"""