fix: 防止任务删除误删源视频目录并跟踪审查问题
This commit is contained in:
@@ -184,18 +184,21 @@ def resume_run(run_id: str, db: Database = Depends(_get_db)) -> dict:
|
||||
|
||||
@router.delete("/api/runs/{run_id}")
|
||||
def delete_run(run_id: str, db: Database = Depends(_get_db)) -> dict:
|
||||
"""删除任务:清理产物记录、上传文件与步骤产物目录。"""
|
||||
"""删除上传任务及其私有文件;批量 run 必须通过批量任务入口删除。"""
|
||||
run = db.get_run(run_id)
|
||||
if run is None:
|
||||
raise HTTPException(status_code=404, detail="run not found")
|
||||
# 批量 run 的输入是用户原始视频,且由 batch_videos 关联管理。
|
||||
# 在任何数据库/文件删除之前拒绝,避免误删媒体库或留下悬空的批量明细。
|
||||
if run.get("source") == "batch":
|
||||
raise HTTPException(status_code=422, detail="请通过批量任务入口删除该任务")
|
||||
from wov_app.config import STORAGE_DIR
|
||||
|
||||
# 先删数据库记录(含产物表),再清理磁盘上的上传与中间产物。
|
||||
db.delete_run(run_id)
|
||||
input_uri = run.get("input_uri")
|
||||
if input_uri:
|
||||
# 上传文件位于 <storage>/uploads/<run_id>/,整目录一并删除。
|
||||
shutil.rmtree(Path(input_uri).parent, ignore_errors=True)
|
||||
# 删除范围仅来自该任务的私有存储布局,绝不由 input_uri 推导:
|
||||
# 即使历史上传记录引用外部路径,也必须保留源视频和同目录的用户文件。
|
||||
shutil.rmtree(STORAGE_DIR / "uploads" / run_id, ignore_errors=True)
|
||||
# 步骤产物位于 <storage>/runs/<run_id>/,整目录一并删除。
|
||||
shutil.rmtree(STORAGE_DIR / "runs" / run_id, ignore_errors=True)
|
||||
return {"deleted": run_id}
|
||||
|
||||
Reference in New Issue
Block a user