From 3d7a17d0d7310cafccc649482ac8ac4c87c56f97 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 23 Jan 2026 11:12:29 +0000 Subject: [PATCH] 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 Co-Authored-By: Happy --- app/download_manager.py | 16 ++++++++++++++++ main.py | 8 ++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/app/download_manager.py b/app/download_manager.py index a1a0a1e..30f79af 100644 --- a/app/download_manager.py +++ b/app/download_manager.py @@ -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: diff --git a/main.py b/main.py index 8a0775e..e827c8e 100644 --- a/main.py +++ b/main.py @@ -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")