feat(setup): separate NFO scan into dedicated phase
- Add /nfo-scan-phase endpoint to trigger NFO scan independently - Move NFO scan out of initial setup into separate post-unresolved phase - Add phase query param handling for /loading page (?phase=initial, ?phase=nfo) - Update setup redirect middleware to handle phase-based redirects - Update auth setup to pass phase=initial to loading page
This commit is contained in:
@@ -208,8 +208,9 @@ async def setup_auth(req: SetupRequest):
|
||||
# Start initialization in background
|
||||
asyncio.create_task(run_initialization())
|
||||
|
||||
# Return redirect to loading page
|
||||
return {"status": "ok", "redirect": "/loading"}
|
||||
# Return redirect to loading page with phase=initial
|
||||
# The loading page will show ONLY series_sync step, then redirect to /setup/unresolved
|
||||
return {"status": "ok", "redirect": "/loading?phase=initial"}
|
||||
# Note: Media scan is skipped during setup as it requires
|
||||
# background_loader service which is only available during
|
||||
# application lifespan. It will run on first application startup.
|
||||
|
||||
@@ -373,4 +373,51 @@ async def complete_unresolved_folders(
|
||||
status="success",
|
||||
message=f"Marked {count} folders as handled. Unresolved phase completed.",
|
||||
count=count,
|
||||
)
|
||||
|
||||
|
||||
class NfoScanPhaseResponse(BaseModel):
|
||||
"""Response model for NFO scan phase trigger."""
|
||||
status: str = Field(..., description="Status of the operation")
|
||||
message: str = Field(..., description="Human-readable message")
|
||||
|
||||
|
||||
@router.post("/nfo-scan-phase", response_model=NfoScanPhaseResponse)
|
||||
async def trigger_nfo_scan_phase() -> NfoScanPhaseResponse:
|
||||
"""Trigger the NFO scan phase.
|
||||
|
||||
This endpoint is called by the loading page when accessed with ?phase=nfo.
|
||||
It starts the NFO scan in the background and returns immediately.
|
||||
The loading page then connects via WebSocket to receive progress updates.
|
||||
|
||||
Returns:
|
||||
NfoScanPhaseResponse with status and message
|
||||
"""
|
||||
import asyncio
|
||||
|
||||
from src.server.services.initialization_service import perform_nfo_scan_phase
|
||||
from src.server.services.progress_service import get_progress_service
|
||||
|
||||
progress_service = get_progress_service()
|
||||
|
||||
async def run_nfo_scan():
|
||||
"""Run NFO scan phase with progress updates."""
|
||||
try:
|
||||
await perform_nfo_scan_phase(progress_service)
|
||||
logger.info("NFO scan phase completed via API trigger")
|
||||
except Exception as e:
|
||||
logger.error("NFO scan phase failed: %s", e, exc_info=True)
|
||||
if progress_service:
|
||||
await progress_service.fail_progress(
|
||||
progress_id="nfo_scan",
|
||||
error_message=f"NFO scan failed: {str(e)}",
|
||||
metadata={"step_id": "nfo_scan", "phase": "nfo"}
|
||||
)
|
||||
|
||||
# Start NFO scan in background
|
||||
asyncio.create_task(run_nfo_scan())
|
||||
|
||||
return NfoScanPhaseResponse(
|
||||
status="started",
|
||||
message="NFO scan phase started. Check progress via WebSocket."
|
||||
)
|
||||
Reference in New Issue
Block a user