fix(HEL-872): library delete reports real kept reasons, not a merged vague one
List only excludes project-data refs, but delete also kept canvas-card files with the same 'referenced' reason the UI merged into 被项目使用或 无法删除 — every fresh playground output (materialized as a canvas card) looked undeletable from 素材库 with a wrong explanation. Backend: split the kept reason into referenced (project data) vs on_canvas (live canvas card); protections unchanged. Frontend: per-reason kept summary with counts and an actionable hint, error toast names failure and stays retryable, readable API error text. E2E: isolated real-page regression (cancel/single/batch/retry) + backend tests for the on_canvas reason. Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
@@ -8,7 +8,7 @@ from __future__ import annotations
|
||||
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
from typing import Any, Literal
|
||||
from typing import Any
|
||||
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from pydantic import BaseModel
|
||||
@@ -16,8 +16,7 @@ from pydantic import BaseModel
|
||||
from calliope.config import settings
|
||||
from calliope.db import get_db
|
||||
from calliope.routers.canvas import (
|
||||
_path_is_referenced,
|
||||
_playground_file_roots,
|
||||
_path_on_canvas,
|
||||
_project_path_referenced,
|
||||
)
|
||||
from calliope.routers.playground import PLAYGROUND_STATUS
|
||||
@@ -112,8 +111,9 @@ async def list_library_media() -> list[dict[str, Any]]:
|
||||
|
||||
@router.delete("/media")
|
||||
async def delete_library_media(payload: LibraryDeleteRequest) -> dict[str, Any]:
|
||||
"""Bulk-delete unlinked library files. Referenced/project-owned/foreign
|
||||
paths are kept and reported per-path."""
|
||||
"""Bulk-delete unlinked library files. Kept reasons per path:
|
||||
referenced (project data), on_canvas (live canvas card),
|
||||
project_owned/outside_assets (not library-deletable), unlink_failed."""
|
||||
if not payload.paths:
|
||||
raise HTTPException(status_code=400, detail="paths must not be empty")
|
||||
if len(payload.paths) > 200:
|
||||
@@ -140,9 +140,12 @@ async def delete_library_media(payload: LibraryDeleteRequest) -> dict[str, Any]:
|
||||
if not under_root:
|
||||
results.append({"path": path, "status": "kept", "reason": "project_owned"})
|
||||
continue
|
||||
if _path_is_referenced(conn, path):
|
||||
if _project_path_referenced(conn, path):
|
||||
results.append({"path": path, "status": "kept", "reason": "referenced"})
|
||||
continue
|
||||
if _path_on_canvas(conn, path):
|
||||
results.append({"path": path, "status": "kept", "reason": "on_canvas"})
|
||||
continue
|
||||
try:
|
||||
target.unlink()
|
||||
deleted.append(path)
|
||||
|
||||
Reference in New Issue
Block a user