feat: add favorite task templates and optimize evidence exports
This commit is contained in:
1 parent
e1ea099592
commit
a4a5430922
46 files changed
+1714
-188
No files matched your search
@@ -182,11 +182,7 @@ async def batch_archive(batch_id: str):
|
||||
if archive_service.status(batch_id, batch)["status"] == "preparing":
|
||||
raise HTTPException(409, "报告正在打包,请等待准备完成")
|
||||
path = archive_service.archive_path(batch_id)
|
||||
if (
|
||||
not path.is_file()
|
||||
or not batch.get("report_ready")
|
||||
and archive_service.status(batch_id, batch)["status"] != "ready"
|
||||
):
|
||||
if not path.is_file() or archive_service.status(batch_id, batch)["status"] != "ready":
|
||||
path = await asyncio.to_thread(report_export.export_batch, batch_id)
|
||||
return FileResponse(path, filename=f"批次报告-{batch_id[:8]}.zip")
|
||||
|
||||
@@ -205,8 +201,7 @@ async def download_report(
|
||||
):
|
||||
try:
|
||||
if fmt in {"screenshots", "video", "all"}:
|
||||
path = await asyncio.to_thread(report_export.export_session_media, session_id, fmt)
|
||||
label = report_export.archive_case_name(report_export.session_report(session_id))
|
||||
path, label = await asyncio.to_thread(report_export.session_download, session_id, fmt)
|
||||
return FileResponse(path, filename=f"{label}-{fmt}.zip")
|
||||
paths = await asyncio.to_thread(report_export.export_session, session_id, [fmt])
|
||||
return FileResponse(paths[0], filename=f"任务报告-{session_id[:8]}.{fmt}")
|
||||
@@ -224,7 +219,9 @@ def review_case(session_id: str, value: CaseReviewRequest):
|
||||
and archive_service.status(batch_id, require("batch", batch_id))["status"] == "preparing"
|
||||
):
|
||||
raise HTTPException(409, "批次报告正在打包,请完成后再保存人工复验")
|
||||
with report_export.EXPORT_LOCK:
|
||||
with report_export.export_lock(
|
||||
*(["batch:" + batch_id] if batch_id else []), "session:" + session_id
|
||||
):
|
||||
current = report(session_id)
|
||||
if current["status"] not in {
|
||||
"completed",
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
"""Favorite templates shared by the home page and MCP."""
|
||||
|
||||
from fastapi import APIRouter, HTTPException
|
||||
|
||||
from apps.admin_console.services.favorites import (
|
||||
FavoriteCreate,
|
||||
FavoriteRun,
|
||||
FavoriteUpdate,
|
||||
favorites,
|
||||
)
|
||||
|
||||
router = APIRouter(prefix="/api/automation/favorites", tags=["automation"])
|
||||
|
||||
|
||||
@router.get("")
|
||||
def list_favorites():
|
||||
return favorites.store.records("favorite", 10000)
|
||||
|
||||
|
||||
@router.post("")
|
||||
def create_favorite(value: FavoriteCreate):
|
||||
try:
|
||||
return favorites.create(value)
|
||||
except (KeyError, ValueError) as exc:
|
||||
raise HTTPException(409, str(exc)) from exc
|
||||
|
||||
|
||||
@router.patch("/{key}")
|
||||
def update_favorite(key: str, value: FavoriteUpdate):
|
||||
try:
|
||||
return favorites.update(key, value)
|
||||
except (KeyError, ValueError) as exc:
|
||||
raise HTTPException(409, str(exc)) from exc
|
||||
|
||||
|
||||
@router.delete("/{key}")
|
||||
def delete_favorite(key: str):
|
||||
try:
|
||||
favorites.delete(key)
|
||||
except ValueError as exc:
|
||||
raise HTTPException(400, str(exc)) from exc
|
||||
return {"status": "deleted"}
|
||||
|
||||
|
||||
@router.post("/{key}/run")
|
||||
async def run_favorite(key: str, value: FavoriteRun):
|
||||
try:
|
||||
return await favorites.run(key, value)
|
||||
except (KeyError, ValueError) as exc:
|
||||
raise HTTPException(409, str(exc)) from exc
|
||||
Reference in new issue
Block a user