Files
tidal-dl-ng-webui/app/routers/download.py
2025-12-02 14:07:35 +01:00

41 lines
1.4 KiB
Python

from fastapi import APIRouter, Request, HTTPException
from fastapi.responses import JSONResponse
from app.services.download_manager import DownloadManager
router = APIRouter(prefix="/download", tags=["download"])
download_manager = DownloadManager()
@router.post("/")
async def add_download(request: Request):
data = await request.json()
item_type = data.get("type")
item_id = data.get("id")
if not item_type or not item_id:
raise HTTPException(status_code=400, detail="Missing type or id")
task = download_manager.add_to_queue(item_type, item_id)
return JSONResponse(task)
@router.get("/queue")
async def get_queue():
return download_manager.get_queue()
@router.post("/cancel/{task_id}")
async def cancel_download(task_id: str):
if download_manager.cancel_task(task_id):
return {"status": "success", "message": "Task cancelled"}
raise HTTPException(status_code=404, detail="Task not found")
@router.post("/pause/{task_id}")
async def pause_download(task_id: str):
if download_manager.pause_task(task_id):
return {"status": "success", "message": "Task paused"}
raise HTTPException(status_code=404, detail="Task not found")
@router.post("/resume/{task_id}")
async def resume_download(task_id: str):
if download_manager.resume_task(task_id):
return {"status": "success", "message": "Task resumed"}
raise HTTPException(status_code=404, detail="Task not found")