This commit is contained in:
2025-10-22 17:39:28 +02:00
parent 6db850c2ad
commit 5c2691b070
7 changed files with 198 additions and 181 deletions

View File

@@ -44,18 +44,34 @@ async def get_queue_status(
queue_status = await download_service.get_queue_status()
queue_stats = await download_service.get_queue_stats()
# Preserve the legacy response contract expected by the original CLI
# client and existing integration tests. Those consumers rely on the
# field names ``active``/``pending``/``completed``/``failed`` and raw
# dict payloads rather than Pydantic models, so we emit JSON-friendly
# dictionaries that mirror the historic structure.
# Preserve the legacy response contract expected by the original CLI
# client and existing integration tests. Those consumers still parse
# the bare dictionaries that the pre-FastAPI implementation emitted,
# so we keep the canonical field names (``active``/``pending``/
# ``completed``/``failed``) and dump each Pydantic object to plain
# JSON-compatible dicts instead of returning the richer
# ``QueueStatusResponse`` shape directly. This guarantees both the
# CLI and older dashboard widgets do not need schema migrations while
# the new web UI can continue to evolve independently.
status_payload = {
"is_running": queue_status.is_running,
"is_paused": queue_status.is_paused,
"active": [it.model_dump(mode="json") for it in queue_status.active_downloads],
"pending": [it.model_dump(mode="json") for it in queue_status.pending_queue],
"completed": [it.model_dump(mode="json") for it in queue_status.completed_downloads],
"failed": [it.model_dump(mode="json") for it in queue_status.failed_downloads],
"active": [
it.model_dump(mode="json")
for it in queue_status.active_downloads
],
"pending": [
it.model_dump(mode="json")
for it in queue_status.pending_queue
],
"completed": [
it.model_dump(mode="json")
for it in queue_status.completed_downloads
],
"failed": [
it.model_dump(mode="json")
for it in queue_status.failed_downloads
],
}
# Add the derived ``success_rate`` metric so dashboards built against
@@ -71,7 +87,10 @@ async def get_queue_status(
stats_payload["success_rate"] = success_rate
return JSONResponse(
content={"status": status_payload, "statistics": stats_payload}
content={
"status": status_payload,
"statistics": stats_payload,
}
)
except Exception as e:
@@ -133,7 +152,10 @@ async def add_to_queue(
"failed_items": [],
}
return JSONResponse(content=payload, status_code=status.HTTP_201_CREATED)
return JSONResponse(
content=payload,
status_code=status.HTTP_201_CREATED,
)
except DownloadServiceError as e:
raise HTTPException(
@@ -509,7 +531,10 @@ async def reorder_queue(
if not success:
# Provide an appropriate 404 message depending on request shape
if "item_order" in request:
detail = "One or more items in item_order were not found in pending queue"
detail = (
"One or more items in item_order were not "
"found in pending queue"
)
else:
detail = f"Item {req.item_id} not found in pending queue"