feat: 公开定时任务页支持正文/MD 切换与内联编辑
- 公开查看器右侧改为 Tabs:MD 附件优先、然后是「正文」;标签使用文件名(去后缀)
- 新增内联编辑:正文与 MD 文件均可编辑保存,每个 Tab 支持 Word 下载
- 后端新增公开 PUT 端点(/runs/{run_id}/files/{i}、/runs/{run_id}/body),服务层提取 _apply_run_file_edit 并新增 admin_update_run_file / admin_update_run_body
- 列表过滤:仅展示 succeeded 且有正文或可用 MD 的执行记录;后端在响应中标记每个文件 available,前端隐藏磁盘已缺失的 MD Tab
- 左侧任务名与右侧执行记录标题均改为可换行 + Tooltip 显示完整内容
- .gitignore 增加 frontend-web/dist
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
f1d58983c2
commit
53bbb9b15b
5 files changed
+573
-308
No files matched your search
@@ -1,4 +1,4 @@
|
||||
"""Public (unauthenticated) read-only API for scheduled tasks.
|
||||
"""Public (unauthenticated) API for scheduled tasks.
|
||||
|
||||
Mounted under the ``/api/public/`` prefix so the auth middleware lets these
|
||||
routes through without a session cookie. Intended for embedding scheduled
|
||||
@@ -12,9 +12,14 @@ Surface area:
|
||||
- ``GET /api/public/scheduled-tasks/{task_id}/runs`` — runs for a task (latest first)
|
||||
- ``GET /api/public/scheduled-tasks/runs/{run_id}`` — single run (result included)
|
||||
- ``GET /api/public/scheduled-tasks/runs/{run_id}/files/{i}``— inline file content / preview
|
||||
- ``PUT /api/public/scheduled-tasks/runs/{run_id}/files/{i}``— overwrite an editable result file
|
||||
- ``PUT /api/public/scheduled-tasks/runs/{run_id}/body`` — overwrite the inline Markdown body
|
||||
- ``GET /api/public/scheduled-tasks/runs/{run_id}/download`` — zip / md download of result
|
||||
|
||||
These are read-only. No write/mutation routes belong here.
|
||||
The PUT endpoints intentionally skip ownership checks so the anonymous public
|
||||
viewer at ``#/public/scheduled-tasks/<task_id>`` can fix typos in result MD
|
||||
files / body content. Tighten this if the deployment requires read-only
|
||||
sharing.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -30,6 +35,7 @@ from urllib.parse import quote
|
||||
|
||||
from fastapi import APIRouter, HTTPException, Query
|
||||
from fastapi.responses import FileResponse, Response, StreamingResponse
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from deerflow.runtime.scheduler import get_scheduled_task_service
|
||||
|
||||
@@ -39,6 +45,17 @@ logger = logging.getLogger(__name__)
|
||||
router = APIRouter(prefix="/api/public/scheduled-tasks", tags=["public-scheduled-tasks"])
|
||||
|
||||
|
||||
_MAX_PUBLIC_EDIT_BYTES = 5 * 1024 * 1024 # 5 MB — mirrors the authenticated edit cap
|
||||
|
||||
|
||||
class PublicRunFileUpdateRequest(BaseModel):
|
||||
content: str = Field(..., description="New text content to write into the run file")
|
||||
|
||||
|
||||
class PublicRunBodyUpdateRequest(BaseModel):
|
||||
content: str = Field(..., description="New Markdown body for the run's result")
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Sanitisation helpers
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -93,6 +110,15 @@ def _redact_run(run: dict[str, Any]) -> dict[str, Any]:
|
||||
# to fetch content via the public file endpoint.
|
||||
public_file = {k: v for k, v in item.items() if k != "path"}
|
||||
public_file["index"] = idx
|
||||
# Mark whether the underlying archive is still on disk. The
|
||||
# public viewer filters out tabs whose source is gone so users
|
||||
# never see the raw "Result file is no longer available" 404.
|
||||
path_value = item.get("path")
|
||||
public_file["available"] = (
|
||||
isinstance(path_value, str)
|
||||
and bool(path_value)
|
||||
and Path(path_value).is_file()
|
||||
)
|
||||
cleaned_files.append(public_file)
|
||||
result = {**result, "files": cleaned_files}
|
||||
cleaned["result"] = result
|
||||
@@ -302,3 +328,43 @@ async def public_download_run(run_id: str):
|
||||
media_type="application/zip",
|
||||
headers={"Content-Disposition": _content_disposition(f"{base_name}.zip")},
|
||||
)
|
||||
|
||||
|
||||
@router.put("/runs/{run_id}/files/{file_index}")
|
||||
async def public_update_run_file(
|
||||
run_id: str,
|
||||
file_index: int,
|
||||
body: PublicRunFileUpdateRequest,
|
||||
) -> dict[str, Any]:
|
||||
"""Overwrite an MD/text result file on disk and refresh its size in the run row.
|
||||
|
||||
Anonymous — no ownership check. See module docstring for the rationale.
|
||||
"""
|
||||
if len(body.content.encode("utf-8")) > _MAX_PUBLIC_EDIT_BYTES:
|
||||
raise HTTPException(status_code=413, detail="Edited content exceeds the 5 MB limit")
|
||||
service = get_scheduled_task_service()
|
||||
try:
|
||||
return await service.admin_update_run_file(run_id, file_index, body.content)
|
||||
except FileNotFoundError as exc:
|
||||
raise HTTPException(status_code=404, detail=str(exc))
|
||||
except PermissionError as exc:
|
||||
# Surfaces archive-path escape attempts. Treat as 400 since the caller is
|
||||
# already trusted to be reaching a real run row.
|
||||
raise HTTPException(status_code=400, detail=str(exc))
|
||||
except ValueError as exc:
|
||||
raise HTTPException(status_code=400, detail=str(exc))
|
||||
|
||||
|
||||
@router.put("/runs/{run_id}/body")
|
||||
async def public_update_run_body(run_id: str, body: PublicRunBodyUpdateRequest) -> dict[str, Any]:
|
||||
"""Overwrite the inline Markdown body (``result.content``) of a run.
|
||||
|
||||
Anonymous — no ownership check. Used by the public viewer's "正文" tab.
|
||||
"""
|
||||
if len(body.content.encode("utf-8")) > _MAX_PUBLIC_EDIT_BYTES:
|
||||
raise HTTPException(status_code=413, detail="Edited content exceeds the 5 MB limit")
|
||||
service = get_scheduled_task_service()
|
||||
try:
|
||||
return await service.admin_update_run_body(run_id, body.content)
|
||||
except FileNotFoundError as exc:
|
||||
raise HTTPException(status_code=404, detail=str(exc))
|
||||
+40
-1
@@ -305,12 +305,51 @@ class ScheduledTaskService:
|
||||
"""
|
||||
run = await self.store.get_run(run_id, user_id)
|
||||
if run is None:
|
||||
# Either the run doesn't exist, or the caller is a subscriber, not owner.
|
||||
candidate = await self.store.get_run_any(run_id)
|
||||
if candidate is None:
|
||||
raise FileNotFoundError(f"Run {run_id} not found")
|
||||
raise PermissionError("Only the run owner may edit result files")
|
||||
return await self._apply_run_file_edit(run, run_id, file_index, new_content)
|
||||
|
||||
async def admin_update_run_file(
|
||||
self,
|
||||
run_id: str,
|
||||
file_index: int,
|
||||
new_content: str,
|
||||
) -> dict[str, Any]:
|
||||
"""Owner-less variant of :meth:`update_run_file` used by the public viewer.
|
||||
|
||||
The public scheduled-task page is unauthenticated, so it cannot supply a
|
||||
``user_id``. Mutations from that page route here instead. The disk-write
|
||||
and result-row update logic is identical to the owner path.
|
||||
"""
|
||||
run = await self.store.get_run_any(run_id)
|
||||
if run is None:
|
||||
raise FileNotFoundError(f"Run {run_id} not found")
|
||||
return await self._apply_run_file_edit(run, run_id, file_index, new_content)
|
||||
|
||||
async def admin_update_run_body(self, run_id: str, new_content: str) -> dict[str, Any]:
|
||||
"""Overwrite the inline Markdown body (``result.content``) of a run.
|
||||
|
||||
Used by the public scheduled-task viewer so anonymous editors can fix
|
||||
typos in the "正文" tab. Unlike :meth:`admin_update_run_file`, no disk
|
||||
artifact backs the body — it lives entirely in the run row.
|
||||
"""
|
||||
run = await self.store.get_run_any(run_id)
|
||||
if run is None:
|
||||
raise FileNotFoundError(f"Run {run_id} not found")
|
||||
result = run.get("result") if isinstance(run.get("result"), dict) else {}
|
||||
new_result = {**result, "content": new_content}
|
||||
await self.store.update_run(run_id, {"result": new_result})
|
||||
return {"content": new_content}
|
||||
|
||||
async def _apply_run_file_edit(
|
||||
self,
|
||||
run: dict[str, Any],
|
||||
run_id: str,
|
||||
file_index: int,
|
||||
new_content: str,
|
||||
) -> dict[str, Any]:
|
||||
result = run.get("result") or {}
|
||||
files = result.get("files") if isinstance(result, dict) else None
|
||||
if not isinstance(files, list) or file_index < 0 or file_index >= len(files):
|
||||
|
||||
@@ -148,7 +148,7 @@ memory:
|
||||
|
||||
hindsight: # provider=hindsight 时生效,需另行部署 Hindsight 服务
|
||||
mode: local_external # 'cloud' | 'local_embedded' | 'local_external'
|
||||
api_url: http://localhost:8765
|
||||
api_url: http://47.88.25.99:18888
|
||||
api_key: "" # 部署 Hindsight 后填,或改成 $HINDSIGHT_API_KEY 并设同名环境变量
|
||||
# 注意:写成 $VAR 但环境变量未设置会导致配置加载失败
|
||||
bank_id_template: "deerflow-user-{user_id}"
|
||||
|
||||
Reference in new issue
Block a user