feat(monitor_web): 加终止按钮 + voice_to_mp3 优雅降级
## 痛点 用户反馈: 1. 没终止按钮 - 任务一旦点了, 跑死(✗ 失败)或跑长(解密 30s+)都没法停 2. ⑧ 语音转 MP3 报 ModuleNotFoundError: 'pilk', 直接 traceback ## Patch 1: 终止任务 ### Backend - _tool_running 加 proc / cancelled 字段 - _run_tool_task 把 proc 暴露到 _tool_running, 每轮 stdout read 后 检查 cancelled 标志, 命中就 break - 新加 POST /api/tool/cancel 路由: proc.terminate() + 1.5s 后 kill, 设 cancelled=True 让 tool runner 收尾 - tool_done 事件加 cancelled 字段 ### Frontend - 任务运行时, 触发按钮临时变成 "🛑 终止" + 红色脉冲动画 - 再点一下就调 /api/tool/cancel - tool_done 收到后还原按钮文本和颜色 - "⊘ 已终止" 状态徽章替代 "✓ 完成" ### CSS - .tool-task-btn.cancel: 实心红渐变 + box-shadow + pulseRed 1.5s 动画 ## Patch 2: voice_to_mp3 优雅降级 之前直接 `import pilk` 失败时打 traceback, 用户看不懂。改成: try: import pilk except ImportError: print 友好提示 + pip install pilk 命令 + 退出 加 ffmpeg 在 PATH 检查 (pilk 解码后需要 ffmpeg 编 MP3), 给三平台 安装指引。 requirements.txt 加注释说明 pilk 还需要 ffmpeg 配合, pyinstaller 仅打包需要(开发不必装)。 ## 测试 185/185 通过 (不影响现有功能)。 实测 web UI: - 点 ⑧ 语音转 MP3 → 立刻看到友好提示而不是 traceback - 点任何任务 → 按钮变红色"🛑 终止" → 再点 → 任务收尾 → 状态变"⊘ 已终止" ## 仍未跟进 (follow-up) - 导出筛选: ③ 导出全部聊天 / ⑦ 企微导出 一点就跑全量很可怕。 应该弹模态框选会话 + 格式. 单独开 issue #112 跟进, 需要: - 新加 GET /api/sessions 路由列会话 - export_all_chats / export_wxwork_messages 加 --filter 参数 - 前端模态框 UI
This commit is contained in:
@@ -9,7 +9,22 @@ from datetime import datetime
|
||||
if sys.platform == "win32" and hasattr(sys.stdout, "reconfigure"):
|
||||
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
||||
|
||||
import pilk
|
||||
try:
|
||||
import pilk
|
||||
except ImportError:
|
||||
print("[ERROR] 缺少 pilk 库 (SILK 解码必需)", file=sys.stderr)
|
||||
print(" 请运行: pip install pilk", file=sys.stderr)
|
||||
print(" 然后重新启动本任务", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
import shutil as _shutil
|
||||
if not _shutil.which("ffmpeg"):
|
||||
print("[ERROR] ffmpeg 不在 PATH 中 (MP3 编码必需)", file=sys.stderr)
|
||||
print(" Windows: https://ffmpeg.org/download.html 下载后加入 PATH", file=sys.stderr)
|
||||
print(" macOS: brew install ffmpeg", file=sys.stderr)
|
||||
print(" Linux: apt install ffmpeg / yum install ffmpeg", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
from config import load_config
|
||||
|
||||
_cfg = load_config()
|
||||
|
||||
Reference in New Issue
Block a user