Web interface merge #1
@@ -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():
|
||||
@@ -59,3 +58,33 @@ async def download_results_as_zip(task_id: str):
|
||||
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}"}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user