feat: add download button to Tables/Images views, add task history delete/clear-all

This commit is contained in:
2026-05-14 16:12:09 +08:00
parent 0e273111a2
commit d585a6baaa
5 changed files with 86 additions and 4 deletions
+23
View File
@@ -112,6 +112,29 @@ async def get_task(
return task
@router.delete("/{task_id}")
async def delete_task(
task_id: str,
current_user: dict = Depends(get_current_user),
):
"""Delete a single task by ID."""
loop = asyncio.get_event_loop()
deleted = await loop.run_in_executor(None, lambda: db_schema.delete_task(task_id))
if not deleted:
raise HTTPException(status_code=404, detail="任务不存在")
return {"message": "已删除"}
@router.delete("")
async def clear_all_tasks(
current_user: dict = Depends(get_current_user),
):
"""Clear all task history records."""
loop = asyncio.get_event_loop()
count = await loop.run_in_executor(None, db_schema.clear_task_history)
return {"message": f"已清除 {count} 条记录", "count": count}
@router.post("/{task_id}/retry")
async def retry_task(
task_id: str,
+22
View File
@@ -333,6 +333,28 @@ def query_task_stats() -> dict:
conn.close()
def delete_task(task_id: str) -> bool:
"""Delete a single task by ID. Returns True if deleted."""
conn = sqlite3.connect(_db_path)
try:
cur = conn.execute("DELETE FROM task_history WHERE id = ?", (task_id,))
conn.commit()
return cur.rowcount > 0
finally:
conn.close()
def clear_task_history() -> int:
"""Delete all task history records. Returns number of deleted rows."""
conn = sqlite3.connect(_db_path)
try:
cur = conn.execute("DELETE FROM task_history")
conn.commit()
return cur.rowcount
finally:
conn.close()
# ---------------------------------------------------------------------------
# Query functions — File metadata
# ---------------------------------------------------------------------------