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:
@@ -75,6 +75,22 @@ class DownloadManager:
|
|||||||
if task.file_path and os.path.exists(task.file_path):
|
if task.file_path and os.path.exists(task.file_path):
|
||||||
os.remove(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 def _download(self, task: DownloadTask):
|
||||||
async with self._semaphore:
|
async with self._semaphore:
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -136,13 +136,13 @@ async def resume_download(task_id: str, background_tasks: BackgroundTasks):
|
|||||||
|
|
||||||
|
|
||||||
@app.delete("/api/download/{task_id}")
|
@app.delete("/api/download/{task_id}")
|
||||||
async def cancel_download(task_id: str):
|
async def delete_download(task_id: str):
|
||||||
"""Cancel a download"""
|
"""Delete/cancel a download (removes it from the list)"""
|
||||||
task = download_manager.get_task(task_id)
|
task = download_manager.get_task(task_id)
|
||||||
if not task:
|
if not task:
|
||||||
raise HTTPException(status_code=404, detail="Task not found")
|
raise HTTPException(status_code=404, detail="Task not found")
|
||||||
await download_manager.cancel_download(task_id)
|
await download_manager.delete_task(task_id)
|
||||||
return {"status": "cancelled"}
|
return {"status": "deleted"}
|
||||||
|
|
||||||
|
|
||||||
@app.get("/api/download/{task_id}/file")
|
@app.get("/api/download/{task_id}/file")
|
||||||
|
|||||||
Reference in New Issue
Block a user