fix download
This commit is contained in:
@@ -208,6 +208,40 @@ async def clear_completed(
|
||||
)
|
||||
|
||||
|
||||
@router.delete("/failed", status_code=status.HTTP_200_OK)
|
||||
async def clear_failed(
|
||||
_: dict = Depends(require_auth),
|
||||
download_service: DownloadService = Depends(get_download_service),
|
||||
):
|
||||
"""Clear failed downloads from history.
|
||||
|
||||
Removes all failed download items from the queue history. This helps
|
||||
keep the queue display clean and manageable.
|
||||
|
||||
Requires authentication.
|
||||
|
||||
Returns:
|
||||
dict: Status message with count of cleared items
|
||||
|
||||
Raises:
|
||||
HTTPException: 401 if not authenticated, 500 on service error
|
||||
"""
|
||||
try:
|
||||
cleared_count = await download_service.clear_failed()
|
||||
|
||||
return {
|
||||
"status": "success",
|
||||
"message": f"Cleared {cleared_count} failed item(s)",
|
||||
"count": cleared_count,
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail=f"Failed to clear failed items: {str(e)}",
|
||||
)
|
||||
|
||||
|
||||
@router.delete("/{item_id}", status_code=status.HTTP_204_NO_CONTENT)
|
||||
async def remove_from_queue(
|
||||
item_id: str = Path(..., description="Download item ID to remove"),
|
||||
@@ -485,28 +519,50 @@ async def reorder_queue(
|
||||
_: dict = Depends(require_auth),
|
||||
download_service: DownloadService = Depends(get_download_service),
|
||||
):
|
||||
"""Reorder an item in the pending queue.
|
||||
"""Reorder items in the pending queue.
|
||||
|
||||
Changes the position of a pending download item in the queue. This only
|
||||
affects items that haven't started downloading yet. The position is
|
||||
0-based.
|
||||
Changes the order of pending download items in the queue. This only
|
||||
affects items that haven't started downloading yet. Supports both
|
||||
bulk reordering with item_ids array and single item reorder.
|
||||
|
||||
Requires authentication.
|
||||
|
||||
Args:
|
||||
request: Item ID and new position in queue
|
||||
request: Either {"item_ids": ["id1", "id2", ...]} for bulk reorder
|
||||
or {"item_id": "id", "new_position": 0} for single item
|
||||
|
||||
Returns:
|
||||
dict: Status message indicating item has been reordered
|
||||
dict: Status message indicating items have been reordered
|
||||
|
||||
Raises:
|
||||
HTTPException: 401 if not authenticated, 404 if item not found,
|
||||
400 for invalid request, 500 on service error
|
||||
"""
|
||||
try:
|
||||
# Support legacy bulk reorder payload used by some integration tests:
|
||||
# {"item_order": ["id1", "id2", ...]}
|
||||
if "item_order" in request:
|
||||
# Support new bulk reorder payload: {"item_ids": ["id1", "id2", ...]}
|
||||
if "item_ids" in request:
|
||||
item_order = request.get("item_ids", [])
|
||||
if not isinstance(item_order, list):
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail="item_ids must be a list of item IDs",
|
||||
)
|
||||
|
||||
success = await download_service.reorder_queue_bulk(item_order)
|
||||
|
||||
if not success:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail="One or more items in item_ids were not found in pending queue",
|
||||
)
|
||||
|
||||
return {
|
||||
"status": "success",
|
||||
"message": "Queue reordered successfully",
|
||||
}
|
||||
|
||||
# Support legacy bulk reorder payload: {"item_order": ["id1", "id2", ...]}
|
||||
elif "item_order" in request:
|
||||
item_order = request.get("item_order", [])
|
||||
if not isinstance(item_order, list):
|
||||
raise HTTPException(
|
||||
@@ -515,6 +571,17 @@ async def reorder_queue(
|
||||
)
|
||||
|
||||
success = await download_service.reorder_queue_bulk(item_order)
|
||||
|
||||
if not success:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail="One or more items in item_order were not found in pending queue",
|
||||
)
|
||||
|
||||
return {
|
||||
"status": "success",
|
||||
"message": "Queue item reordered successfully",
|
||||
}
|
||||
else:
|
||||
# Fallback to single-item reorder shape
|
||||
# Validate request
|
||||
@@ -531,25 +598,16 @@ async def reorder_queue(
|
||||
new_position=req.new_position,
|
||||
)
|
||||
|
||||
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"
|
||||
if not success:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail=f"Item {req.item_id} not found in pending queue",
|
||||
)
|
||||
else:
|
||||
detail = f"Item {req.item_id} not found in pending queue"
|
||||
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail=detail,
|
||||
)
|
||||
|
||||
return {
|
||||
"status": "success",
|
||||
"message": "Queue item reordered successfully",
|
||||
}
|
||||
return {
|
||||
"status": "success",
|
||||
"message": "Queue item reordered successfully",
|
||||
}
|
||||
|
||||
except DownloadServiceError as e:
|
||||
raise HTTPException(
|
||||
@@ -596,6 +654,7 @@ async def retry_failed(
|
||||
return {
|
||||
"status": "success",
|
||||
"message": f"Retrying {len(retried_ids)} failed item(s)",
|
||||
"retried_count": len(retried_ids),
|
||||
"retried_ids": retried_ids,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user