mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-24 22:52:12 -03:00
feat(routes): extract orchestration use cases
This commit is contained in:
37
py/services/use_cases/download_model_use_case.py
Normal file
37
py/services/use_cases/download_model_use_case.py
Normal file
@@ -0,0 +1,37 @@
|
||||
"""Use case for scheduling model downloads with consistent error handling."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Dict
|
||||
|
||||
from ..download_coordinator import DownloadCoordinator
|
||||
|
||||
|
||||
class DownloadModelValidationError(ValueError):
|
||||
"""Raised when incoming payload validation fails."""
|
||||
|
||||
|
||||
class DownloadModelEarlyAccessError(RuntimeError):
|
||||
"""Raised when the download is gated behind Civitai early access."""
|
||||
|
||||
|
||||
class DownloadModelUseCase:
|
||||
"""Coordinate download scheduling through the coordinator service."""
|
||||
|
||||
def __init__(self, *, download_coordinator: DownloadCoordinator) -> None:
|
||||
self._download_coordinator = download_coordinator
|
||||
|
||||
async def execute(self, payload: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""Schedule a download and normalize error conditions."""
|
||||
|
||||
try:
|
||||
return await self._download_coordinator.schedule_download(payload)
|
||||
except ValueError as exc:
|
||||
raise DownloadModelValidationError(str(exc)) from exc
|
||||
except Exception as exc: # pragma: no cover - defensive logging path
|
||||
message = str(exc)
|
||||
if "401" in message:
|
||||
raise DownloadModelEarlyAccessError(
|
||||
"Early Access Restriction: This model requires purchase. Please buy early access on Civitai.com."
|
||||
) from exc
|
||||
raise
|
||||
Reference in New Issue
Block a user