from fastapi import APIRouter, BackgroundTasks from app.scan_state import scan_state from app.services.scanner import run_scan router = APIRouter() def _run_scan_sync(): import asyncio asyncio.run(run_scan()) @router.post("/scan", status_code=202) async def trigger_scan(background_tasks: BackgroundTasks): if scan_state.status == "scanning": return {"message": "Scan déjà en cours", **scan_state.to_dict()} background_tasks.add_task(run_scan) return {"message": "Scan lancé", **scan_state.to_dict()}