Backend: endpoint for single output download added

This commit is contained in:
2026-08-03 10:53:13 +05:00
parent e23b0f44ce
commit 1d1f8563c0
+31 -2
View File
@@ -29,7 +29,6 @@ def _prepare_download(task_id: str):
raise HTTPException(status_code=404, detail="No output files found")
zip_path = settings.temp_dir / task_id / "splits.zip"
# Create ZIP if not already exists (or overwrite)
with ZipFile(zip_path, "w") as zipf:
for file_path in output_dir.iterdir():
if file_path.is_file():
@@ -58,4 +57,34 @@ async def download_results_as_zip(task_id: str):
media_type="application/zip",
filename="splits.zip",
headers={"Content-Disposition": "attachment; filename=splits.zip"}
)
)
# NEW: Endpoint for downloading individual tracks
@router.get("/download/{task_id}/{filename}")
async def download_single_track(task_id: str, filename: str):
"""
Download a single track file from the output directory.
"""
if not task_manager.has_task(task_id):
raise HTTPException(status_code=404, detail=f"Task {task_id} not found")
status = task_manager.get_status(task_id)
if status["status"] != TaskStatus.DONE:
raise HTTPException(
status_code=400,
detail=f"Task {task_id} is not complete. Current status: {status['status']}"
)
output_dir = settings.temp_dir / task_id / "output"
file_path = output_dir / filename
if not file_path.exists() or not file_path.is_file():
raise HTTPException(status_code=404, detail=f"File '{filename}' not found")
return FileResponse(
path=file_path,
filename=filename,
media_type="application/octet-stream",
headers={"Content-Disposition": f"attachment; filename={filename}"}
)