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")