fix: Implement proper task deletion in cleanup button

- Add delete_task() method to DownloadManager that removes tasks from the task list
- Modify DELETE endpoint to use delete_task() instead of cancel_download()
- Tasks are now completely removed from the list when cleanup button is clicked

Previously, DELETE only cancelled the download but kept it in the list.
Now cancelled/failed/deleted downloads are permanently removed.

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
root
2026-01-23 11:12:29 +00:00
parent 30f79789ee
commit 3d7a17d0d7
2 changed files with 20 additions and 4 deletions
+16
View File
@@ -75,6 +75,22 @@ class DownloadManager:
if task.file_path and os.path.exists(task.file_path):
os.remove(task.file_path)
async def delete_task(self, task_id: str):
"""Completely remove a task from the task list"""
task = self.tasks.get(task_id)
if task:
# Cancel if downloading
if task_id in self.active_downloads:
self.active_downloads[task_id].cancel()
del self.active_downloads[task_id]
# Delete file if exists
if task.file_path and os.path.exists(task.file_path):
os.remove(task.file_path)
# Remove from tasks dict
del self.tasks[task_id]
async def _download(self, task: DownloadTask):
async with self._semaphore:
try:
+4 -4
View File
@@ -136,13 +136,13 @@ async def resume_download(task_id: str, background_tasks: BackgroundTasks):
@app.delete("/api/download/{task_id}")
async def cancel_download(task_id: str):
"""Cancel a download"""
async def delete_download(task_id: str):
"""Delete/cancel a download (removes it from the list)"""
task = download_manager.get_task(task_id)
if not task:
raise HTTPException(status_code=404, detail="Task not found")
await download_manager.cancel_download(task_id)
return {"status": "cancelled"}
await download_manager.delete_task(task_id)
return {"status": "deleted"}
@app.get("/api/download/{task_id}/file")