fixed some tests
This commit is contained in:
@@ -4,7 +4,12 @@ from fastapi import APIRouter, Depends, HTTPException, status
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from src.core.entities.series import Serie
|
||||
from src.server.utils.dependencies import get_series_app, require_auth
|
||||
from src.server.services.anime_service import AnimeService, AnimeServiceError
|
||||
from src.server.utils.dependencies import (
|
||||
get_anime_service,
|
||||
get_series_app,
|
||||
require_auth,
|
||||
)
|
||||
|
||||
router = APIRouter(prefix="/api/anime", tags=["anime"])
|
||||
|
||||
@@ -224,63 +229,34 @@ async def list_anime(
|
||||
@router.post("/rescan")
|
||||
async def trigger_rescan(
|
||||
_auth: dict = Depends(require_auth),
|
||||
series_app: Any = Depends(get_series_app),
|
||||
anime_service: AnimeService = Depends(get_anime_service),
|
||||
) -> dict:
|
||||
"""Kick off a rescan of the local library.
|
||||
|
||||
Args:
|
||||
_auth: Ensures the caller is authenticated (value unused)
|
||||
series_app: Core `SeriesApp` instance provided via dependency.
|
||||
anime_service: AnimeService instance provided via dependency.
|
||||
|
||||
Returns:
|
||||
Dict[str, Any]: Status payload with scan results including
|
||||
number of series found.
|
||||
Dict[str, Any]: Status payload confirming scan started
|
||||
|
||||
Raises:
|
||||
HTTPException: If the rescan command is unsupported or fails.
|
||||
HTTPException: If the rescan command fails.
|
||||
"""
|
||||
try:
|
||||
# SeriesApp.ReScan expects a callback; pass a no-op
|
||||
if hasattr(series_app, "ReScan"):
|
||||
result = series_app.ReScan(lambda *args, **kwargs: None)
|
||||
|
||||
# Handle cases where ReScan might not return anything
|
||||
if result is None:
|
||||
# If no result, assume success
|
||||
return {
|
||||
"success": True,
|
||||
"message": "Rescan completed successfully",
|
||||
"series_count": 0
|
||||
}
|
||||
elif hasattr(result, 'success') and result.success:
|
||||
series_count = (
|
||||
result.data.get("series_count", 0)
|
||||
if result.data else 0
|
||||
)
|
||||
return {
|
||||
"success": True,
|
||||
"message": result.message,
|
||||
"series_count": series_count
|
||||
}
|
||||
elif hasattr(result, 'success'):
|
||||
return {
|
||||
"success": False,
|
||||
"message": result.message
|
||||
}
|
||||
else:
|
||||
# Result exists but has no success attribute
|
||||
return {
|
||||
"success": True,
|
||||
"message": "Rescan completed",
|
||||
"series_count": 0
|
||||
}
|
||||
|
||||
# Use the async rescan method from AnimeService
|
||||
# Progress tracking is handled automatically via event handlers
|
||||
await anime_service.rescan()
|
||||
|
||||
return {
|
||||
"success": True,
|
||||
"message": "Rescan started successfully",
|
||||
}
|
||||
except AnimeServiceError as e:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_501_NOT_IMPLEMENTED,
|
||||
detail="Rescan not available",
|
||||
)
|
||||
except HTTPException:
|
||||
raise
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail=f"Rescan failed: {str(e)}",
|
||||
) from e
|
||||
except Exception as exc:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
|
||||
Reference in New Issue
Block a user