mirror of
https://github.com/whyour/qinglong.git
synced 2026-08-12 03:10:48 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c32a53c40b | ||
|
|
8ae7a85bf8 | ||
|
|
a56f2393a4 | ||
|
|
1124040eeb | ||
|
|
f043aa62e4 | ||
|
|
d64dc64df7 | ||
|
|
c61d1aa828 | ||
|
|
33fa3aca99 | ||
|
|
c772fc9527 | ||
|
|
c5d2aa3aba | ||
|
|
02a05f06bd | ||
|
|
3b0f55caf4 | ||
|
|
6a3dd4f83c | ||
|
|
177cd3de81 | ||
|
|
d473c3ae88 | ||
|
|
ee2fbe5335 | ||
|
|
48abf44ceb | ||
|
|
03c7031a3c | ||
|
|
0e5de4a824 | ||
|
|
af96bd98ac | ||
|
|
08ef509e27 | ||
|
|
fbeb4f4a6c | ||
|
|
eb09a417a1 | ||
|
|
e84ddb6cfc | ||
|
|
d01ec3b310 | ||
|
|
45fac29804 | ||
|
|
72d4c8bfd4 | ||
|
|
8f23c61fee | ||
|
|
e41eed81ae | ||
|
|
58f5fe763f | ||
|
|
214241797d | ||
|
|
aedd48c9c4 | ||
|
|
90ddf0fb57 |
@@ -129,6 +129,13 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
cache: "pnpm"
|
cache: "pnpm"
|
||||||
|
|
||||||
|
- name: Read version from version.yaml
|
||||||
|
id: version
|
||||||
|
run: |
|
||||||
|
VERSION=$(grep '^version:' version.yaml | awk '{print $2}')
|
||||||
|
echo "version=$VERSION" >> $GITHUB_OUTPUT
|
||||||
|
echo "Version: $VERSION"
|
||||||
|
|
||||||
- name: Setup timezone
|
- name: Setup timezone
|
||||||
uses: szenius/set-timezone@v2.0
|
uses: szenius/set-timezone@v2.0
|
||||||
with:
|
with:
|
||||||
@@ -154,19 +161,13 @@ jobs:
|
|||||||
images: |
|
images: |
|
||||||
${{ github.repository }}
|
${{ github.repository }}
|
||||||
ghcr.io/${{ github.repository }}
|
ghcr.io/${{ github.repository }}
|
||||||
# generate Docker tags based on the following events/attributes
|
|
||||||
# nightly, master, pr-2, 1.2.3, 1.2, 1
|
|
||||||
flavor: |
|
flavor: |
|
||||||
latest=false
|
latest=false
|
||||||
tags: |
|
tags: |
|
||||||
type=schedule,pattern=nightly
|
type=ref,event=branch,enable=${{ github.ref == format('refs/heads/{0}', 'develop') }}
|
||||||
type=edge
|
|
||||||
type=ref,event=pr
|
|
||||||
type=ref,event=branch,enable=${{ github.ref != format('refs/heads/{0}', 'master') }}
|
|
||||||
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'master') }}
|
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'master') }}
|
||||||
|
type=raw,value=${{ steps.version.outputs.version }},enable=${{ github.ref == format('refs/heads/{0}', 'master') }}
|
||||||
type=semver,pattern={{version}}
|
type=semver,pattern={{version}}
|
||||||
type=semver,pattern={{major}}.{{minor}}
|
|
||||||
type=semver,pattern={{major}}
|
|
||||||
|
|
||||||
- name: Set up QEMU
|
- name: Set up QEMU
|
||||||
uses: docker/setup-qemu-action@v3
|
uses: docker/setup-qemu-action@v3
|
||||||
@@ -216,6 +217,13 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
cache: "pnpm"
|
cache: "pnpm"
|
||||||
|
|
||||||
|
- name: Read version from version.yaml
|
||||||
|
id: version
|
||||||
|
run: |
|
||||||
|
VERSION=$(grep '^version:' version.yaml | awk '{print $2}')
|
||||||
|
echo "version=$VERSION" >> $GITHUB_OUTPUT
|
||||||
|
echo "Version: $VERSION"
|
||||||
|
|
||||||
- name: Setup timezone
|
- name: Setup timezone
|
||||||
uses: szenius/set-timezone@v2.0
|
uses: szenius/set-timezone@v2.0
|
||||||
with:
|
with:
|
||||||
@@ -254,7 +262,9 @@ jobs:
|
|||||||
context: .
|
context: .
|
||||||
file: ./docker/310.Dockerfile
|
file: ./docker/310.Dockerfile
|
||||||
push: true
|
push: true
|
||||||
tags: whyour/qinglong:python3.10
|
tags: |
|
||||||
|
whyour/qinglong:python3.10
|
||||||
|
whyour/qinglong:${{ steps.version.outputs.version }}-python3.10
|
||||||
cache-from: type=registry,ref=whyour/qinglong:cache-python3.10
|
cache-from: type=registry,ref=whyour/qinglong:cache-python3.10
|
||||||
cache-to: type=registry,ref=whyour/qinglong:cache-python3.10,mode=max
|
cache-to: type=registry,ref=whyour/qinglong:cache-python3.10,mode=max
|
||||||
|
|
||||||
|
|||||||
@@ -1,359 +0,0 @@
|
|||||||
# 场景模式完整实现总结 (Scenario Mode Complete Implementation Summary)
|
|
||||||
|
|
||||||
## 🎉 实现完成 (Implementation Complete)
|
|
||||||
|
|
||||||
场景模式功能已完全实现,包含可视化工作流编辑器和完整的图执行引擎!
|
|
||||||
|
|
||||||
## 📦 实现的三个阶段 (Three Implementation Phases)
|
|
||||||
|
|
||||||
### Phase 1: 基础架构 (Foundation) ✅
|
|
||||||
**Commits**: fffc1e4, 2e0775e
|
|
||||||
|
|
||||||
- 数据模型扩展(添加 `workflowGraph` 字段)
|
|
||||||
- 数据库迁移
|
|
||||||
- API 层更新
|
|
||||||
- 依赖包安装(Flowgram + React Flow)
|
|
||||||
- 基础文档
|
|
||||||
|
|
||||||
### Phase 2: 可视化编辑器 (Visual Editor) ✅
|
|
||||||
**Commit**: 5ed2e5b
|
|
||||||
|
|
||||||
- 完整的节点类型系统(5大类,20+模板)
|
|
||||||
- 基于 React Flow 的可视化编辑器
|
|
||||||
- 拖拽式节点创建和连接
|
|
||||||
- 动态配置表单
|
|
||||||
- 节点渲染器
|
|
||||||
|
|
||||||
### Phase 3: 图执行引擎 (Graph Execution Engine) ✅
|
|
||||||
**Commit**: 2c5357e
|
|
||||||
|
|
||||||
- 图遍历和执行引擎
|
|
||||||
- 节点执行实现(触发器、条件、动作、控制流)
|
|
||||||
- 工作流验证
|
|
||||||
- 双模式支持(图模式 + 遗留模式)
|
|
||||||
|
|
||||||
## 🎯 功能清单 (Feature Checklist)
|
|
||||||
|
|
||||||
### 原始需求完全实现 ✅
|
|
||||||
|
|
||||||
#### 多样化触发器 (Diverse Triggers)
|
|
||||||
- [x] **变量监听**: 环境变量/配置文件变更监听 ✅
|
|
||||||
- [x] **Webhook触发器**: API端点接收外部触发 ✅
|
|
||||||
- [x] **任务状态触发器**: 基于其他任务的成功/失败状态触发 ✅
|
|
||||||
- [x] **时间触发器**: Cron表达式支持 ✅
|
|
||||||
- [x] **系统事件**: 磁盘空间/内存占用等硬件指标触发 ✅
|
|
||||||
|
|
||||||
#### 动态响应机制 (Dynamic Response)
|
|
||||||
- [x] **多条件嵌套**: 支持AND/OR逻辑的条件组合 ✅
|
|
||||||
- [x] **延时执行**: 设置触发后的延迟执行时间 ✅
|
|
||||||
- [x] **失败熔断**: 连续失败N次后自动禁用任务 ✅
|
|
||||||
- [x] **自适应重试**: 根据错误类型配置重试策略 ✅
|
|
||||||
|
|
||||||
#### 可视化工作流 (Visual Workflow) ✅
|
|
||||||
- [x] **节点式编辑器**: 拖拽创建工作流 ✅
|
|
||||||
- [x] **节点配置**: 双击配置节点参数 ✅
|
|
||||||
- [x] **连线绘制**: 可视化连接节点 ✅
|
|
||||||
- [x] **实时保存**: 工作流图持久化 ✅
|
|
||||||
|
|
||||||
## 💻 技术架构 (Technical Architecture)
|
|
||||||
|
|
||||||
### 后端 (Backend)
|
|
||||||
```
|
|
||||||
├── back/data/scenario.ts # 数据模型(支持 workflowGraph)
|
|
||||||
├── back/data/scenarioLog.ts # 日志模型
|
|
||||||
├── back/services/scenario.ts # 场景服务(双模式支持)
|
|
||||||
├── back/services/graphExecutor.ts # 图执行引擎
|
|
||||||
└── back/api/scenario.ts # REST API
|
|
||||||
```
|
|
||||||
|
|
||||||
**关键技术**:
|
|
||||||
- TypeScript
|
|
||||||
- Sequelize (SQLite)
|
|
||||||
- TypeDI (依赖注入)
|
|
||||||
- Chokidar (文件监控)
|
|
||||||
- Node-Schedule (定时任务)
|
|
||||||
|
|
||||||
### 前端 (Frontend)
|
|
||||||
```
|
|
||||||
├── src/pages/scenario/
|
|
||||||
│ ├── index.tsx # 场景列表页
|
|
||||||
│ ├── visualWorkflowModal.tsx # 可视化编辑器
|
|
||||||
│ ├── nodeTypes.tsx # 节点类型定义
|
|
||||||
│ ├── logModal.tsx # 日志查看器
|
|
||||||
│ └── modal.tsx # (遗留)表单编辑器
|
|
||||||
└── src/locales/ # 国际化文件
|
|
||||||
```
|
|
||||||
|
|
||||||
**关键技术**:
|
|
||||||
- React 18
|
|
||||||
- TypeScript
|
|
||||||
- React Flow (可视化工作流)
|
|
||||||
- Ant Design 4
|
|
||||||
- React Intl Universal
|
|
||||||
|
|
||||||
## 📊 代码统计 (Code Statistics)
|
|
||||||
|
|
||||||
### 新增代码
|
|
||||||
- **后端**: ~1,200 行
|
|
||||||
- 数据模型: ~200 行
|
|
||||||
- 服务层: ~850 行
|
|
||||||
- API 层: ~150 行
|
|
||||||
|
|
||||||
- **前端**: ~1,600 行
|
|
||||||
- 节点系统: ~300 行
|
|
||||||
- 可视化编辑器: ~500 行
|
|
||||||
- 列表页面: ~300 行
|
|
||||||
- 日志查看: ~130 行
|
|
||||||
- 国际化: ~144 条翻译
|
|
||||||
|
|
||||||
- **文档**: ~700 行
|
|
||||||
- SCENARIO_MODE.md: 用户指南
|
|
||||||
- IMPLEMENTATION_SUMMARY.md: 技术总结
|
|
||||||
- FLOWGRAM_INTEGRATION_STATUS.md: 集成状态
|
|
||||||
- COMPLETE_SUMMARY.md: 完整总结
|
|
||||||
|
|
||||||
### 修改文件
|
|
||||||
- 数据库加载器: +4 行
|
|
||||||
- 主菜单: +6 行
|
|
||||||
- Package.json: +2 个依赖
|
|
||||||
|
|
||||||
**总计**: ~2,800 行新增代码 + 详细文档
|
|
||||||
|
|
||||||
## 🎨 用户界面 (User Interface)
|
|
||||||
|
|
||||||
### 场景列表页
|
|
||||||
- 表格展示所有场景
|
|
||||||
- 实时统计(执行次数、成功/失败率)
|
|
||||||
- 快速操作(启用/禁用、手动触发、查看日志)
|
|
||||||
- Webhook URL 获取
|
|
||||||
|
|
||||||
### 可视化编辑器
|
|
||||||
- 工具栏:快速添加节点
|
|
||||||
- 触发器按钮
|
|
||||||
- 条件按钮
|
|
||||||
- 动作按钮
|
|
||||||
- 控制流按钮
|
|
||||||
- 逻辑门按钮
|
|
||||||
- 画布:拖拽节点和连线
|
|
||||||
- 配置抽屉:双击节点配置参数
|
|
||||||
- 网格背景:辅助对齐
|
|
||||||
- 缩放控制:放大缩小画布
|
|
||||||
|
|
||||||
### 日志查看器
|
|
||||||
- 时间线展示
|
|
||||||
- 执行状态(成功/失败)
|
|
||||||
- 条件匹配结果
|
|
||||||
- 执行时间
|
|
||||||
- 重试次数
|
|
||||||
- 错误信息
|
|
||||||
|
|
||||||
## 🔧 使用示例 (Usage Examples)
|
|
||||||
|
|
||||||
### 示例 1: 定时备份工作流
|
|
||||||
```
|
|
||||||
[时间触发: 每天凌晨3点]
|
|
||||||
↓
|
|
||||||
[检查磁盘空间 > 20%]
|
|
||||||
↓
|
|
||||||
[执行备份命令]
|
|
||||||
↓
|
|
||||||
[发送通知: 备份完成]
|
|
||||||
```
|
|
||||||
|
|
||||||
### 示例 2: CI/CD 集成工作流
|
|
||||||
```
|
|
||||||
[Webhook触发]
|
|
||||||
↓
|
|
||||||
[条件: branch == "main" AND status == "success"]
|
|
||||||
↓
|
|
||||||
[运行部署任务]
|
|
||||||
↓
|
|
||||||
[设置变量: LAST_DEPLOY = timestamp]
|
|
||||||
↓
|
|
||||||
[发送通知: 部署成功]
|
|
||||||
```
|
|
||||||
|
|
||||||
### 示例 3: 任务链工作流
|
|
||||||
```
|
|
||||||
[任务状态触发: 任务A完成]
|
|
||||||
↓
|
|
||||||
[条件: 任务A成功]
|
|
||||||
↓
|
|
||||||
[延迟执行: 60秒]
|
|
||||||
↓
|
|
||||||
[运行任务B]
|
|
||||||
↓ (失败)
|
|
||||||
[重试策略: 3次,间隔5秒,指数退避]
|
|
||||||
↓ (仍然失败)
|
|
||||||
[熔断器: 禁用场景]
|
|
||||||
```
|
|
||||||
|
|
||||||
## 🚀 部署和使用 (Deployment & Usage)
|
|
||||||
|
|
||||||
### 安装依赖
|
|
||||||
```bash
|
|
||||||
pnpm install
|
|
||||||
```
|
|
||||||
|
|
||||||
### 构建
|
|
||||||
```bash
|
|
||||||
npm run build:back # 构建后端
|
|
||||||
npm run build:front # 构建前端
|
|
||||||
```
|
|
||||||
|
|
||||||
### 启动
|
|
||||||
```bash
|
|
||||||
npm run panel # 生产模式
|
|
||||||
# 或
|
|
||||||
npm start # 开发模式
|
|
||||||
```
|
|
||||||
|
|
||||||
### 访问
|
|
||||||
1. 登录青龙面板
|
|
||||||
2. 点击侧边栏"场景模式"菜单
|
|
||||||
3. 点击"新建场景"按钮
|
|
||||||
4. 在可视化编辑器中创建工作流
|
|
||||||
5. 保存并启用场景
|
|
||||||
|
|
||||||
## 📖 API 文档 (API Documentation)
|
|
||||||
|
|
||||||
### 场景管理
|
|
||||||
```bash
|
|
||||||
# 获取场景列表
|
|
||||||
GET /api/scenarios
|
|
||||||
|
|
||||||
# 创建场景
|
|
||||||
POST /api/scenarios
|
|
||||||
{
|
|
||||||
"name": "场景名称",
|
|
||||||
"description": "描述",
|
|
||||||
"workflowGraph": {
|
|
||||||
"nodes": [...],
|
|
||||||
"edges": [...]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# 更新场景
|
|
||||||
PUT /api/scenarios
|
|
||||||
{
|
|
||||||
"id": 1,
|
|
||||||
"name": "新名称",
|
|
||||||
"workflowGraph": {...}
|
|
||||||
}
|
|
||||||
|
|
||||||
# 删除场景
|
|
||||||
DELETE /api/scenarios
|
|
||||||
{ "ids": [1, 2, 3] }
|
|
||||||
|
|
||||||
# 手动触发
|
|
||||||
POST /api/scenarios/:id/trigger
|
|
||||||
{}
|
|
||||||
|
|
||||||
# 获取 Webhook URL
|
|
||||||
GET /api/scenarios/:id/webhook
|
|
||||||
```
|
|
||||||
|
|
||||||
### Webhook 触发
|
|
||||||
```bash
|
|
||||||
POST /api/scenarios/webhook/:token
|
|
||||||
Content-Type: application/json
|
|
||||||
|
|
||||||
{
|
|
||||||
"event": "deployment",
|
|
||||||
"status": "success",
|
|
||||||
"branch": "main",
|
|
||||||
"data": {...}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 日志查询
|
|
||||||
```bash
|
|
||||||
GET /api/scenarios/logs?scenarioId=1&limit=100
|
|
||||||
```
|
|
||||||
|
|
||||||
## 🔒 安全性 (Security)
|
|
||||||
|
|
||||||
- ✅ Webhook Token 认证
|
|
||||||
- ✅ 命令执行权限控制
|
|
||||||
- ✅ 输入验证(Joi)
|
|
||||||
- ✅ SQL 注入防护(Sequelize)
|
|
||||||
- ✅ 循环检测
|
|
||||||
- ✅ 失败熔断
|
|
||||||
|
|
||||||
## 🧪 测试建议 (Testing Recommendations)
|
|
||||||
|
|
||||||
### 手动测试清单
|
|
||||||
- [ ] 创建场景
|
|
||||||
- [ ] 添加各类节点
|
|
||||||
- [ ] 配置节点参数
|
|
||||||
- [ ] 连接节点
|
|
||||||
- [ ] 保存场景
|
|
||||||
- [ ] 启用场景
|
|
||||||
- [ ] 触发执行(手动/Webhook/定时)
|
|
||||||
- [ ] 查看日志
|
|
||||||
- [ ] 验证结果
|
|
||||||
|
|
||||||
### 自动化测试(未来)
|
|
||||||
- 单元测试:节点执行逻辑
|
|
||||||
- 集成测试:完整工作流执行
|
|
||||||
- E2E 测试:前端交互
|
|
||||||
|
|
||||||
## 📝 已知限制 (Known Limitations)
|
|
||||||
|
|
||||||
1. **并行执行**: 当前是串行执行节点(可扩展)
|
|
||||||
2. **子工作流**: 不支持嵌套工作流(可扩展)
|
|
||||||
3. **循环**: 不支持 for-each 循环(可扩展)
|
|
||||||
4. **条件分支**: 简单的条件判断(可扩展为 if-else)
|
|
||||||
|
|
||||||
## 🔮 未来增强 (Future Enhancements)
|
|
||||||
|
|
||||||
### 短期 (Short-term)
|
|
||||||
- [ ] 并行节点执行
|
|
||||||
- [ ] 可视化执行轨迹
|
|
||||||
- [ ] 节点模板库
|
|
||||||
- [ ] 工作流导入/导出
|
|
||||||
|
|
||||||
### 中期 (Mid-term)
|
|
||||||
- [ ] 子工作流支持
|
|
||||||
- [ ] 条件分支节点(if-else)
|
|
||||||
- [ ] 循环节点(for-each)
|
|
||||||
- [ ] 变量传递优化
|
|
||||||
|
|
||||||
### 长期 (Long-term)
|
|
||||||
- [ ] 工作流市场
|
|
||||||
- [ ] AI 辅助工作流生成
|
|
||||||
- [ ] 实时执行监控
|
|
||||||
- [ ] 性能分析工具
|
|
||||||
|
|
||||||
## 🎓 学习资源 (Learning Resources)
|
|
||||||
|
|
||||||
### 文档
|
|
||||||
- `SCENARIO_MODE.md` - 用户指南
|
|
||||||
- `IMPLEMENTATION_SUMMARY.md` - 技术实现
|
|
||||||
- `FLOWGRAM_INTEGRATION_STATUS.md` - 集成进度
|
|
||||||
|
|
||||||
### 代码示例
|
|
||||||
见源代码中的注释和 JSDoc
|
|
||||||
|
|
||||||
### 社区
|
|
||||||
- GitHub Issues: 问题反馈
|
|
||||||
- Pull Requests: 功能贡献
|
|
||||||
|
|
||||||
## 🙏 致谢 (Acknowledgments)
|
|
||||||
|
|
||||||
- **Flowgram.ai** - 工作流编辑器灵感
|
|
||||||
- **React Flow** - 可视化图编辑库
|
|
||||||
- **Qinglong** - 基础平台
|
|
||||||
- **贡献者** - 所有参与者
|
|
||||||
|
|
||||||
## 📄 许可证 (License)
|
|
||||||
|
|
||||||
遵循青龙面板的开源许可证
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
**实现完成日期**: 2025-11-09
|
|
||||||
**版本**: 1.0.0
|
|
||||||
**状态**: ✅ 生产就绪 (Production Ready)
|
|
||||||
|
|
||||||
🎉 场景模式功能已完全实现并可投入使用!
|
|
||||||
@@ -1,329 +0,0 @@
|
|||||||
# Flowgram 实现完成总结 (Flowgram Implementation Summary)
|
|
||||||
|
|
||||||
## 🎉 实现状态:完成 (Status: Complete)
|
|
||||||
|
|
||||||
本文档总结了 Flowgram 可视化工作流编辑器的完整实现。
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 📦 实现的组件 (Implemented Components)
|
|
||||||
|
|
||||||
### 1. 类型定义系统 (Type System)
|
|
||||||
**文件**: `src/pages/scenario/flowgram/types.ts`
|
|
||||||
- FlowgramGraph, FlowgramNode, FlowgramEdge 接口
|
|
||||||
- 7 种节点数据类型接口
|
|
||||||
- 完整的 TypeScript 类型安全
|
|
||||||
|
|
||||||
### 2. 节点注册系统 (Node Registry)
|
|
||||||
**文件**: `src/pages/scenario/flowgram/nodes/index.ts`
|
|
||||||
- 节点创建工厂函数 (createStartNode, createTriggerNode, etc.)
|
|
||||||
- 20+ 预配置节点模板
|
|
||||||
- 使用 nanoid 生成唯一节点 ID
|
|
||||||
|
|
||||||
### 3. 数据转换工具 (Data Converter)
|
|
||||||
**文件**: `src/pages/scenario/flowgram/utils/dataConverter.ts`
|
|
||||||
- `flowgramToBackend()` - 前端到后端格式转换
|
|
||||||
- `backendToFlowgram()` - 后端到前端格式转换
|
|
||||||
- `validateWorkflow()` - 工作流验证(循环检测、断点检测)
|
|
||||||
- `createEdge()` - 边创建辅助函数
|
|
||||||
|
|
||||||
### 4. Flowgram 编辑器 (Flowgram Editor)
|
|
||||||
**文件**: `src/pages/scenario/flowgram/Editor.tsx` (480+ 行)
|
|
||||||
|
|
||||||
**功能**:
|
|
||||||
- 工具栏 - 快速添加各类节点
|
|
||||||
- 节点列表 - 显示所有节点卡片
|
|
||||||
- 配置抽屉 - 点击节点打开配置表单
|
|
||||||
- 动态表单 - 根据节点类型显示不同配置项
|
|
||||||
- 工作流验证 - 检查工作流结构合法性
|
|
||||||
|
|
||||||
**支持的节点类型**:
|
|
||||||
- ✅ Start (开始) / End (结束)
|
|
||||||
- ✅ Trigger (触发器): 时间、Webhook、变量监听、任务状态、系统事件
|
|
||||||
- ✅ Condition (条件): 6种操作符
|
|
||||||
- ✅ Action (动作): 运行任务、设置变量、执行命令、发送通知
|
|
||||||
- ✅ Control (控制流): 延迟、重试、熔断器
|
|
||||||
- ✅ Logic Gate (逻辑门): AND、OR
|
|
||||||
|
|
||||||
### 5. 样式文件 (Styles)
|
|
||||||
**文件**: `src/pages/scenario/flowgram/editor.css`
|
|
||||||
- 编辑器容器样式
|
|
||||||
- 工具栏样式
|
|
||||||
- 画布样式
|
|
||||||
- 节点卡片样式和悬停效果
|
|
||||||
|
|
||||||
### 6. 工作流模态框 (Workflow Modal)
|
|
||||||
**文件**: `src/pages/scenario/flowgramWorkflowModal.tsx`
|
|
||||||
- 场景创建/编辑模态框
|
|
||||||
- 集成 Flowgram 编辑器
|
|
||||||
- 表单验证和提交处理
|
|
||||||
- 启用/禁用开关
|
|
||||||
|
|
||||||
### 7. 主页面集成 (Main Page Integration)
|
|
||||||
**文件**: `src/pages/scenario/index.tsx` (已更新)
|
|
||||||
- 从 `visualWorkflowModal` 切换到 `flowgramWorkflowModal`
|
|
||||||
- 保持所有现有功能
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 🎨 用户界面 (User Interface)
|
|
||||||
|
|
||||||
### 工具栏 (Toolbar)
|
|
||||||
```
|
|
||||||
[开始] [添加触发器▾] [条件] [添加动作▾] [添加控制流▾] [添加逻辑门▾] [结束] [验证]
|
|
||||||
```
|
|
||||||
|
|
||||||
### 节点配置示例 (Node Configuration Examples)
|
|
||||||
|
|
||||||
#### Trigger 节点 - 时间触发
|
|
||||||
- 标签: "每日任务触发"
|
|
||||||
- 触发类型: time
|
|
||||||
- Cron表达式: "0 0 * * *"
|
|
||||||
|
|
||||||
#### Condition 节点
|
|
||||||
- 标签: "检查状态"
|
|
||||||
- 字段: "data.status"
|
|
||||||
- 操作符: equals
|
|
||||||
- 值: "success"
|
|
||||||
|
|
||||||
#### Action 节点 - 运行任务
|
|
||||||
- 标签: "执行备份任务"
|
|
||||||
- 动作类型: run_task
|
|
||||||
- 任务ID: 123
|
|
||||||
|
|
||||||
#### Control 节点 - 延迟
|
|
||||||
- 标签: "等待30秒"
|
|
||||||
- 控制类型: delay
|
|
||||||
- 延迟时间: 30秒
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 📊 技术架构 (Technical Architecture)
|
|
||||||
|
|
||||||
```
|
|
||||||
┌─────────────────────────────────────────────────────────┐
|
|
||||||
│ 用户界面 (User Interface) │
|
|
||||||
│ - 工具栏 (Toolbar) │
|
|
||||||
│ - 节点列表 (Node List) │
|
|
||||||
│ - 配置抽屉 (Config Drawer) │
|
|
||||||
└──────────────────┬──────────────────────────────────────┘
|
|
||||||
│
|
|
||||||
┌──────────────────▼──────────────────────────────────────┐
|
|
||||||
│ FlowgramEditor 组件 │
|
|
||||||
│ - 状态管理 (State Management) │
|
|
||||||
│ - 事件处理 (Event Handlers) │
|
|
||||||
│ - 表单渲染 (Form Rendering) │
|
|
||||||
└──────────────────┬──────────────────────────────────────┘
|
|
||||||
│
|
|
||||||
┌──────────────────▼──────────────────────────────────────┐
|
|
||||||
│ 节点系统 (Node System) │
|
|
||||||
│ - 节点模板 (Node Templates) │
|
|
||||||
│ - 节点创建 (Node Creation) │
|
|
||||||
│ - 类型定义 (Type Definitions) │
|
|
||||||
└──────────────────┬──────────────────────────────────────┘
|
|
||||||
│
|
|
||||||
┌──────────────────▼──────────────────────────────────────┐
|
|
||||||
│ 数据转换 (Data Conversion) │
|
|
||||||
│ - Flowgram ↔ Backend │
|
|
||||||
│ - 工作流验证 (Workflow Validation) │
|
|
||||||
└──────────────────┬──────────────────────────────────────┘
|
|
||||||
│
|
|
||||||
┌──────────────────▼──────────────────────────────────────┐
|
|
||||||
│ 后端 API (Backend API) │
|
|
||||||
│ - 场景 CRUD (Scenario CRUD) │
|
|
||||||
│ - 图执行引擎 (Graph Executor) │
|
|
||||||
└─────────────────────────────────────────────────────────┘
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 🔧 数据流 (Data Flow)
|
|
||||||
|
|
||||||
### 创建工作流
|
|
||||||
```
|
|
||||||
1. 用户点击工具栏按钮
|
|
||||||
↓
|
|
||||||
2. 调用 nodeTemplates 创建节点
|
|
||||||
↓
|
|
||||||
3. 更新 FlowgramGraph 状态
|
|
||||||
↓
|
|
||||||
4. 通过 onChange 传递给 Modal
|
|
||||||
↓
|
|
||||||
5. 用户保存,调用 flowgramToBackend()
|
|
||||||
↓
|
|
||||||
6. 提交到 API: POST /api/scenarios
|
|
||||||
↓
|
|
||||||
7. 保存到数据库 (workflowGraph 字段)
|
|
||||||
```
|
|
||||||
|
|
||||||
### 执行工作流
|
|
||||||
```
|
|
||||||
1. 触发器激活 (时间/Webhook/事件)
|
|
||||||
↓
|
|
||||||
2. 后端加载 workflowGraph
|
|
||||||
↓
|
|
||||||
3. 图执行引擎遍历节点
|
|
||||||
↓
|
|
||||||
4. 执行各节点逻辑
|
|
||||||
↓
|
|
||||||
5. 记录执行日志
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 📝 使用说明 (Usage Guide)
|
|
||||||
|
|
||||||
### 创建场景
|
|
||||||
1. 点击 "新建场景" 按钮
|
|
||||||
2. 输入场景名称
|
|
||||||
3. 使用工具栏添加节点
|
|
||||||
4. 点击节点配置参数
|
|
||||||
5. 点击验证按钮检查工作流
|
|
||||||
6. 保存场景
|
|
||||||
|
|
||||||
### 配置节点
|
|
||||||
1. 点击节点卡片
|
|
||||||
2. 在配置抽屉中填写参数
|
|
||||||
3. 点击 "保存" 按钮
|
|
||||||
4. 节点配置已更新
|
|
||||||
|
|
||||||
### 验证工作流
|
|
||||||
1. 点击工具栏 "验证" 按钮
|
|
||||||
2. 系统检查:
|
|
||||||
- 是否有触发器节点
|
|
||||||
- 是否存在循环依赖
|
|
||||||
- 是否有断开的节点
|
|
||||||
3. 显示验证结果
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 🎯 功能完整性 (Feature Completeness)
|
|
||||||
|
|
||||||
### 原始需求对照
|
|
||||||
|
|
||||||
| 需求 | 状态 | 实现方式 |
|
|
||||||
|------|------|----------|
|
|
||||||
| 变量监听 | ✅ | Trigger 节点 - variable_monitor |
|
|
||||||
| Webhook触发器 | ✅ | Trigger 节点 - webhook |
|
|
||||||
| 任务状态触发器 | ✅ | Trigger 节点 - task_status |
|
|
||||||
| 时间触发器 | ✅ | Trigger 节点 - time |
|
|
||||||
| 系统事件 | ✅ | Trigger 节点 - system_event |
|
|
||||||
| 多条件嵌套 (AND/OR) | ✅ | Logic Gate 节点 + Condition 节点 |
|
|
||||||
| 延时执行 | ✅ | Control 节点 - delay |
|
|
||||||
| 失败熔断 | ✅ | Control 节点 - circuit_breaker |
|
|
||||||
| 自适应重试 | ✅ | Control 节点 - retry |
|
|
||||||
| 可视化编排 | ✅ | Flowgram 编辑器 |
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 📦 依赖列表 (Dependencies)
|
|
||||||
|
|
||||||
已安装的 Flowgram 相关包:
|
|
||||||
- `@flowgram.ai/free-layout-editor` - 核心编辑器
|
|
||||||
- `@flowgram.ai/core` - 核心库
|
|
||||||
- `@flowgram.ai/reactive` - 响应式系统
|
|
||||||
- `@flowgram.ai/free-snap-plugin` - 吸附插件
|
|
||||||
- `@flowgram.ai/free-lines-plugin` - 连线插件
|
|
||||||
- `@flowgram.ai/free-node-panel-plugin` - 节点面板
|
|
||||||
- `@flowgram.ai/minimap-plugin` - 小地图
|
|
||||||
- `@flowgram.ai/free-container-plugin` - 容器插件
|
|
||||||
- `@flowgram.ai/free-group-plugin` - 分组插件
|
|
||||||
- `@flowgram.ai/form-materials` - 表单素材
|
|
||||||
- `@flowgram.ai/panel-manager-plugin` - 面板管理
|
|
||||||
- `@flowgram.ai/free-stack-plugin` - 堆栈插件
|
|
||||||
- `@flowgram.ai/runtime-interface` - 运行时接口
|
|
||||||
- `@flowgram.ai/runtime-js` - 运行时 JS
|
|
||||||
- `nanoid` - ID 生成器
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 🔄 与 React Flow 实现的区别
|
|
||||||
|
|
||||||
### React Flow 版本 (已替换)
|
|
||||||
- 使用 reactflow 库
|
|
||||||
- 完整的可视化画布
|
|
||||||
- 拖拽节点定位
|
|
||||||
- 可视化连线
|
|
||||||
|
|
||||||
### Flowgram 版本 (当前)
|
|
||||||
- 基于 Flowgram 架构
|
|
||||||
- 节点列表视图(简化版)
|
|
||||||
- 点击配置
|
|
||||||
- 数据结构兼容
|
|
||||||
|
|
||||||
### 为什么当前是简化版?
|
|
||||||
Flowgram 的完整可视化画布需要更多配置和集成工作。当前实现:
|
|
||||||
- ✅ 完整的数据模型
|
|
||||||
- ✅ 完整的节点系统
|
|
||||||
- ✅ 完整的配置功能
|
|
||||||
- ✅ 与后端完全兼容
|
|
||||||
- ⏳ 可视化画布(可后续增强)
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 🚀 后续增强 (Future Enhancements)
|
|
||||||
|
|
||||||
### Phase 1 (当前) - 完成 ✅
|
|
||||||
- [x] 节点系统
|
|
||||||
- [x] 配置表单
|
|
||||||
- [x] 数据转换
|
|
||||||
- [x] 后端集成
|
|
||||||
|
|
||||||
### Phase 2 (未来) - 可选
|
|
||||||
- [ ] 完整的 Flowgram 可视化画布
|
|
||||||
- [ ] 拖拽节点定位
|
|
||||||
- [ ] 可视化连线绘制
|
|
||||||
- [ ] 小地图导航
|
|
||||||
- [ ] 节点缩放和平移
|
|
||||||
|
|
||||||
### Phase 3 (未来) - 高级
|
|
||||||
- [ ] 节点复制/粘贴
|
|
||||||
- [ ] 工作流模板
|
|
||||||
- [ ] 导入/导出
|
|
||||||
- [ ] 执行轨迹可视化
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 📚 文档资源 (Documentation)
|
|
||||||
|
|
||||||
- **FLOWGRAM_MIGRATION_GUIDE.md** - 完整的迁移指南
|
|
||||||
- **SCENARIO_MODE.md** - 功能使用指南
|
|
||||||
- **IMPLEMENTATION_SUMMARY.md** - 技术实现详解
|
|
||||||
- **COMPLETE_SUMMARY.md** - 功能完整性总结
|
|
||||||
- **本文档** - Flowgram 实现总结
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## ✅ 验收检查 (Acceptance Checklist)
|
|
||||||
|
|
||||||
- [x] 节点系统完整实现
|
|
||||||
- [x] 支持所有需求的节点类型
|
|
||||||
- [x] 配置表单动态适配
|
|
||||||
- [x] 数据转换正确无误
|
|
||||||
- [x] 与后端 API 集成
|
|
||||||
- [x] 与图执行引擎兼容
|
|
||||||
- [x] TypeScript 类型安全
|
|
||||||
- [x] 代码风格一致
|
|
||||||
- [x] 文档完整
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 🎊 总结 (Summary)
|
|
||||||
|
|
||||||
Flowgram 可视化工作流编辑器已完整实现,包含:
|
|
||||||
- **7 个新文件** (~900 行代码)
|
|
||||||
- **20+ 节点模板**
|
|
||||||
- **完整的配置系统**
|
|
||||||
- **工作流验证**
|
|
||||||
- **后端完全兼容**
|
|
||||||
|
|
||||||
基于官方 Demo 实现,数据结构与后端图执行引擎无缝对接。
|
|
||||||
|
|
||||||
**状态**: ✅ 生产就绪
|
|
||||||
|
|
||||||
**下一步**: 可选择增强可视化画布或直接投入使用。
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
**实现完成日期**: 2025-11-10
|
|
||||||
**参考**: https://github.com/bytedance/flowgram.ai/tree/main/apps/demo-free-layout
|
|
||||||
@@ -1,151 +0,0 @@
|
|||||||
# Flowgram 可视化工作流集成进度 (Flowgram Visual Workflow Integration Progress)
|
|
||||||
|
|
||||||
## 当前状态 (Current Status)
|
|
||||||
|
|
||||||
### ✅ 已完成 (Completed - Commit: fffc1e4)
|
|
||||||
|
|
||||||
1. **依赖安装** (Dependencies Installed)
|
|
||||||
- `@flowgram.ai/free-layout-editor@1.0.2`
|
|
||||||
- `@flowgram.ai/core@1.0.2`
|
|
||||||
- `@flowgram.ai/reactive@1.0.2`
|
|
||||||
|
|
||||||
2. **数据模型更新** (Data Model Updates)
|
|
||||||
- 添加 `workflowGraph` 字段到 Scenario 模型
|
|
||||||
- 保留旧字段以保持向后兼容
|
|
||||||
- 数据库迁移脚本已更新
|
|
||||||
|
|
||||||
3. **API 层更新** (API Layer Updates)
|
|
||||||
- `triggerType` 从必需改为可选
|
|
||||||
- 添加 `workflowGraph` 参数支持
|
|
||||||
- Create 和 Update 端点已更新
|
|
||||||
|
|
||||||
4. **前端基础** (Frontend Foundation)
|
|
||||||
- 创建新的 `flowgramModal.tsx` 组件
|
|
||||||
- 主页面更新使用新的模态框
|
|
||||||
- 基础工作流结构定义
|
|
||||||
|
|
||||||
### 🔄 需要完成 (To Be Completed)
|
|
||||||
|
|
||||||
#### 1. 完善 Flowgram 编辑器集成 (Complete Flowgram Editor Integration)
|
|
||||||
|
|
||||||
**当前问题**: Flowgram.ai 的详细 API 文档不完全公开。需要:
|
|
||||||
- 研究 Flowgram API 的正确使用方式
|
|
||||||
- 实现自定义节点渲染器
|
|
||||||
- 添加节点工具栏和配置面板
|
|
||||||
|
|
||||||
**临时方案**:
|
|
||||||
- 可以使用 React Flow 或其他开源流程图库作为替代
|
|
||||||
- 或等待 Flowgram 官方文档/示例
|
|
||||||
|
|
||||||
#### 2. 自定义节点类型实现 (Custom Node Types)
|
|
||||||
|
|
||||||
需要实现以下节点类型:
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
// Trigger Nodes (触发器节点)
|
|
||||||
- TimeT riggerNode: 时间触发配置
|
|
||||||
- WebhookTriggerNode: Webhook 触发配置
|
|
||||||
- VariableTriggerNode: 变量监听配置
|
|
||||||
- TaskStatusTriggerNode: 任务状态触发
|
|
||||||
- SystemEventTriggerNode: 系统事件触发
|
|
||||||
|
|
||||||
// Condition Nodes (条件节点)
|
|
||||||
- ConditionNode: 条件判断配置
|
|
||||||
- LogicGateNode: AND/OR 逻辑门
|
|
||||||
|
|
||||||
// Action Nodes (动作节点)
|
|
||||||
- RunTaskNode: 运行任务配置
|
|
||||||
- SetVariableNode: 设置变量配置
|
|
||||||
- ExecuteCommandNode: 执行命令配置
|
|
||||||
- SendNotificationNode: 发送通知配置
|
|
||||||
|
|
||||||
// Control Flow Nodes (控制流节点)
|
|
||||||
- DelayNode: 延迟执行
|
|
||||||
- RetryNode: 重试策略
|
|
||||||
- CircuitBreakerNode: 熔断器
|
|
||||||
```
|
|
||||||
|
|
||||||
#### 3. 节点配置面板 (Node Configuration Panels)
|
|
||||||
|
|
||||||
每个节点类型需要自己的配置表单:
|
|
||||||
- 双击节点打开配置面板
|
|
||||||
- 表单验证
|
|
||||||
- 实时预览
|
|
||||||
|
|
||||||
#### 4. 后端执行引擎重写 (Backend Execution Engine Rewrite)
|
|
||||||
|
|
||||||
当前 `ScenarioService.executeScenario()` 是线性执行。需要:
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
// 新的图执行引擎
|
|
||||||
class GraphExecutor {
|
|
||||||
async execute(workflowGraph: any, triggerData: any) {
|
|
||||||
// 1. 查找入口节点(触发器节点)
|
|
||||||
// 2. 遍历图结构
|
|
||||||
// 3. 评估条件节点
|
|
||||||
// 4. 执行动作节点
|
|
||||||
// 5. 处理分支和合并
|
|
||||||
// 6. 记录执行轨迹
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### 5. 工作流验证 (Workflow Validation)
|
|
||||||
|
|
||||||
- 检查是否有有效的触发器节点
|
|
||||||
- 验证节点连接的完整性
|
|
||||||
- 检测循环
|
|
||||||
- 验证节点配置
|
|
||||||
|
|
||||||
#### 6. 测试和调试 (Testing & Debugging)
|
|
||||||
|
|
||||||
- 单元测试
|
|
||||||
- 集成测试
|
|
||||||
- UI 测试
|
|
||||||
- 性能测试
|
|
||||||
|
|
||||||
## 实现建议 (Implementation Recommendations)
|
|
||||||
|
|
||||||
### 方案 A: 完整 Flowgram 集成 (推荐如有文档)
|
|
||||||
如果能获取 Flowgram 完整文档和示例:
|
|
||||||
1. 参考官方示例实现自定义节点
|
|
||||||
2. 使用 Flowgram 的插件系统
|
|
||||||
3. 利用 Flowgram 的内置功能
|
|
||||||
|
|
||||||
### 方案 B: 使用 React Flow (备选方案)
|
|
||||||
如果 Flowgram 文档不足:
|
|
||||||
1. 使用 React Flow (`reactflow` npm package)
|
|
||||||
2. 成熟的文档和社区支持
|
|
||||||
3. 更容易实现自定义节点
|
|
||||||
4. 保持相同的数据结构
|
|
||||||
|
|
||||||
### 方案 C: 混合方案
|
|
||||||
1. 前端继续改进表单界面
|
|
||||||
2. 后端同时支持表单数据和图数据
|
|
||||||
3. 渐进式迁移
|
|
||||||
|
|
||||||
## 预估工作量 (Estimated Effort)
|
|
||||||
|
|
||||||
- **方案 A** (Flowgram): 20-30 小时(假设有文档)
|
|
||||||
- **方案 B** (React Flow): 15-20 小时
|
|
||||||
- **方案 C** (渐进式): 10-15 小时初始,后续持续
|
|
||||||
|
|
||||||
## 下一步建议 (Next Steps Recommendations)
|
|
||||||
|
|
||||||
1. **立即**: 确认是否有 Flowgram 官方文档或示例代码
|
|
||||||
2. **短期**: 实现一个简单的节点(如触发器节点)作为 POC
|
|
||||||
3. **中期**: 完成所有节点类型和配置面板
|
|
||||||
4. **长期**: 重写执行引擎并测试
|
|
||||||
|
|
||||||
## 技术债务注意 (Technical Debt Notes)
|
|
||||||
|
|
||||||
- 旧的表单数据结构被标记为 deprecated 但仍保留
|
|
||||||
- 需要在未来版本中清理
|
|
||||||
- 数据库包含两套结构的字段
|
|
||||||
|
|
||||||
## 联系和协作 (Contact & Collaboration)
|
|
||||||
|
|
||||||
如需加速开发,建议:
|
|
||||||
1. 获取 Flowgram 官方支持或文档
|
|
||||||
2. 提供 Flowgram 集成的参考示例
|
|
||||||
3. 或考虑使用 React Flow 等替代方案
|
|
||||||
@@ -1,692 +0,0 @@
|
|||||||
# Flowgram Migration Guide - 从 React Flow 迁移到 Flowgram.ai
|
|
||||||
|
|
||||||
## 概述 (Overview)
|
|
||||||
|
|
||||||
本文档提供从 React Flow 迁移到 Flowgram.ai 的完整指南。
|
|
||||||
|
|
||||||
参考 Demo: https://github.com/bytedance/flowgram.ai/tree/main/apps/demo-free-layout
|
|
||||||
|
|
||||||
## 1. 依赖安装 (Dependencies Installation)
|
|
||||||
|
|
||||||
### 已添加的依赖 (Dependencies Added)
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"@flowgram.ai/core": "^1.0.2",
|
|
||||||
"@flowgram.ai/free-layout-editor": "^1.0.2",
|
|
||||||
"@flowgram.ai/reactive": "^1.0.2",
|
|
||||||
"@flowgram.ai/free-snap-plugin": "^1.0.2",
|
|
||||||
"@flowgram.ai/free-lines-plugin": "^1.0.2",
|
|
||||||
"@flowgram.ai/free-node-panel-plugin": "^1.0.2",
|
|
||||||
"@flowgram.ai/minimap-plugin": "^1.0.2",
|
|
||||||
"@flowgram.ai/free-container-plugin": "^1.0.2",
|
|
||||||
"@flowgram.ai/free-group-plugin": "^1.0.2",
|
|
||||||
"@flowgram.ai/form-materials": "^1.0.2",
|
|
||||||
"@flowgram.ai/panel-manager-plugin": "^1.0.2",
|
|
||||||
"@flowgram.ai/free-stack-plugin": "^1.0.2",
|
|
||||||
"@flowgram.ai/runtime-interface": "^1.0.2",
|
|
||||||
"@flowgram.ai/runtime-js": "^1.0.2",
|
|
||||||
"nanoid": "^5.0.9"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 安装命令 (Installation Command)
|
|
||||||
|
|
||||||
```bash
|
|
||||||
cd /home/runner/work/qinglong/qinglong
|
|
||||||
npm install --legacy-peer-deps
|
|
||||||
# or
|
|
||||||
pnpm install
|
|
||||||
```
|
|
||||||
|
|
||||||
## 2. 数据结构适配 (Data Structure Adaptation)
|
|
||||||
|
|
||||||
### 当前 React Flow 格式
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
{
|
|
||||||
nodes: [
|
|
||||||
{
|
|
||||||
id: "trigger-1",
|
|
||||||
type: "trigger",
|
|
||||||
position: { x: 100, y: 100 },
|
|
||||||
data: {
|
|
||||||
label: "Webhook Trigger",
|
|
||||||
triggerType: "webhook",
|
|
||||||
config: {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
edges: [
|
|
||||||
{
|
|
||||||
id: "e1",
|
|
||||||
source: "trigger-1",
|
|
||||||
target: "condition-1"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Flowgram 格式
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
{
|
|
||||||
nodes: [
|
|
||||||
{
|
|
||||||
id: "trigger_1",
|
|
||||||
type: "trigger",
|
|
||||||
meta: {
|
|
||||||
position: { x: 100, y: 100 }
|
|
||||||
},
|
|
||||||
data: {
|
|
||||||
title: "Webhook Trigger",
|
|
||||||
triggerType: "webhook",
|
|
||||||
config: {},
|
|
||||||
// Flowgram 使用 inputs/outputs schema
|
|
||||||
outputs: {
|
|
||||||
type: "object",
|
|
||||||
properties: {
|
|
||||||
data: { type: "object" }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
edges: [
|
|
||||||
{
|
|
||||||
sourceNodeID: "trigger_1",
|
|
||||||
targetNodeID: "condition_1"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## 3. 节点注册系统 (Node Registry System)
|
|
||||||
|
|
||||||
### 节点注册接口 (Node Registry Interface)
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
// src/pages/scenario/flowgram/types.ts
|
|
||||||
import { FlowNodeRegistry as FlowgramRegistry } from '@flowgram.ai/free-layout-editor';
|
|
||||||
|
|
||||||
export type FlowNodeRegistry = FlowgramRegistry;
|
|
||||||
|
|
||||||
export interface NodeData {
|
|
||||||
title: string;
|
|
||||||
inputs?: any;
|
|
||||||
outputs?: any;
|
|
||||||
inputsValues?: any;
|
|
||||||
[key: string]: any;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 创建节点注册 (Create Node Registries)
|
|
||||||
|
|
||||||
#### Start 节点 (src/pages/scenario/flowgram/nodes/start.tsx)
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
import { FlowNodeRegistry } from '../types';
|
|
||||||
|
|
||||||
export const StartNodeRegistry: FlowNodeRegistry = {
|
|
||||||
type: 'start',
|
|
||||||
meta: {
|
|
||||||
category: 'basic',
|
|
||||||
label: '开始',
|
|
||||||
description: '工作流开始节点',
|
|
||||||
},
|
|
||||||
data: {
|
|
||||||
title: '开始',
|
|
||||||
outputs: {
|
|
||||||
type: 'object',
|
|
||||||
properties: {
|
|
||||||
triggerData: {
|
|
||||||
type: 'object',
|
|
||||||
description: '触发数据',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
formMeta: {
|
|
||||||
properties: {
|
|
||||||
title: {
|
|
||||||
type: 'string',
|
|
||||||
title: '标题',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Trigger 节点 (src/pages/scenario/flowgram/nodes/trigger.tsx)
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
export const TriggerNodeRegistry: FlowNodeRegistry = {
|
|
||||||
type: 'trigger',
|
|
||||||
meta: {
|
|
||||||
category: 'triggers',
|
|
||||||
label: '触发器',
|
|
||||||
description: '各种触发器类型',
|
|
||||||
},
|
|
||||||
data: {
|
|
||||||
title: '触发器',
|
|
||||||
triggerType: 'webhook',
|
|
||||||
outputs: {
|
|
||||||
type: 'object',
|
|
||||||
properties: {
|
|
||||||
data: { type: 'object' },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
formMeta: {
|
|
||||||
properties: {
|
|
||||||
title: {
|
|
||||||
type: 'string',
|
|
||||||
title: '标题',
|
|
||||||
},
|
|
||||||
triggerType: {
|
|
||||||
type: 'string',
|
|
||||||
title: '触发类型',
|
|
||||||
enum: ['time', 'webhook', 'variable', 'task_status', 'system_event'],
|
|
||||||
enumNames: ['时间触发', 'Webhook', '变量监听', '任务状态', '系统事件'],
|
|
||||||
},
|
|
||||||
config: {
|
|
||||||
type: 'object',
|
|
||||||
title: '配置',
|
|
||||||
properties: {
|
|
||||||
schedule: {
|
|
||||||
type: 'string',
|
|
||||||
title: 'Cron 表达式',
|
|
||||||
},
|
|
||||||
filePath: {
|
|
||||||
type: 'string',
|
|
||||||
title: '文件路径',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Condition 节点
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
export const ConditionNodeRegistry: FlowNodeRegistry = {
|
|
||||||
type: 'condition',
|
|
||||||
meta: {
|
|
||||||
category: 'logic',
|
|
||||||
label: '条件',
|
|
||||||
description: '条件判断节点',
|
|
||||||
},
|
|
||||||
data: {
|
|
||||||
title: '条件',
|
|
||||||
conditions: [],
|
|
||||||
outputs: {
|
|
||||||
type: 'object',
|
|
||||||
properties: {
|
|
||||||
result: { type: 'boolean' },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
formMeta: {
|
|
||||||
properties: {
|
|
||||||
title: { type: 'string', title: '标题' },
|
|
||||||
operator: {
|
|
||||||
type: 'string',
|
|
||||||
title: '操作符',
|
|
||||||
enum: ['equals', 'not_equals', 'greater_than', 'less_than', 'contains', 'not_contains'],
|
|
||||||
enumNames: ['等于', '不等于', '大于', '小于', '包含', '不包含'],
|
|
||||||
},
|
|
||||||
field: { type: 'string', title: '字段名' },
|
|
||||||
value: { type: 'string', title: '比较值' },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Action 节点
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
export const ActionNodeRegistry: FlowNodeRegistry = {
|
|
||||||
type: 'action',
|
|
||||||
meta: {
|
|
||||||
category: 'actions',
|
|
||||||
label: '动作',
|
|
||||||
description: '执行动作',
|
|
||||||
},
|
|
||||||
data: {
|
|
||||||
title: '动作',
|
|
||||||
actionType: 'run_task',
|
|
||||||
},
|
|
||||||
formMeta: {
|
|
||||||
properties: {
|
|
||||||
title: { type: 'string', title: '标题' },
|
|
||||||
actionType: {
|
|
||||||
type: 'string',
|
|
||||||
title: '动作类型',
|
|
||||||
enum: ['run_task', 'set_variable', 'execute_command', 'send_notification'],
|
|
||||||
enumNames: ['运行任务', '设置变量', '执行命令', '发送通知'],
|
|
||||||
},
|
|
||||||
cronId: { type: 'number', title: '任务 ID' },
|
|
||||||
name: { type: 'string', title: '变量名' },
|
|
||||||
value: { type: 'string', title: '变量值' },
|
|
||||||
command: { type: 'string', title: '命令' },
|
|
||||||
message: { type: 'string', title: '消息' },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Control 节点
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
export const ControlNodeRegistry: FlowNodeRegistry = {
|
|
||||||
type: 'control',
|
|
||||||
meta: {
|
|
||||||
category: 'control',
|
|
||||||
label: '控制流',
|
|
||||||
description: '控制流节点',
|
|
||||||
},
|
|
||||||
data: {
|
|
||||||
title: '控制流',
|
|
||||||
controlType: 'delay',
|
|
||||||
},
|
|
||||||
formMeta: {
|
|
||||||
properties: {
|
|
||||||
title: { type: 'string', title: '标题' },
|
|
||||||
controlType: {
|
|
||||||
type: 'string',
|
|
||||||
title: '控制类型',
|
|
||||||
enum: ['delay', 'retry', 'circuit_breaker'],
|
|
||||||
enumNames: ['延迟', '重试', '熔断器'],
|
|
||||||
},
|
|
||||||
delaySeconds: { type: 'number', title: '延迟秒数' },
|
|
||||||
maxRetries: { type: 'number', title: '最大重试次数' },
|
|
||||||
retryDelay: { type: 'number', title: '重试延迟' },
|
|
||||||
backoffMultiplier: { type: 'number', title: '退避倍数' },
|
|
||||||
failureThreshold: { type: 'number', title: '失败阈值' },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Logic Gate 节点
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
export const LogicGateNodeRegistry: FlowNodeRegistry = {
|
|
||||||
type: 'logic_gate',
|
|
||||||
meta: {
|
|
||||||
category: 'logic',
|
|
||||||
label: '逻辑门',
|
|
||||||
description: 'AND/OR 逻辑',
|
|
||||||
},
|
|
||||||
data: {
|
|
||||||
title: '逻辑门',
|
|
||||||
gateType: 'AND',
|
|
||||||
},
|
|
||||||
formMeta: {
|
|
||||||
properties: {
|
|
||||||
title: { type: 'string', title: '标题' },
|
|
||||||
gateType: {
|
|
||||||
type: 'string',
|
|
||||||
title: '逻辑类型',
|
|
||||||
enum: ['AND', 'OR'],
|
|
||||||
enumNames: ['AND', 'OR'],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
```
|
|
||||||
|
|
||||||
#### End 节点
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
export const EndNodeRegistry: FlowNodeRegistry = {
|
|
||||||
type: 'end',
|
|
||||||
meta: {
|
|
||||||
category: 'basic',
|
|
||||||
label: '结束',
|
|
||||||
description: '工作流结束节点',
|
|
||||||
},
|
|
||||||
data: {
|
|
||||||
title: '结束',
|
|
||||||
inputs: {
|
|
||||||
type: 'object',
|
|
||||||
properties: {
|
|
||||||
result: { type: 'any' },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
formMeta: {
|
|
||||||
properties: {
|
|
||||||
title: { type: 'string', title: '标题' },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
```
|
|
||||||
|
|
||||||
## 4. 编辑器组件 (Editor Component)
|
|
||||||
|
|
||||||
### 主编辑器 (src/pages/scenario/flowgram/Editor.tsx)
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
import React from 'react';
|
|
||||||
import { EditorRenderer, FreeLayoutEditorProvider } from '@flowgram.ai/free-layout-editor';
|
|
||||||
import '@flowgram.ai/free-layout-editor/index.css';
|
|
||||||
import { useEditorProps } from './hooks/useEditorProps';
|
|
||||||
import { nodeRegistries } from './nodes';
|
|
||||||
|
|
||||||
interface EditorProps {
|
|
||||||
initialData: any;
|
|
||||||
onSave: (data: any) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const FlowgramEditor: React.FC<EditorProps> = ({ initialData, onSave }) => {
|
|
||||||
const editorProps = useEditorProps(initialData, nodeRegistries, onSave);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div style={{ width: '100%', height: '600px' }}>
|
|
||||||
<FreeLayoutEditorProvider {...editorProps}>
|
|
||||||
<EditorRenderer />
|
|
||||||
</FreeLayoutEditorProvider>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
```
|
|
||||||
|
|
||||||
### 编辑器配置 (src/pages/scenario/flowgram/hooks/useEditorProps.tsx)
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
import { useMemo } from 'react';
|
|
||||||
import { FreeLayoutProps } from '@flowgram.ai/free-layout-editor';
|
|
||||||
import { createMinimapPlugin } from '@flowgram.ai/minimap-plugin';
|
|
||||||
import { createFreeSnapPlugin } from '@flowgram.ai/free-snap-plugin';
|
|
||||||
import { createFreeNodePanelPlugin } from '@flowgram.ai/free-node-panel-plugin';
|
|
||||||
import { createFreeLinesPlugin } from '@flowgram.ai/free-lines-plugin';
|
|
||||||
import { FlowNodeRegistry } from '../types';
|
|
||||||
|
|
||||||
export function useEditorProps(
|
|
||||||
initialData: any,
|
|
||||||
nodeRegistries: FlowNodeRegistry[],
|
|
||||||
onSave: (data: any) => void
|
|
||||||
): FreeLayoutProps {
|
|
||||||
return useMemo<FreeLayoutProps>(
|
|
||||||
() => ({
|
|
||||||
background: true,
|
|
||||||
readonly: false,
|
|
||||||
twoWayConnection: true,
|
|
||||||
initialData,
|
|
||||||
nodeRegistries,
|
|
||||||
|
|
||||||
// 节点数据转换
|
|
||||||
fromNodeJSON(node, json) {
|
|
||||||
return json;
|
|
||||||
},
|
|
||||||
|
|
||||||
toNodeJSON(node, json) {
|
|
||||||
return json;
|
|
||||||
},
|
|
||||||
|
|
||||||
// 连线颜色
|
|
||||||
lineColor: {
|
|
||||||
default: '#4d53e8',
|
|
||||||
drawing: '#5DD6E3',
|
|
||||||
hovered: '#37d0ff',
|
|
||||||
selected: '#37d0ff',
|
|
||||||
error: 'red',
|
|
||||||
},
|
|
||||||
|
|
||||||
// 连线规则
|
|
||||||
canAddLine(ctx, fromPort, toPort) {
|
|
||||||
if (fromPort.node === toPort.node) return false;
|
|
||||||
return !fromPort.node.lines.allInputNodes.includes(toPort.node);
|
|
||||||
},
|
|
||||||
|
|
||||||
// 内容变化回调
|
|
||||||
onContentChange: (ctx, event) => {
|
|
||||||
if (ctx.document.disposed) return;
|
|
||||||
const data = ctx.document.toJSON();
|
|
||||||
onSave(data);
|
|
||||||
},
|
|
||||||
|
|
||||||
// 插件
|
|
||||||
plugins: () => [
|
|
||||||
createMinimapPlugin({}),
|
|
||||||
createFreeSnapPlugin({}),
|
|
||||||
createFreeNodePanelPlugin({}),
|
|
||||||
createFreeLinesPlugin({}),
|
|
||||||
],
|
|
||||||
}),
|
|
||||||
[initialData, nodeRegistries, onSave]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## 5. 模态框集成 (Modal Integration)
|
|
||||||
|
|
||||||
### 替换 visualWorkflowModal.tsx
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
// src/pages/scenario/flowgramWorkflowModal.tsx
|
|
||||||
import React, { useState, useEffect } from 'react';
|
|
||||||
import { Modal } from 'antd';
|
|
||||||
import { FlowgramEditor } from './flowgram/Editor';
|
|
||||||
import intl from 'react-intl-universal';
|
|
||||||
|
|
||||||
interface FlowgramWorkflowModalProps {
|
|
||||||
visible: boolean;
|
|
||||||
scenario?: any;
|
|
||||||
onOk: (scenario: any) => void;
|
|
||||||
onCancel: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const FlowgramWorkflowModal: React.FC<FlowgramWorkflowModalProps> = ({
|
|
||||||
visible,
|
|
||||||
scenario,
|
|
||||||
onOk,
|
|
||||||
onCancel,
|
|
||||||
}) => {
|
|
||||||
const [workflowData, setWorkflowData] = useState<any>(null);
|
|
||||||
const [name, setName] = useState('');
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (scenario) {
|
|
||||||
setName(scenario.name || '');
|
|
||||||
setWorkflowData(scenario.workflowGraph || getInitialData());
|
|
||||||
} else {
|
|
||||||
setName('');
|
|
||||||
setWorkflowData(getInitialData());
|
|
||||||
}
|
|
||||||
}, [scenario, visible]);
|
|
||||||
|
|
||||||
const getInitialData = () => ({
|
|
||||||
nodes: [
|
|
||||||
{
|
|
||||||
id: 'start_0',
|
|
||||||
type: 'start',
|
|
||||||
meta: { position: { x: 100, y: 300 } },
|
|
||||||
data: { title: '开始' },
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'end_0',
|
|
||||||
type: 'end',
|
|
||||||
meta: { position: { x: 800, y: 300 } },
|
|
||||||
data: { title: '结束' },
|
|
||||||
},
|
|
||||||
],
|
|
||||||
edges: [],
|
|
||||||
});
|
|
||||||
|
|
||||||
const handleSave = (data: any) => {
|
|
||||||
setWorkflowData(data);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleOk = () => {
|
|
||||||
onOk({
|
|
||||||
...scenario,
|
|
||||||
name,
|
|
||||||
workflowGraph: workflowData,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Modal
|
|
||||||
title={scenario ? intl.get('编辑场景') : intl.get('新建场景')}
|
|
||||||
open={visible}
|
|
||||||
onOk={handleOk}
|
|
||||||
onCancel={onCancel}
|
|
||||||
width="90%"
|
|
||||||
style={{ top: 20 }}
|
|
||||||
>
|
|
||||||
<div style={{ marginBottom: 16 }}>
|
|
||||||
<input
|
|
||||||
placeholder="场景名称"
|
|
||||||
value={name}
|
|
||||||
onChange={(e) => setName(e.target.value)}
|
|
||||||
style={{ width: '100%', padding: '8px' }}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
{workflowData && (
|
|
||||||
<FlowgramEditor
|
|
||||||
initialData={workflowData}
|
|
||||||
onSave={handleSave}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</Modal>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
```
|
|
||||||
|
|
||||||
## 6. 在主页面中使用 (Usage in Main Page)
|
|
||||||
|
|
||||||
### 更新 index.tsx
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
// src/pages/scenario/index.tsx
|
|
||||||
import { FlowgramWorkflowModal } from './flowgramWorkflowModal';
|
|
||||||
|
|
||||||
// 替换原来的
|
|
||||||
// import { VisualWorkflowModal } from './visualWorkflowModal';
|
|
||||||
|
|
||||||
// 使用
|
|
||||||
<FlowgramWorkflowModal
|
|
||||||
visible={modalVisible}
|
|
||||||
scenario={editingScenario}
|
|
||||||
onOk={handleSaveScenario}
|
|
||||||
onCancel={() => setModalVisible(false)}
|
|
||||||
/>
|
|
||||||
```
|
|
||||||
|
|
||||||
## 7. 后端兼容性 (Backend Compatibility)
|
|
||||||
|
|
||||||
### 数据转换工具 (Data Conversion)
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
// src/pages/scenario/flowgram/utils/dataConverter.ts
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 将 Flowgram 格式转换为后端格式
|
|
||||||
*/
|
|
||||||
export function convertFlowgramToBackend(flowgramData: any) {
|
|
||||||
return {
|
|
||||||
nodes: flowgramData.nodes.map((node: any) => ({
|
|
||||||
id: node.id,
|
|
||||||
type: node.type,
|
|
||||||
position: node.meta?.position || { x: 0, y: 0 },
|
|
||||||
data: node.data,
|
|
||||||
})),
|
|
||||||
edges: flowgramData.edges.map((edge: any) => ({
|
|
||||||
id: `${edge.sourceNodeID}-${edge.targetNodeID}`,
|
|
||||||
source: edge.sourceNodeID,
|
|
||||||
target: edge.targetNodeID,
|
|
||||||
sourcePort: edge.sourcePortID,
|
|
||||||
})),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 将后端格式转换为 Flowgram 格式
|
|
||||||
*/
|
|
||||||
export function convertBackendToFlowgram(backendData: any) {
|
|
||||||
return {
|
|
||||||
nodes: backendData.nodes.map((node: any) => ({
|
|
||||||
id: node.id,
|
|
||||||
type: node.type,
|
|
||||||
meta: {
|
|
||||||
position: node.position,
|
|
||||||
},
|
|
||||||
data: node.data,
|
|
||||||
})),
|
|
||||||
edges: backendData.edges.map((edge: any) => ({
|
|
||||||
sourceNodeID: edge.source,
|
|
||||||
targetNodeID: edge.target,
|
|
||||||
sourcePortID: edge.sourcePort,
|
|
||||||
})),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## 8. CSS 样式 (Styles)
|
|
||||||
|
|
||||||
### 导入 Flowgram 样式
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
// src/pages/scenario/flowgram/Editor.tsx
|
|
||||||
import '@flowgram.ai/free-layout-editor/index.css';
|
|
||||||
|
|
||||||
// 自定义样式
|
|
||||||
const customStyles = `
|
|
||||||
.flowgram-editor {
|
|
||||||
width: 100%;
|
|
||||||
height: 600px;
|
|
||||||
border: 1px solid #d9d9d9;
|
|
||||||
border-radius: 4px;
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
```
|
|
||||||
|
|
||||||
## 9. 测试清单 (Testing Checklist)
|
|
||||||
|
|
||||||
- [ ] 依赖安装成功
|
|
||||||
- [ ] 节点可以正常创建和拖拽
|
|
||||||
- [ ] 节点可以连接
|
|
||||||
- [ ] 节点配置面板正常显示
|
|
||||||
- [ ] 保存功能正常
|
|
||||||
- [ ] 与后端图执行引擎兼容
|
|
||||||
- [ ] 可以编辑现有场景
|
|
||||||
- [ ] 所有节点类型都可用
|
|
||||||
|
|
||||||
## 10. 故障排查 (Troubleshooting)
|
|
||||||
|
|
||||||
### 常见问题
|
|
||||||
|
|
||||||
**Q: Flowgram 插件包无法安装**
|
|
||||||
A: 使用 `npm install --legacy-peer-deps` 或 `pnpm install`
|
|
||||||
|
|
||||||
**Q: TypeScript 类型错误**
|
|
||||||
A: 添加类型声明文件或使用 `// @ts-ignore`
|
|
||||||
|
|
||||||
**Q: 样式不显示**
|
|
||||||
A: 确保导入了 `@flowgram.ai/free-layout-editor/index.css`
|
|
||||||
|
|
||||||
**Q: 节点不显示**
|
|
||||||
A: 检查节点注册是否正确,formMeta 是否完整
|
|
||||||
|
|
||||||
## 11. 参考资源 (Resources)
|
|
||||||
|
|
||||||
- Flowgram 官方 Demo: https://github.com/bytedance/flowgram.ai/tree/main/apps/demo-free-layout
|
|
||||||
- Flowgram 文档: https://flowgram.ai/
|
|
||||||
- 当前实现: src/pages/scenario/visualWorkflowModal.tsx (React Flow 版本)
|
|
||||||
|
|
||||||
## 总结 (Summary)
|
|
||||||
|
|
||||||
这个迁移涉及:
|
|
||||||
1. 替换依赖包(React Flow -> Flowgram)
|
|
||||||
2. 重写节点注册系统
|
|
||||||
3. 重新实现编辑器组件
|
|
||||||
4. 适配数据格式
|
|
||||||
5. 保持后端兼容性
|
|
||||||
|
|
||||||
预计工作量:8-12 小时
|
|
||||||
难度:中等
|
|
||||||
风险:中等(主要是 Flowgram 文档不完整)
|
|
||||||
@@ -1,352 +0,0 @@
|
|||||||
# 场景模式实现总结 (Scenario Mode Implementation Summary)
|
|
||||||
|
|
||||||
## 📊 实现统计 (Implementation Statistics)
|
|
||||||
|
|
||||||
- **新增文件**: 8 个 (8 new files)
|
|
||||||
- **修改文件**: 6 个 (6 modified files)
|
|
||||||
- **代码行数**: ~2,100 行新增代码 (~2,100 lines of new code)
|
|
||||||
- **功能数量**: 5 种触发器 + 4 种动作 (5 triggers + 4 actions)
|
|
||||||
- **语言支持**: 中文 + 英文 (Chinese + English)
|
|
||||||
|
|
||||||
## 🎯 核心功能实现 (Core Features Implemented)
|
|
||||||
|
|
||||||
### 1. 数据模型 (Data Models)
|
|
||||||
```
|
|
||||||
back/data/scenario.ts - 场景数据模型 (117 lines)
|
|
||||||
back/data/scenarioLog.ts - 日志数据模型 (58 lines)
|
|
||||||
```
|
|
||||||
|
|
||||||
**特性**:
|
|
||||||
- 完整的场景配置存储
|
|
||||||
- 触发器、条件、动作的灵活配置
|
|
||||||
- 执行统计和状态跟踪
|
|
||||||
- 详细的日志记录
|
|
||||||
|
|
||||||
### 2. 后端服务 (Backend Service)
|
|
||||||
```
|
|
||||||
back/services/scenario.ts - 场景服务 (501 lines)
|
|
||||||
```
|
|
||||||
|
|
||||||
**核心功能**:
|
|
||||||
- ✅ 场景生命周期管理(创建、更新、删除)
|
|
||||||
- ✅ 5 种触发器实现
|
|
||||||
- ✅ 条件评估引擎
|
|
||||||
- ✅ 动作执行引擎
|
|
||||||
- ✅ 失败熔断机制
|
|
||||||
- ✅ 自适应重试策略
|
|
||||||
- ✅ 完整的日志系统
|
|
||||||
|
|
||||||
### 3. API 接口 (API Endpoints)
|
|
||||||
```
|
|
||||||
back/api/scenario.ts - REST API (214 lines)
|
|
||||||
```
|
|
||||||
|
|
||||||
**端点列表**:
|
|
||||||
- `GET /api/scenarios` - 获取场景列表
|
|
||||||
- `POST /api/scenarios` - 创建场景
|
|
||||||
- `PUT /api/scenarios` - 更新场景
|
|
||||||
- `DELETE /api/scenarios` - 删除场景
|
|
||||||
- `POST /api/scenarios/:id/trigger` - 手动触发
|
|
||||||
- `GET /api/scenarios/:id/webhook` - 获取 Webhook URL
|
|
||||||
- `GET /api/scenarios/logs` - 查询日志
|
|
||||||
- `POST /api/scenarios/webhook/:token` - Webhook 触发
|
|
||||||
|
|
||||||
### 4. 前端界面 (Frontend UI)
|
|
||||||
```
|
|
||||||
src/pages/scenario/index.tsx - 主页面 (318 lines)
|
|
||||||
src/pages/scenario/modal.tsx - 编辑器 (443 lines)
|
|
||||||
src/pages/scenario/logModal.tsx - 日志查看 (130 lines)
|
|
||||||
```
|
|
||||||
|
|
||||||
**界面功能**:
|
|
||||||
- 📋 场景列表管理
|
|
||||||
- ✏️ 可视化场景编辑器
|
|
||||||
- 🔧 动态触发器配置
|
|
||||||
- 🧩 条件构建器 (AND/OR)
|
|
||||||
- ⚡ 动作配置器
|
|
||||||
- 📊 执行统计展示
|
|
||||||
- 📝 日志查看器
|
|
||||||
- 🔗 Webhook 管理
|
|
||||||
|
|
||||||
### 5. 国际化支持 (i18n)
|
|
||||||
```
|
|
||||||
src/locales/zh-CN.json - 中文翻译 (+72 entries)
|
|
||||||
src/locales/en-US.json - 英文翻译 (+72 entries)
|
|
||||||
```
|
|
||||||
|
|
||||||
## 🔧 技术架构 (Technical Architecture)
|
|
||||||
|
|
||||||
```
|
|
||||||
┌─────────────────────────────────────────────────────────┐
|
|
||||||
│ 前端层 (Frontend) │
|
|
||||||
├─────────────────────────────────────────────────────────┤
|
|
||||||
│ 场景列表 │ 场景编辑器 │ 日志查看器 │
|
|
||||||
│ (List) │ (Editor) │ (Log Viewer) │
|
|
||||||
└─────────────────────────────────────────────────────────┘
|
|
||||||
↕ HTTP API
|
|
||||||
┌─────────────────────────────────────────────────────────┐
|
|
||||||
│ API 层 (API Layer) │
|
|
||||||
├─────────────────────────────────────────────────────────┤
|
|
||||||
│ 场景管理 │ 手动触发 │ Webhook │ 日志 │
|
|
||||||
│ (CRUD) │ (Trigger) │ (External) │ (Logs) │
|
|
||||||
└─────────────────────────────────────────────────────────┘
|
|
||||||
↕ Service Layer
|
|
||||||
┌─────────────────────────────────────────────────────────┐
|
|
||||||
│ 服务层 (Service Layer) │
|
|
||||||
├─────────────────────────────────────────────────────────┤
|
|
||||||
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
|
|
||||||
│ │ 触发器管理 │ │ 条件评估引擎 │ │ 动作执行引擎 │ │
|
|
||||||
│ │ (Triggers) │ │ (Conditions) │ │ (Actions) │ │
|
|
||||||
│ └──────────────┘ └──────────────┘ └──────────────┘ │
|
|
||||||
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
|
|
||||||
│ │ 失败熔断 │ │ 重试策略 │ │ 日志记录 │ │
|
|
||||||
│ │ (Breaker) │ │ (Retry) │ │ (Logging) │ │
|
|
||||||
│ └──────────────┘ └──────────────┘ └──────────────┘ │
|
|
||||||
└─────────────────────────────────────────────────────────┘
|
|
||||||
↕ Data Layer
|
|
||||||
┌─────────────────────────────────────────────────────────┐
|
|
||||||
│ 数据层 (Data Layer) │
|
|
||||||
├─────────────────────────────────────────────────────────┤
|
|
||||||
│ Scenario 表 │ ScenarioLog 表 │
|
|
||||||
│ (场景配置) │ (执行日志) │
|
|
||||||
└─────────────────────────────────────────────────────────┘
|
|
||||||
```
|
|
||||||
|
|
||||||
## 🎨 触发器详解 (Trigger Details)
|
|
||||||
|
|
||||||
### 1. Variable Monitor (变量监听)
|
|
||||||
```javascript
|
|
||||||
{
|
|
||||||
triggerType: 'variable',
|
|
||||||
triggerConfig: {
|
|
||||||
watchPath: '/path/to/watch'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
**工作原理**: 使用 chokidar 监控文件系统变化
|
|
||||||
|
|
||||||
### 2. Webhook Trigger (Webhook 触发)
|
|
||||||
```javascript
|
|
||||||
{
|
|
||||||
triggerType: 'webhook',
|
|
||||||
triggerConfig: {
|
|
||||||
token: 'auto-generated-or-custom'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
**工作原理**: 生成唯一 Token,通过 HTTP POST 接收触发
|
|
||||||
|
|
||||||
### 3. Task Status Trigger (任务状态)
|
|
||||||
```javascript
|
|
||||||
{
|
|
||||||
triggerType: 'task_status',
|
|
||||||
triggerConfig: {
|
|
||||||
cronId: 123,
|
|
||||||
status: 'success' // or 'failure'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
**工作原理**: 监听定时任务执行结果
|
|
||||||
|
|
||||||
### 4. Time Trigger (时间触发)
|
|
||||||
```javascript
|
|
||||||
{
|
|
||||||
triggerType: 'time',
|
|
||||||
triggerConfig: {
|
|
||||||
schedule: '0 0 * * *' // Cron expression
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
**工作原理**: 使用 Cron 表达式定时触发
|
|
||||||
|
|
||||||
### 5. System Event Trigger (系统事件)
|
|
||||||
```javascript
|
|
||||||
{
|
|
||||||
triggerType: 'system_event',
|
|
||||||
triggerConfig: {
|
|
||||||
eventType: 'disk_space', // or 'memory'
|
|
||||||
threshold: 80, // percentage
|
|
||||||
checkInterval: 60000 // milliseconds
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
**工作原理**: 定期检查系统资源使用率
|
|
||||||
|
|
||||||
## 🧩 条件逻辑示例 (Condition Logic Examples)
|
|
||||||
|
|
||||||
### AND 逻辑(全部满足)
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"conditionLogic": "AND",
|
|
||||||
"conditions": [
|
|
||||||
{ "field": "status", "operator": "equals", "value": "success" },
|
|
||||||
{ "field": "branch", "operator": "equals", "value": "main" }
|
|
||||||
]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### OR 逻辑(任一满足)
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"conditionLogic": "OR",
|
|
||||||
"conditions": [
|
|
||||||
{ "field": "branch", "operator": "equals", "value": "main" },
|
|
||||||
{ "field": "branch", "operator": "equals", "value": "develop" }
|
|
||||||
]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 支持的操作符
|
|
||||||
- `equals` - 等于
|
|
||||||
- `not_equals` - 不等于
|
|
||||||
- `greater_than` - 大于
|
|
||||||
- `less_than` - 小于
|
|
||||||
- `contains` - 包含
|
|
||||||
- `not_contains` - 不包含
|
|
||||||
|
|
||||||
## ⚡ 动作类型详解 (Action Types)
|
|
||||||
|
|
||||||
### 1. Run Task (运行任务)
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"type": "run_task",
|
|
||||||
"cronId": 123
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 2. Set Variable (设置变量)
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"type": "set_variable",
|
|
||||||
"name": "DEPLOY_STATUS",
|
|
||||||
"value": "completed"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 3. Execute Command (执行命令)
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"type": "execute_command",
|
|
||||||
"command": "rm -rf /tmp/cache/*"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 4. Send Notification (发送通知)
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"type": "send_notification",
|
|
||||||
"message": "Deployment completed successfully"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## 🛡️ 可靠性机制 (Reliability Mechanisms)
|
|
||||||
|
|
||||||
### 失败熔断 (Circuit Breaker)
|
|
||||||
```javascript
|
|
||||||
{
|
|
||||||
failureThreshold: 3, // 连续失败 3 次后自动禁用
|
|
||||||
consecutiveFailures: 0 // 当前连续失败次数
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 自适应重试 (Adaptive Retry)
|
|
||||||
```javascript
|
|
||||||
{
|
|
||||||
retryStrategy: {
|
|
||||||
maxRetries: 3, // 最多重试 3 次
|
|
||||||
retryDelay: 5, // 基础延迟 5 秒
|
|
||||||
backoffMultiplier: 2 // 每次延迟翻倍
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 重试延迟: 5s, 10s, 20s
|
|
||||||
```
|
|
||||||
|
|
||||||
### 延迟执行 (Delayed Execution)
|
|
||||||
```javascript
|
|
||||||
{
|
|
||||||
delayExecution: 30 // 触发后延迟 30 秒执行
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## 📈 统计信息 (Statistics)
|
|
||||||
|
|
||||||
每个场景实时跟踪:
|
|
||||||
- `executionCount` - 总执行次数
|
|
||||||
- `successCount` - 成功次数
|
|
||||||
- `failureCount` - 失败次数
|
|
||||||
- `consecutiveFailures` - 连续失败次数
|
|
||||||
- `lastTriggeredAt` - 最后触发时间
|
|
||||||
- `lastExecutedAt` - 最后执行时间
|
|
||||||
|
|
||||||
## 🔍 日志系统 (Logging System)
|
|
||||||
|
|
||||||
每次执行记录:
|
|
||||||
- 触发数据 (`triggerData`)
|
|
||||||
- 条件匹配结果 (`conditionsMatched`)
|
|
||||||
- 执行状态 (`executionStatus`: success/failure/partial)
|
|
||||||
- 执行详情 (`executionDetails`)
|
|
||||||
- 错误信息 (`errorMessage`)
|
|
||||||
- 执行耗时 (`executionTime`)
|
|
||||||
- 重试次数 (`retriesAttempted`)
|
|
||||||
- 创建时间 (`createdAt`)
|
|
||||||
|
|
||||||
## 🎯 使用场景示例 (Use Case Examples)
|
|
||||||
|
|
||||||
### 场景 1: 配置文件自动重载
|
|
||||||
```
|
|
||||||
触发器: Variable Monitor
|
|
||||||
- 监听: /config/app.json
|
|
||||||
条件: 无
|
|
||||||
动作:
|
|
||||||
1. Execute Command - "pm2 reload app"
|
|
||||||
2. Send Notification - "配置已更新并重载"
|
|
||||||
```
|
|
||||||
|
|
||||||
### 场景 2: CI/CD 集成
|
|
||||||
```
|
|
||||||
触发器: Webhook
|
|
||||||
条件:
|
|
||||||
- event = "deployment" AND
|
|
||||||
- status = "success" AND
|
|
||||||
- branch = "main"
|
|
||||||
动作:
|
|
||||||
1. Run Task - 执行部署后清理任务
|
|
||||||
2. Set Variable - LAST_DEPLOY_TIME = ${timestamp}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 场景 3: 磁盘空间告警
|
|
||||||
```
|
|
||||||
触发器: System Event
|
|
||||||
- 事件类型: disk_space
|
|
||||||
- 阈值: 85%
|
|
||||||
条件: 无
|
|
||||||
动作:
|
|
||||||
1. Execute Command - "清理临时文件"
|
|
||||||
2. Send Notification - "磁盘空间不足,已自动清理"
|
|
||||||
```
|
|
||||||
|
|
||||||
### 场景 4: 任务失败自动重试
|
|
||||||
```
|
|
||||||
触发器: Task Status
|
|
||||||
- 任务 ID: 123
|
|
||||||
- 状态: failure
|
|
||||||
条件: 无
|
|
||||||
动作:
|
|
||||||
1. Run Task - 重新执行任务 123
|
|
||||||
高级设置:
|
|
||||||
- 延迟执行: 300 秒
|
|
||||||
- 失败熔断: 3 次
|
|
||||||
```
|
|
||||||
|
|
||||||
## 📝 总结 (Summary)
|
|
||||||
|
|
||||||
场景模式功能为青龙面板提供了强大的自动化能力:
|
|
||||||
|
|
||||||
✅ **完整实现** - 从数据模型到前端界面全栈实现
|
|
||||||
✅ **灵活配置** - 5 种触发器和 4 种动作满足各种需求
|
|
||||||
✅ **可靠稳定** - 失败熔断、重试机制确保系统稳定
|
|
||||||
✅ **易于使用** - 可视化配置,无需编写代码
|
|
||||||
✅ **完善文档** - 详细的使用指南和 API 文档
|
|
||||||
✅ **国际化** - 完整的中英文支持
|
|
||||||
|
|
||||||
这个功能将青龙面板从简单的定时任务管理工具升级为智能的自动化运维中枢!
|
|
||||||
@@ -41,6 +41,8 @@ Timed task management platform supporting Python3, JavaScript, Shell, Typescript
|
|||||||
|
|
||||||
The `latest` image is built on `alpine` and the `debian` image is built on `debian-slim`. If you need to use a dependency that is not supported by `alpine`, it is recommended that you use the `debian` image.
|
The `latest` image is built on `alpine` and the `debian` image is built on `debian-slim`. If you need to use a dependency that is not supported by `alpine`, it is recommended that you use the `debian` image.
|
||||||
|
|
||||||
|
**⚠️ Important**: If you need to run Docker as a **non-root user**, please use the `debian` image. Alpine's `crond` requires root privileges.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker pull whyour/qinglong:latest
|
docker pull whyour/qinglong:latest
|
||||||
docker pull whyour/qinglong:debian
|
docker pull whyour/qinglong:debian
|
||||||
|
|||||||
@@ -43,6 +43,8 @@ Timed task management platform supporting Python3, JavaScript, Shell, Typescript
|
|||||||
|
|
||||||
`latest` 镜像是基于 `alpine` 构建,`debian` 镜像是基于 `debian-slim` 构建。如果需要使用 `alpine` 不支持的依赖,建议使用 `debian` 镜像
|
`latest` 镜像是基于 `alpine` 构建,`debian` 镜像是基于 `debian-slim` 构建。如果需要使用 `alpine` 不支持的依赖,建议使用 `debian` 镜像
|
||||||
|
|
||||||
|
**⚠️ 重要提示**: 如果您需要以**非 root 用户**运行 Docker,请使用 `debian` 镜像。Alpine 的 `crond` 需要 root 权限。
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker pull whyour/qinglong:latest
|
docker pull whyour/qinglong:latest
|
||||||
docker pull whyour/qinglong:debian
|
docker pull whyour/qinglong:debian
|
||||||
|
|||||||
@@ -1,295 +0,0 @@
|
|||||||
# 场景模式功能文档 (Scenario Mode Documentation)
|
|
||||||
|
|
||||||
## 概述 (Overview)
|
|
||||||
|
|
||||||
场景模式是青龙面板的一个强大功能扩展,支持基于条件的自动化工作流。通过场景模式,您可以创建智能的自动化任务,响应各种触发器并执行相应的动作。
|
|
||||||
|
|
||||||
Scenario Mode is a powerful feature extension for Qinglong panel, supporting conditional automated workflows. With Scenario Mode, you can create intelligent automation tasks that respond to various triggers and execute corresponding actions.
|
|
||||||
|
|
||||||
## 功能特性 (Features)
|
|
||||||
|
|
||||||
### 1. 多样化触发器 (Diverse Triggers)
|
|
||||||
|
|
||||||
#### 变量监听 (Variable Monitor)
|
|
||||||
- 监控指定路径的文件变化
|
|
||||||
- 当配置文件或环境变量文件发生变化时自动触发
|
|
||||||
- 适用场景:配置文件热加载、环境变量同步等
|
|
||||||
|
|
||||||
#### Webhook 触发器 (Webhook Trigger)
|
|
||||||
- 提供唯一的 HTTP 端点接收外部触发
|
|
||||||
- 支持 POST 请求传递触发数据
|
|
||||||
- 适用场景:第三方系统集成、CI/CD 流程集成等
|
|
||||||
|
|
||||||
#### 任务状态触发器 (Task Status Trigger)
|
|
||||||
- 基于其他定时任务的执行状态触发
|
|
||||||
- 可在任务成功或失败时执行相应动作
|
|
||||||
- 适用场景:任务链、失败告警、成功后续处理等
|
|
||||||
|
|
||||||
#### 时间触发器 (Time Trigger)
|
|
||||||
- 使用标准 Cron 表达式定时触发
|
|
||||||
- 支持灵活的时间调度
|
|
||||||
- 适用场景:定期检查、定时清理、周期性任务等
|
|
||||||
|
|
||||||
#### 系统事件触发器 (System Event Trigger)
|
|
||||||
- 监控系统资源使用情况
|
|
||||||
- 支持磁盘使用率和内存使用率监控
|
|
||||||
- 达到设定阈值时自动触发
|
|
||||||
- 适用场景:资源告警、自动清理、容量管理等
|
|
||||||
|
|
||||||
### 2. 条件逻辑引擎 (Condition Logic Engine)
|
|
||||||
|
|
||||||
- 支持多条件组合,使用 AND 或 OR 逻辑
|
|
||||||
- 灵活的条件表达式:
|
|
||||||
- 等于 (equals)
|
|
||||||
- 不等于 (not_equals)
|
|
||||||
- 大于 (greater_than)
|
|
||||||
- 小于 (less_than)
|
|
||||||
- 包含 (contains)
|
|
||||||
- 不包含 (not_contains)
|
|
||||||
- 支持嵌套字段访问(使用点号分隔,如 `data.user.name`)
|
|
||||||
|
|
||||||
### 3. 动作执行引擎 (Action Execution Engine)
|
|
||||||
|
|
||||||
#### 运行任务 (Run Task)
|
|
||||||
- 执行指定的定时任务
|
|
||||||
- 通过任务 ID 引用
|
|
||||||
|
|
||||||
#### 设置变量 (Set Variable)
|
|
||||||
- 动态设置环境变量
|
|
||||||
- 自动更新环境配置
|
|
||||||
|
|
||||||
#### 执行命令 (Execute Command)
|
|
||||||
- 执行自定义 Shell 命令
|
|
||||||
- 获取命令输出
|
|
||||||
|
|
||||||
#### 发送通知 (Send Notification)
|
|
||||||
- 发送通知消息
|
|
||||||
- 可集成现有通知系统
|
|
||||||
|
|
||||||
### 4. 高级特性 (Advanced Features)
|
|
||||||
|
|
||||||
#### 延迟执行 (Delayed Execution)
|
|
||||||
- 在触发后延迟指定秒数执行
|
|
||||||
- 避免频繁触发
|
|
||||||
|
|
||||||
#### 失败熔断 (Failure Circuit Breaker)
|
|
||||||
- 设置连续失败阈值
|
|
||||||
- 达到阈值后自动禁用场景
|
|
||||||
- 防止资源浪费和错误累积
|
|
||||||
|
|
||||||
#### 自适应重试 (Adaptive Retry)
|
|
||||||
- 配置最大重试次数
|
|
||||||
- 设置重试延迟
|
|
||||||
- 支持退避倍数(每次重试延迟递增)
|
|
||||||
- 根据错误类型灵活调整
|
|
||||||
|
|
||||||
#### 执行日志 (Execution Logs)
|
|
||||||
- 记录每次触发和执行的详细信息
|
|
||||||
- 包括触发数据、条件匹配结果、执行状态、错误信息
|
|
||||||
- 支持按场景查询历史日志
|
|
||||||
|
|
||||||
## 使用指南 (Usage Guide)
|
|
||||||
|
|
||||||
### 创建场景 (Creating a Scenario)
|
|
||||||
|
|
||||||
1. 进入"场景模式"页面
|
|
||||||
2. 点击"新建场景"按钮
|
|
||||||
3. 填写基本信息:
|
|
||||||
- 名称:场景的标识名称
|
|
||||||
- 描述:场景的详细说明(可选)
|
|
||||||
|
|
||||||
4. 配置触发器:
|
|
||||||
- 选择触发类型
|
|
||||||
- 根据触发类型填写相应配置
|
|
||||||
|
|
||||||
5. 配置条件(可选):
|
|
||||||
- 选择条件逻辑(AND/OR)
|
|
||||||
- 添加多个条件
|
|
||||||
- 每个条件包含字段名、操作符和值
|
|
||||||
|
|
||||||
6. 配置动作:
|
|
||||||
- 至少添加一个动作
|
|
||||||
- 根据动作类型填写相应参数
|
|
||||||
|
|
||||||
7. 高级设置(可选):
|
|
||||||
- 延迟执行时间
|
|
||||||
- 失败熔断阈值
|
|
||||||
- 重试策略
|
|
||||||
|
|
||||||
8. 保存场景
|
|
||||||
|
|
||||||
### Webhook 使用示例 (Webhook Usage Example)
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# 1. 创建 Webhook 类型的场景
|
|
||||||
# 2. 获取 Webhook URL(点击"获取 Webhook"按钮)
|
|
||||||
# 3. 使用 curl 或其他工具发送请求
|
|
||||||
|
|
||||||
curl -X POST https://your-domain/api/scenarios/webhook/YOUR_TOKEN \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d '{
|
|
||||||
"event": "deployment",
|
|
||||||
"status": "success",
|
|
||||||
"branch": "main"
|
|
||||||
}'
|
|
||||||
```
|
|
||||||
|
|
||||||
### 条件配置示例 (Condition Configuration Examples)
|
|
||||||
|
|
||||||
#### 示例 1:检查事件类型
|
|
||||||
```
|
|
||||||
字段名: event
|
|
||||||
操作符: equals
|
|
||||||
值: deployment
|
|
||||||
```
|
|
||||||
|
|
||||||
#### 示例 2:检查状态和分支(AND 逻辑)
|
|
||||||
```
|
|
||||||
条件逻辑: AND
|
|
||||||
|
|
||||||
条件 1:
|
|
||||||
字段名: status
|
|
||||||
操作符: equals
|
|
||||||
值: success
|
|
||||||
|
|
||||||
条件 2:
|
|
||||||
字段名: branch
|
|
||||||
操作符: equals
|
|
||||||
值: main
|
|
||||||
```
|
|
||||||
|
|
||||||
#### 示例 3:多分支支持(OR 逻辑)
|
|
||||||
```
|
|
||||||
条件逻辑: OR
|
|
||||||
|
|
||||||
条件 1:
|
|
||||||
字段名: branch
|
|
||||||
操作符: equals
|
|
||||||
值: main
|
|
||||||
|
|
||||||
条件 2:
|
|
||||||
字段名: branch
|
|
||||||
操作符: equals
|
|
||||||
值: develop
|
|
||||||
```
|
|
||||||
|
|
||||||
### 动作配置示例 (Action Configuration Examples)
|
|
||||||
|
|
||||||
#### 示例 1:执行任务
|
|
||||||
```
|
|
||||||
动作类型: 运行任务
|
|
||||||
任务 ID: 123
|
|
||||||
```
|
|
||||||
|
|
||||||
#### 示例 2:设置环境变量
|
|
||||||
```
|
|
||||||
动作类型: 设置变量
|
|
||||||
变量名: DEPLOY_STATUS
|
|
||||||
变量值: completed
|
|
||||||
```
|
|
||||||
|
|
||||||
#### 示例 3:执行清理命令
|
|
||||||
```
|
|
||||||
动作类型: 执行命令
|
|
||||||
命令: rm -rf /tmp/cache/*
|
|
||||||
```
|
|
||||||
|
|
||||||
## API 接口 (API Endpoints)
|
|
||||||
|
|
||||||
### 场景管理 (Scenario Management)
|
|
||||||
|
|
||||||
- `GET /api/scenarios` - 获取场景列表
|
|
||||||
- `POST /api/scenarios` - 创建场景
|
|
||||||
- `PUT /api/scenarios` - 更新场景
|
|
||||||
- `DELETE /api/scenarios` - 删除场景
|
|
||||||
- `POST /api/scenarios/:id/trigger` - 手动触发场景
|
|
||||||
- `GET /api/scenarios/:id/webhook` - 获取 Webhook URL
|
|
||||||
|
|
||||||
### 日志查询 (Log Query)
|
|
||||||
|
|
||||||
- `GET /api/scenarios/logs?scenarioId={id}&limit={limit}` - 查询场景日志
|
|
||||||
|
|
||||||
### Webhook 端点 (Webhook Endpoint)
|
|
||||||
|
|
||||||
- `POST /api/scenarios/webhook/:token` - Webhook 触发端点
|
|
||||||
|
|
||||||
## 最佳实践 (Best Practices)
|
|
||||||
|
|
||||||
1. **合理设置失败熔断阈值**
|
|
||||||
- 建议设置为 3-5 次
|
|
||||||
- 避免长时间重复执行失败的场景
|
|
||||||
|
|
||||||
2. **使用条件过滤不必要的执行**
|
|
||||||
- 添加精确的条件判断
|
|
||||||
- 减少无效触发
|
|
||||||
|
|
||||||
3. **监控执行日志**
|
|
||||||
- 定期检查场景执行情况
|
|
||||||
- 及时发现和处理异常
|
|
||||||
|
|
||||||
4. **合理使用延迟执行**
|
|
||||||
- 避免高频触发导致的系统负载
|
|
||||||
- 给外部系统足够的处理时间
|
|
||||||
|
|
||||||
5. **配置适当的重试策略**
|
|
||||||
- 对临时性错误启用重试
|
|
||||||
- 使用退避倍数避免频繁重试
|
|
||||||
|
|
||||||
6. **保护敏感的 Webhook**
|
|
||||||
- 使用复杂的 Token
|
|
||||||
- 限制来源 IP(如需要)
|
|
||||||
- 添加必要的条件验证
|
|
||||||
|
|
||||||
## 注意事项 (Notes)
|
|
||||||
|
|
||||||
1. 变量监听功能需要读取文件系统权限
|
|
||||||
2. 系统事件监控会定期执行检查,可能产生额外的系统开销
|
|
||||||
3. Webhook Token 在场景创建后不可更改,如需更换请重建场景
|
|
||||||
4. 执行命令动作需要谨慎使用,确保命令安全可靠
|
|
||||||
5. 建议在生产环境使用前先在测试环境验证场景配置
|
|
||||||
|
|
||||||
## 故障排查 (Troubleshooting)
|
|
||||||
|
|
||||||
### 场景未触发
|
|
||||||
1. 检查场景是否启用
|
|
||||||
2. 验证触发器配置是否正确
|
|
||||||
3. 查看场景执行日志
|
|
||||||
|
|
||||||
### 条件未匹配
|
|
||||||
1. 检查字段名是否正确(区分大小写)
|
|
||||||
2. 验证操作符和值的类型匹配
|
|
||||||
3. 查看触发数据的实际内容
|
|
||||||
|
|
||||||
### 动作执行失败
|
|
||||||
1. 检查动作配置参数
|
|
||||||
2. 验证引用的任务 ID 是否存在
|
|
||||||
3. 确认命令语法正确
|
|
||||||
4. 查看详细的错误信息
|
|
||||||
|
|
||||||
### Webhook 无法访问
|
|
||||||
1. 确认场景触发类型为 Webhook
|
|
||||||
2. 检查 Token 是否正确
|
|
||||||
3. 验证请求格式(Content-Type: application/json)
|
|
||||||
|
|
||||||
## 更新日志 (Changelog)
|
|
||||||
|
|
||||||
### Version 1.0.0 (2025-11-08)
|
|
||||||
- ✨ 初始版本发布
|
|
||||||
- ✨ 支持 5 种触发器类型
|
|
||||||
- ✨ 支持 4 种动作类型
|
|
||||||
- ✨ 完整的条件逻辑引擎
|
|
||||||
- ✨ 失败熔断和重试机制
|
|
||||||
- ✨ 执行日志记录
|
|
||||||
- ✨ 中英文双语支持
|
|
||||||
|
|
||||||
## 贡献 (Contributing)
|
|
||||||
|
|
||||||
欢迎提交问题和建议!
|
|
||||||
|
|
||||||
Welcome to submit issues and suggestions!
|
|
||||||
|
|
||||||
## 许可证 (License)
|
|
||||||
|
|
||||||
遵循青龙面板的开源许可证
|
|
||||||
|
|
||||||
Follows the Qinglong panel's open source license
|
|
||||||
@@ -11,7 +11,6 @@ import system from './system';
|
|||||||
import subscription from './subscription';
|
import subscription from './subscription';
|
||||||
import update from './update';
|
import update from './update';
|
||||||
import health from './health';
|
import health from './health';
|
||||||
import scenario from './scenario';
|
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
const app = Router();
|
const app = Router();
|
||||||
@@ -27,7 +26,6 @@ export default () => {
|
|||||||
subscription(app);
|
subscription(app);
|
||||||
update(app);
|
update(app);
|
||||||
health(app);
|
health(app);
|
||||||
scenario(app);
|
|
||||||
|
|
||||||
return app;
|
return app;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,216 +0,0 @@
|
|||||||
import { Router, Request, Response, NextFunction } from 'express';
|
|
||||||
import { Container } from 'typedi';
|
|
||||||
import { Logger } from 'winston';
|
|
||||||
import ScenarioService from '../services/scenario';
|
|
||||||
import { celebrate, Joi } from 'celebrate';
|
|
||||||
|
|
||||||
const route = Router();
|
|
||||||
|
|
||||||
export default (app: Router) => {
|
|
||||||
app.use('/scenarios', route);
|
|
||||||
|
|
||||||
// List all scenarios
|
|
||||||
route.get(
|
|
||||||
'/',
|
|
||||||
async (req: Request, res: Response, next: NextFunction) => {
|
|
||||||
try {
|
|
||||||
const scenarioService = Container.get(ScenarioService);
|
|
||||||
const data = await scenarioService.list(req.query.searchValue as string);
|
|
||||||
return res.send({ code: 200, data });
|
|
||||||
} catch (e) {
|
|
||||||
return next(e);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
// Create a new scenario
|
|
||||||
route.post(
|
|
||||||
'/',
|
|
||||||
celebrate({
|
|
||||||
body: Joi.object({
|
|
||||||
name: Joi.string().required(),
|
|
||||||
description: Joi.string().optional().allow(''),
|
|
||||||
workflowGraph: Joi.object().optional(),
|
|
||||||
triggerType: Joi.string()
|
|
||||||
.valid('variable', 'webhook', 'task_status', 'time', 'system_event')
|
|
||||||
.optional(),
|
|
||||||
triggerConfig: Joi.object().optional(),
|
|
||||||
conditionLogic: Joi.string().valid('AND', 'OR').default('AND'),
|
|
||||||
conditions: Joi.array().optional().default([]),
|
|
||||||
actions: Joi.array().optional(),
|
|
||||||
retryStrategy: Joi.object({
|
|
||||||
maxRetries: Joi.number().min(0).max(10),
|
|
||||||
retryDelay: Joi.number().min(1),
|
|
||||||
backoffMultiplier: Joi.number().min(1).optional(),
|
|
||||||
errorTypes: Joi.array().items(Joi.string()).optional(),
|
|
||||||
}).optional(),
|
|
||||||
failureThreshold: Joi.number().min(1).default(3),
|
|
||||||
delayExecution: Joi.number().min(0).default(0),
|
|
||||||
isEnabled: Joi.number().valid(0, 1).default(1),
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
async (req: Request, res: Response, next: NextFunction) => {
|
|
||||||
try {
|
|
||||||
const scenarioService = Container.get(ScenarioService);
|
|
||||||
const data = await scenarioService.create(req.body);
|
|
||||||
return res.send({ code: 200, data });
|
|
||||||
} catch (e) {
|
|
||||||
return next(e);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
// Update a scenario
|
|
||||||
route.put(
|
|
||||||
'/',
|
|
||||||
celebrate({
|
|
||||||
body: Joi.object({
|
|
||||||
id: Joi.number().required(),
|
|
||||||
name: Joi.string().optional(),
|
|
||||||
description: Joi.string().optional().allow(''),
|
|
||||||
workflowGraph: Joi.object().optional(),
|
|
||||||
triggerType: Joi.string()
|
|
||||||
.valid('variable', 'webhook', 'task_status', 'time', 'system_event')
|
|
||||||
.optional(),
|
|
||||||
triggerConfig: Joi.object().optional(),
|
|
||||||
conditionLogic: Joi.string().valid('AND', 'OR').optional(),
|
|
||||||
conditions: Joi.array().optional(),
|
|
||||||
actions: Joi.array().optional(),
|
|
||||||
retryStrategy: Joi.object({
|
|
||||||
maxRetries: Joi.number().min(0).max(10),
|
|
||||||
retryDelay: Joi.number().min(1),
|
|
||||||
backoffMultiplier: Joi.number().min(1).optional(),
|
|
||||||
errorTypes: Joi.array().items(Joi.string()).optional(),
|
|
||||||
}).optional(),
|
|
||||||
failureThreshold: Joi.number().min(1).optional(),
|
|
||||||
delayExecution: Joi.number().min(0).optional(),
|
|
||||||
isEnabled: Joi.number().valid(0, 1).optional(),
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
async (req: Request, res: Response, next: NextFunction) => {
|
|
||||||
try {
|
|
||||||
const scenarioService = Container.get(ScenarioService);
|
|
||||||
const data = await scenarioService.update(req.body);
|
|
||||||
return res.send({ code: 200, data });
|
|
||||||
} catch (e) {
|
|
||||||
return next(e);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
// Delete scenarios
|
|
||||||
route.delete(
|
|
||||||
'/',
|
|
||||||
celebrate({
|
|
||||||
body: Joi.array().items(Joi.number().required()),
|
|
||||||
}),
|
|
||||||
async (req: Request, res: Response, next: NextFunction) => {
|
|
||||||
try {
|
|
||||||
const scenarioService = Container.get(ScenarioService);
|
|
||||||
const data = await scenarioService.remove(req.body);
|
|
||||||
return res.send({ code: 200, data });
|
|
||||||
} catch (e) {
|
|
||||||
return next(e);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
// Get scenario logs
|
|
||||||
route.get(
|
|
||||||
'/logs',
|
|
||||||
async (req: Request, res: Response, next: NextFunction) => {
|
|
||||||
try {
|
|
||||||
const scenarioService = Container.get(ScenarioService);
|
|
||||||
const scenarioId = req.query.scenarioId
|
|
||||||
? parseInt(req.query.scenarioId as string)
|
|
||||||
: undefined;
|
|
||||||
const limit = req.query.limit
|
|
||||||
? parseInt(req.query.limit as string)
|
|
||||||
: 100;
|
|
||||||
const data = await scenarioService.getLogs(scenarioId, limit);
|
|
||||||
return res.send({ code: 200, data });
|
|
||||||
} catch (e) {
|
|
||||||
return next(e);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
// Manually trigger a scenario
|
|
||||||
route.post(
|
|
||||||
'/:id/trigger',
|
|
||||||
celebrate({
|
|
||||||
params: Joi.object({
|
|
||||||
id: Joi.number().required(),
|
|
||||||
}),
|
|
||||||
body: Joi.object().optional().default({}),
|
|
||||||
}),
|
|
||||||
async (req: Request, res: Response, next: NextFunction) => {
|
|
||||||
try {
|
|
||||||
const scenarioService = Container.get(ScenarioService);
|
|
||||||
await scenarioService.triggerScenario(
|
|
||||||
parseInt(req.params.id),
|
|
||||||
req.body,
|
|
||||||
);
|
|
||||||
return res.send({ code: 200, message: 'Scenario triggered successfully' });
|
|
||||||
} catch (e) {
|
|
||||||
return next(e);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
// Webhook endpoint for external triggers
|
|
||||||
route.post(
|
|
||||||
'/webhook/:token',
|
|
||||||
async (req: Request, res: Response, next: NextFunction) => {
|
|
||||||
try {
|
|
||||||
const scenarioService = Container.get(ScenarioService);
|
|
||||||
const scenario = await scenarioService.findByWebhookToken(
|
|
||||||
req.params.token,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!scenario) {
|
|
||||||
return res.status(404).send({ code: 404, message: 'Invalid webhook token' });
|
|
||||||
}
|
|
||||||
|
|
||||||
await scenarioService.triggerScenario(scenario.id!, {
|
|
||||||
...req.body,
|
|
||||||
headers: req.headers,
|
|
||||||
query: req.query,
|
|
||||||
webhookTriggered: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
return res.send({ code: 200, message: 'Webhook received and scenario triggered' });
|
|
||||||
} catch (e) {
|
|
||||||
return next(e);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
// Get webhook URL for a scenario
|
|
||||||
route.get(
|
|
||||||
'/:id/webhook',
|
|
||||||
celebrate({
|
|
||||||
params: Joi.object({
|
|
||||||
id: Joi.number().required(),
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
async (req: Request, res: Response, next: NextFunction) => {
|
|
||||||
try {
|
|
||||||
const scenarioService = Container.get(ScenarioService);
|
|
||||||
const token = scenarioService.getWebhookToken(parseInt(req.params.id));
|
|
||||||
|
|
||||||
if (!token) {
|
|
||||||
return res.status(404).send({
|
|
||||||
code: 404,
|
|
||||||
message: 'Webhook token not found. Ensure the scenario trigger type is webhook.'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const webhookUrl = `${req.protocol}://${req.get('host')}/api/scenarios/webhook/${token}`;
|
|
||||||
return res.send({ code: 200, data: { token, webhookUrl } });
|
|
||||||
} catch (e) {
|
|
||||||
return next(e);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -129,6 +129,7 @@ export default (app: Router) => {
|
|||||||
content: Joi.string().optional().allow(''),
|
content: Joi.string().optional().allow(''),
|
||||||
originFilename: Joi.string().optional().allow(''),
|
originFilename: Joi.string().optional().allow(''),
|
||||||
directory: Joi.string().optional().allow(''),
|
directory: Joi.string().optional().allow(''),
|
||||||
|
file: Joi.string().optional().allow(''),
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
async (req: Request, res: Response, next: NextFunction) => {
|
async (req: Request, res: Response, next: NextFunction) => {
|
||||||
@@ -175,6 +176,7 @@ export default (app: Router) => {
|
|||||||
path,
|
path,
|
||||||
`${originFilename.replace(/\//g, '')}`,
|
`${originFilename.replace(/\//g, '')}`,
|
||||||
);
|
);
|
||||||
|
await fs.mkdir(path, { recursive: true });
|
||||||
const filePath = join(path, `${filename.replace(/\//g, '')}`);
|
const filePath = join(path, `${filename.replace(/\//g, '')}`);
|
||||||
const fileExists = await fileExist(filePath);
|
const fileExists = await fileExist(filePath);
|
||||||
if (fileExists) {
|
if (fileExists) {
|
||||||
|
|||||||
+23
-2
@@ -14,6 +14,7 @@ import {
|
|||||||
} from '../config/util';
|
} from '../config/util';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import multer from 'multer';
|
import multer from 'multer';
|
||||||
|
import { logStreamManager } from '../shared/logStreamManager';
|
||||||
|
|
||||||
const route = Router();
|
const route = Router();
|
||||||
const storage = multer.diskStorage({
|
const storage = multer.diskStorage({
|
||||||
@@ -276,17 +277,19 @@ export default (app: Router) => {
|
|||||||
res.setHeader('QL-Task-Log', `${logPath}`);
|
res.setHeader('QL-Task-Log', `${logPath}`);
|
||||||
},
|
},
|
||||||
onEnd: async (cp, endTime, diff) => {
|
onEnd: async (cp, endTime, diff) => {
|
||||||
|
// Close the stream after task completion
|
||||||
|
await logStreamManager.closeStream(await handleLogPath(logPath));
|
||||||
res.end();
|
res.end();
|
||||||
},
|
},
|
||||||
onError: async (message: string) => {
|
onError: async (message: string) => {
|
||||||
res.write(message);
|
res.write(message);
|
||||||
const absolutePath = await handleLogPath(logPath);
|
const absolutePath = await handleLogPath(logPath);
|
||||||
await fs.appendFile(absolutePath, message);
|
await logStreamManager.write(absolutePath, message);
|
||||||
},
|
},
|
||||||
onLog: async (message: string) => {
|
onLog: async (message: string) => {
|
||||||
res.write(message);
|
res.write(message);
|
||||||
const absolutePath = await handleLogPath(logPath);
|
const absolutePath = await handleLogPath(logPath);
|
||||||
await fs.appendFile(absolutePath, message);
|
await logStreamManager.write(absolutePath, message);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@@ -423,6 +426,24 @@ export default (app: Router) => {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
route.put(
|
||||||
|
'/config/global-ssh-key',
|
||||||
|
celebrate({
|
||||||
|
body: Joi.object({
|
||||||
|
globalSshKey: Joi.string().allow('').allow(null),
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
async (req: Request, res: Response, next: NextFunction) => {
|
||||||
|
try {
|
||||||
|
const systemService = Container.get(SystemService);
|
||||||
|
const result = await systemService.updateGlobalSshKey(req.body);
|
||||||
|
res.send(result);
|
||||||
|
} catch (e) {
|
||||||
|
return next(e);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
route.put(
|
route.put(
|
||||||
'/config/dependence-clean',
|
'/config/dependence-clean',
|
||||||
celebrate({
|
celebrate({
|
||||||
|
|||||||
+3
-2
@@ -8,7 +8,7 @@ import path from 'path';
|
|||||||
import { v4 as uuidV4 } from 'uuid';
|
import { v4 as uuidV4 } from 'uuid';
|
||||||
import rateLimit from 'express-rate-limit';
|
import rateLimit from 'express-rate-limit';
|
||||||
import config from '../config';
|
import config from '../config';
|
||||||
import { isDemoEnv } from '../config/util';
|
import { isDemoEnv, getToken } from '../config/util';
|
||||||
const route = Router();
|
const route = Router();
|
||||||
|
|
||||||
const storage = multer.diskStorage({
|
const storage = multer.diskStorage({
|
||||||
@@ -56,7 +56,8 @@ export default (app: Router) => {
|
|||||||
const logger: Logger = Container.get('logger');
|
const logger: Logger = Container.get('logger');
|
||||||
try {
|
try {
|
||||||
const userService = Container.get(UserService);
|
const userService = Container.get(UserService);
|
||||||
await userService.logout(req.platform);
|
const token = getToken(req);
|
||||||
|
await userService.logout(req.platform, token);
|
||||||
res.send({ code: 200 });
|
res.send({ code: 200 });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return next(e);
|
return next(e);
|
||||||
|
|||||||
+80
-16
@@ -24,6 +24,7 @@ class Application {
|
|||||||
private grpcServerService?: GrpcServerService;
|
private grpcServerService?: GrpcServerService;
|
||||||
private isShuttingDown = false;
|
private isShuttingDown = false;
|
||||||
private workerMetadataMap = new Map<number, WorkerMetadata>();
|
private workerMetadataMap = new Map<number, WorkerMetadata>();
|
||||||
|
private httpWorker?: Worker;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.app = express();
|
this.app = express();
|
||||||
@@ -53,21 +54,54 @@ class Application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private startMasterProcess() {
|
private startMasterProcess() {
|
||||||
this.forkWorker('http');
|
// Fork gRPC worker first and wait for it to be ready
|
||||||
this.forkWorker('grpc');
|
const grpcWorker = this.forkWorker('grpc');
|
||||||
|
|
||||||
|
// Wait for gRPC worker to signal it's ready before starting HTTP worker
|
||||||
|
this.waitForWorkerReady(grpcWorker, 30000)
|
||||||
|
.then(() => {
|
||||||
|
Logger.info('✌️ gRPC worker is ready, starting HTTP worker');
|
||||||
|
this.httpWorker = this.forkWorker('http');
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
Logger.error('✌️ Failed to wait for gRPC worker:', error);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
|
|
||||||
cluster.on('exit', (worker, code, signal) => {
|
cluster.on('exit', (worker, code, signal) => {
|
||||||
const metadata = this.workerMetadataMap.get(worker.id);
|
const metadata = this.workerMetadataMap.get(worker.id);
|
||||||
if (metadata) {
|
if (metadata) {
|
||||||
if (!this.isShuttingDown) {
|
if (!this.isShuttingDown) {
|
||||||
Logger.error(
|
Logger.error(
|
||||||
`${metadata.serviceType} worker ${worker.process.pid} died (${signal || code
|
`✌️ ${metadata.serviceType} worker ${worker.process.pid} died (${signal || code
|
||||||
}). Restarting...`,
|
}). Restarting...`,
|
||||||
);
|
);
|
||||||
const newWorker = this.forkWorker(metadata.serviceType);
|
// If gRPC worker died, restart it and wait for it to be ready
|
||||||
Logger.info(
|
if (metadata.serviceType === 'grpc') {
|
||||||
`Restarted ${metadata.serviceType} worker (New PID: ${newWorker.process.pid})`,
|
const newGrpcWorker = this.forkWorker('grpc');
|
||||||
);
|
this.waitForWorkerReady(newGrpcWorker, 30000)
|
||||||
|
.then(() => {
|
||||||
|
Logger.info('✌️ gRPC worker restarted and ready');
|
||||||
|
// Re-register cron jobs by notifying the HTTP worker
|
||||||
|
if (this.httpWorker) {
|
||||||
|
try {
|
||||||
|
this.httpWorker.send('reregister-crons');
|
||||||
|
Logger.info('✌️ Sent reregister-crons message to HTTP worker');
|
||||||
|
} catch (error) {
|
||||||
|
Logger.error('✌️ Failed to send reregister-crons message:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
Logger.error('✌️ Failed to restart gRPC worker:', error);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// For HTTP worker, just restart it
|
||||||
|
const newWorker = this.forkWorker(metadata.serviceType);
|
||||||
|
this.httpWorker = newWorker;
|
||||||
|
Logger.info(`✌️ Restarted ${metadata.serviceType} worker (PID: ${newWorker.process.pid})`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.workerMetadataMap.delete(worker.id);
|
this.workerMetadataMap.delete(worker.id);
|
||||||
@@ -77,6 +111,25 @@ class Application {
|
|||||||
this.setupMasterShutdown();
|
this.setupMasterShutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private waitForWorkerReady(worker: Worker, timeoutMs: number): Promise<void> {
|
||||||
|
return new Promise<void>((resolve, reject) => {
|
||||||
|
const messageHandler = (msg: any) => {
|
||||||
|
if (msg === 'ready') {
|
||||||
|
worker.removeListener('message', messageHandler);
|
||||||
|
clearTimeout(timeoutId);
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
worker.on('message', messageHandler);
|
||||||
|
|
||||||
|
// Timeout after specified milliseconds
|
||||||
|
const timeoutId = setTimeout(() => {
|
||||||
|
worker.removeListener('message', messageHandler);
|
||||||
|
reject(new Error(`Worker failed to start within ${timeoutMs / 1000} seconds`));
|
||||||
|
}, timeoutMs);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private forkWorker(serviceType: string): Worker {
|
private forkWorker(serviceType: string): Worker {
|
||||||
const worker = cluster.fork({ SERVICE_TYPE: serviceType });
|
const worker = cluster.fork({ SERVICE_TYPE: serviceType });
|
||||||
|
|
||||||
@@ -116,7 +169,7 @@ class Application {
|
|||||||
if (worker) {
|
if (worker) {
|
||||||
const exitPromise = new Promise<void>((resolve) => {
|
const exitPromise = new Promise<void>((resolve) => {
|
||||||
worker.once('exit', () => {
|
worker.once('exit', () => {
|
||||||
Logger.info(`Worker ${worker.process.pid} exited`);
|
Logger.info(`✌️ Worker ${worker.process.pid} exited`);
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -124,7 +177,7 @@ class Application {
|
|||||||
worker.send('shutdown');
|
worker.send('shutdown');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
Logger.warn(
|
Logger.warn(
|
||||||
`Failed to send shutdown to worker ${worker.process.pid}:`,
|
`✌️ Failed to send shutdown to worker ${worker.process.pid}:`,
|
||||||
error,
|
error,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -139,14 +192,14 @@ class Application {
|
|||||||
Promise.all(workerPromises),
|
Promise.all(workerPromises),
|
||||||
new Promise<void>((resolve) => {
|
new Promise<void>((resolve) => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
Logger.warn('Worker shutdown timeout reached');
|
Logger.warn('✌️ Worker shutdown timeout reached');
|
||||||
resolve();
|
resolve();
|
||||||
}, 10000);
|
}, 10000);
|
||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
Logger.error('Error during worker shutdown:', error);
|
Logger.error('✌️ Error during worker shutdown:', error);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -158,7 +211,7 @@ class Application {
|
|||||||
private async startWorkerProcess() {
|
private async startWorkerProcess() {
|
||||||
const serviceType = process.env.SERVICE_TYPE;
|
const serviceType = process.env.SERVICE_TYPE;
|
||||||
if (!serviceType || !['http', 'grpc'].includes(serviceType)) {
|
if (!serviceType || !['http', 'grpc'].includes(serviceType)) {
|
||||||
Logger.error('Invalid SERVICE_TYPE:', serviceType);
|
Logger.error('✌️ Invalid SERVICE_TYPE:', serviceType);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,7 +226,7 @@ class Application {
|
|||||||
|
|
||||||
process.send?.('ready');
|
process.send?.('ready');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
Logger.error(`${serviceType} worker failed:`, error);
|
Logger.error(`✌️ ${serviceType} worker failed:`, error);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -206,9 +259,20 @@ class Application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private setupWorkerShutdown(serviceType: string) {
|
private setupWorkerShutdown(serviceType: string) {
|
||||||
process.on('message', (msg) => {
|
process.on('message', async (msg) => {
|
||||||
if (msg === 'shutdown') {
|
if (msg === 'shutdown') {
|
||||||
this.gracefulShutdown(serviceType);
|
this.gracefulShutdown(serviceType);
|
||||||
|
} else if (msg === 'reregister-crons' && serviceType === 'http') {
|
||||||
|
// Re-register cron jobs when gRPC worker restarts
|
||||||
|
try {
|
||||||
|
Logger.info('✌️ Received reregister-crons message, re-registering cron jobs...');
|
||||||
|
const CronService = (await import('./services/cron')).default;
|
||||||
|
const cronService = Container.get(CronService);
|
||||||
|
await cronService.autosave_crontab();
|
||||||
|
Logger.info('✌️ Cron jobs re-registered successfully');
|
||||||
|
} catch (error) {
|
||||||
|
Logger.error('✌️ Failed to re-register cron jobs:', error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -229,7 +293,7 @@ class Application {
|
|||||||
}
|
}
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
Logger.error(`[${serviceType}] Error during shutdown:`, error);
|
Logger.error(`✌️ [${serviceType}] Error during shutdown:`, error);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -237,6 +301,6 @@ class Application {
|
|||||||
|
|
||||||
const app = new Application();
|
const app = new Application();
|
||||||
app.start().catch((error) => {
|
app.start().catch((error) => {
|
||||||
Logger.error('Application failed to start:', error);
|
Logger.error('🙅♀️ Application failed to start:', error);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -176,4 +176,5 @@ export default {
|
|||||||
sshdPath,
|
sshdPath,
|
||||||
systemLogPath,
|
systemLogPath,
|
||||||
dependenceCachePath,
|
dependenceCachePath,
|
||||||
|
maxTokensPerPlatform: 10, // Maximum number of concurrent sessions per platform
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -397,6 +397,21 @@ export function psTree(pid: number): Promise<number[]> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isPidRunning(pid: number): boolean {
|
||||||
|
// Validate PID: must be a positive integer
|
||||||
|
if (pid == null || pid <= 0 || !Number.isInteger(pid)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Signal 0 doesn't kill the process, just checks if it exists
|
||||||
|
process.kill(pid, 0);
|
||||||
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function killTask(pid: number) {
|
export async function killTask(pid: number) {
|
||||||
const pids = await psTree(pid);
|
const pids = await psTree(pid);
|
||||||
|
|
||||||
@@ -417,6 +432,27 @@ export async function getPid(cmd: string) {
|
|||||||
return pid ? Number(pid) : undefined;
|
return pid ? Number(pid) : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getAllPids(cmd: string): Promise<number[]> {
|
||||||
|
const taskCommand = `ps -eo pid,command | grep "${cmd}" | grep -v grep | awk '{print $1}'`;
|
||||||
|
const pidsStr = await promiseExec(taskCommand);
|
||||||
|
if (!pidsStr) return [];
|
||||||
|
return pidsStr
|
||||||
|
.split('\n')
|
||||||
|
.map((p) => Number(p.trim()))
|
||||||
|
.filter((p) => !isNaN(p) && p > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function killAllTasks(cmd: string): Promise<void> {
|
||||||
|
const pids = await getAllPids(cmd);
|
||||||
|
for (const pid of pids) {
|
||||||
|
try {
|
||||||
|
await killTask(pid);
|
||||||
|
} catch (error) {
|
||||||
|
// Ignore errors if process already terminated
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
interface IVersion {
|
interface IVersion {
|
||||||
version: string;
|
version: string;
|
||||||
changeLogLink: string;
|
changeLogLink: string;
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ export class Crontab {
|
|||||||
task_before?: string;
|
task_before?: string;
|
||||||
task_after?: string;
|
task_after?: string;
|
||||||
log_name?: string;
|
log_name?: string;
|
||||||
|
allow_multiple_instances?: 1 | 0;
|
||||||
|
|
||||||
constructor(options: Crontab) {
|
constructor(options: Crontab) {
|
||||||
this.name = options.name;
|
this.name = options.name;
|
||||||
@@ -47,6 +48,7 @@ export class Crontab {
|
|||||||
this.task_before = options.task_before;
|
this.task_before = options.task_before;
|
||||||
this.task_after = options.task_after;
|
this.task_after = options.task_after;
|
||||||
this.log_name = options.log_name;
|
this.log_name = options.log_name;
|
||||||
|
this.allow_multiple_instances = options.allow_multiple_instances || 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,4 +89,5 @@ export const CrontabModel = sequelize.define<CronInstance>('Crontab', {
|
|||||||
task_before: DataTypes.STRING,
|
task_before: DataTypes.STRING,
|
||||||
task_after: DataTypes.STRING,
|
task_after: DataTypes.STRING,
|
||||||
log_name: DataTypes.STRING,
|
log_name: DataTypes.STRING,
|
||||||
|
allow_multiple_instances: DataTypes.NUMBER,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -142,6 +142,7 @@ export class WebhookNotification extends NotificationBaseInfo {
|
|||||||
|
|
||||||
export class LarkNotification extends NotificationBaseInfo {
|
export class LarkNotification extends NotificationBaseInfo {
|
||||||
public larkKey = '';
|
public larkKey = '';
|
||||||
|
public larkSecret = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
export class NtfyNotification extends NotificationBaseInfo {
|
export class NtfyNotification extends NotificationBaseInfo {
|
||||||
|
|||||||
@@ -1,123 +0,0 @@
|
|||||||
import { sequelize } from '.';
|
|
||||||
import { DataTypes, Model } from 'sequelize';
|
|
||||||
|
|
||||||
export class Scenario {
|
|
||||||
id?: number;
|
|
||||||
name: string;
|
|
||||||
description?: string;
|
|
||||||
isEnabled?: 1 | 0;
|
|
||||||
workflowGraph?: any; // Flowgram workflow graph structure
|
|
||||||
triggerType?: string; // Deprecated: kept for backward compatibility
|
|
||||||
triggerConfig?: any; // Deprecated: kept for backward compatibility
|
|
||||||
conditionLogic?: 'AND' | 'OR'; // Deprecated: kept for backward compatibility
|
|
||||||
conditions?: any[]; // Deprecated: kept for backward compatibility
|
|
||||||
actions?: any[]; // Deprecated: kept for backward compatibility
|
|
||||||
retryStrategy?: {
|
|
||||||
maxRetries: number;
|
|
||||||
retryDelay: number; // in seconds
|
|
||||||
backoffMultiplier?: number;
|
|
||||||
errorTypes?: string[];
|
|
||||||
};
|
|
||||||
failureThreshold?: number; // Auto-disable after N consecutive failures
|
|
||||||
consecutiveFailures?: number;
|
|
||||||
delayExecution?: number; // Delay in seconds after trigger
|
|
||||||
lastTriggeredAt?: Date;
|
|
||||||
lastExecutedAt?: Date;
|
|
||||||
executionCount?: number;
|
|
||||||
failureCount?: number;
|
|
||||||
successCount?: number;
|
|
||||||
createdAt?: Date;
|
|
||||||
updatedAt?: Date;
|
|
||||||
|
|
||||||
constructor(options: Scenario) {
|
|
||||||
this.id = options.id;
|
|
||||||
this.name = options.name;
|
|
||||||
this.description = options.description;
|
|
||||||
this.isEnabled = options.isEnabled ?? 1;
|
|
||||||
this.workflowGraph = options.workflowGraph || null;
|
|
||||||
this.triggerType = options.triggerType;
|
|
||||||
this.triggerConfig = options.triggerConfig;
|
|
||||||
this.conditionLogic = options.conditionLogic || 'AND';
|
|
||||||
this.conditions = options.conditions || [];
|
|
||||||
this.actions = options.actions || [];
|
|
||||||
this.retryStrategy = options.retryStrategy;
|
|
||||||
this.failureThreshold = options.failureThreshold || 3;
|
|
||||||
this.consecutiveFailures = options.consecutiveFailures || 0;
|
|
||||||
this.delayExecution = options.delayExecution || 0;
|
|
||||||
this.lastTriggeredAt = options.lastTriggeredAt;
|
|
||||||
this.lastExecutedAt = options.lastExecutedAt;
|
|
||||||
this.executionCount = options.executionCount || 0;
|
|
||||||
this.failureCount = options.failureCount || 0;
|
|
||||||
this.successCount = options.successCount || 0;
|
|
||||||
this.createdAt = options.createdAt;
|
|
||||||
this.updatedAt = options.updatedAt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ScenarioInstance extends Model<Scenario, Scenario>, Scenario {}
|
|
||||||
|
|
||||||
export const ScenarioModel = sequelize.define<ScenarioInstance>('Scenario', {
|
|
||||||
name: {
|
|
||||||
type: DataTypes.STRING,
|
|
||||||
allowNull: false,
|
|
||||||
},
|
|
||||||
description: DataTypes.TEXT,
|
|
||||||
isEnabled: {
|
|
||||||
type: DataTypes.NUMBER,
|
|
||||||
defaultValue: 1,
|
|
||||||
},
|
|
||||||
workflowGraph: {
|
|
||||||
type: DataTypes.JSON,
|
|
||||||
allowNull: true,
|
|
||||||
},
|
|
||||||
triggerType: {
|
|
||||||
type: DataTypes.STRING,
|
|
||||||
allowNull: true,
|
|
||||||
},
|
|
||||||
triggerConfig: {
|
|
||||||
type: DataTypes.JSON,
|
|
||||||
allowNull: true,
|
|
||||||
},
|
|
||||||
conditionLogic: {
|
|
||||||
type: DataTypes.STRING,
|
|
||||||
defaultValue: 'AND',
|
|
||||||
},
|
|
||||||
conditions: {
|
|
||||||
type: DataTypes.JSON,
|
|
||||||
defaultValue: [],
|
|
||||||
},
|
|
||||||
actions: {
|
|
||||||
type: DataTypes.JSON,
|
|
||||||
defaultValue: [],
|
|
||||||
},
|
|
||||||
retryStrategy: {
|
|
||||||
type: DataTypes.JSON,
|
|
||||||
allowNull: true,
|
|
||||||
},
|
|
||||||
failureThreshold: {
|
|
||||||
type: DataTypes.NUMBER,
|
|
||||||
defaultValue: 3,
|
|
||||||
},
|
|
||||||
consecutiveFailures: {
|
|
||||||
type: DataTypes.NUMBER,
|
|
||||||
defaultValue: 0,
|
|
||||||
},
|
|
||||||
delayExecution: {
|
|
||||||
type: DataTypes.NUMBER,
|
|
||||||
defaultValue: 0,
|
|
||||||
},
|
|
||||||
lastTriggeredAt: DataTypes.DATE,
|
|
||||||
lastExecutedAt: DataTypes.DATE,
|
|
||||||
executionCount: {
|
|
||||||
type: DataTypes.NUMBER,
|
|
||||||
defaultValue: 0,
|
|
||||||
},
|
|
||||||
failureCount: {
|
|
||||||
type: DataTypes.NUMBER,
|
|
||||||
defaultValue: 0,
|
|
||||||
},
|
|
||||||
successCount: {
|
|
||||||
type: DataTypes.NUMBER,
|
|
||||||
defaultValue: 0,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
import { sequelize } from '.';
|
|
||||||
import { DataTypes, Model } from 'sequelize';
|
|
||||||
|
|
||||||
export class ScenarioLog {
|
|
||||||
id?: number;
|
|
||||||
scenarioId: number;
|
|
||||||
scenarioName?: string;
|
|
||||||
triggerData?: any; // The data that triggered the scenario
|
|
||||||
conditionsMatched?: boolean;
|
|
||||||
executionStatus?: 'success' | 'failure' | 'partial';
|
|
||||||
executionDetails?: any; // Details about actions executed
|
|
||||||
errorMessage?: string;
|
|
||||||
executionTime?: number; // Time taken in milliseconds
|
|
||||||
retriesAttempted?: number;
|
|
||||||
createdAt?: Date;
|
|
||||||
|
|
||||||
constructor(options: ScenarioLog) {
|
|
||||||
this.id = options.id;
|
|
||||||
this.scenarioId = options.scenarioId;
|
|
||||||
this.scenarioName = options.scenarioName;
|
|
||||||
this.triggerData = options.triggerData;
|
|
||||||
this.conditionsMatched = options.conditionsMatched;
|
|
||||||
this.executionStatus = options.executionStatus;
|
|
||||||
this.executionDetails = options.executionDetails;
|
|
||||||
this.errorMessage = options.errorMessage;
|
|
||||||
this.executionTime = options.executionTime;
|
|
||||||
this.retriesAttempted = options.retriesAttempted || 0;
|
|
||||||
this.createdAt = options.createdAt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ScenarioLogInstance
|
|
||||||
extends Model<ScenarioLog, ScenarioLog>,
|
|
||||||
ScenarioLog {}
|
|
||||||
|
|
||||||
export const ScenarioLogModel = sequelize.define<ScenarioLogInstance>(
|
|
||||||
'ScenarioLog',
|
|
||||||
{
|
|
||||||
scenarioId: {
|
|
||||||
type: DataTypes.NUMBER,
|
|
||||||
allowNull: false,
|
|
||||||
},
|
|
||||||
scenarioName: DataTypes.STRING,
|
|
||||||
triggerData: DataTypes.JSON,
|
|
||||||
conditionsMatched: DataTypes.BOOLEAN,
|
|
||||||
executionStatus: {
|
|
||||||
type: DataTypes.STRING,
|
|
||||||
allowNull: false,
|
|
||||||
},
|
|
||||||
executionDetails: DataTypes.JSON,
|
|
||||||
errorMessage: DataTypes.TEXT,
|
|
||||||
executionTime: DataTypes.NUMBER,
|
|
||||||
retriesAttempted: {
|
|
||||||
type: DataTypes.NUMBER,
|
|
||||||
defaultValue: 0,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
+15
-1
@@ -38,6 +38,7 @@ export interface SystemConfigInfo {
|
|||||||
pythonMirror?: string;
|
pythonMirror?: string;
|
||||||
linuxMirror?: string;
|
linuxMirror?: string;
|
||||||
timezone?: string;
|
timezone?: string;
|
||||||
|
globalSshKey?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LoginLogInfo {
|
export interface LoginLogInfo {
|
||||||
@@ -48,6 +49,19 @@ export interface LoginLogInfo {
|
|||||||
status?: LoginStatus;
|
status?: LoginStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface TokenInfo {
|
||||||
|
value: string;
|
||||||
|
timestamp: number;
|
||||||
|
ip: string;
|
||||||
|
address: string;
|
||||||
|
platform: string;
|
||||||
|
/**
|
||||||
|
* Token expiration time in seconds since Unix epoch.
|
||||||
|
* If undefined, the token uses JWT's built-in expiration.
|
||||||
|
*/
|
||||||
|
expiration?: number;
|
||||||
|
}
|
||||||
|
|
||||||
export interface AuthInfo {
|
export interface AuthInfo {
|
||||||
username: string;
|
username: string;
|
||||||
password: string;
|
password: string;
|
||||||
@@ -58,7 +72,7 @@ export interface AuthInfo {
|
|||||||
platform: string;
|
platform: string;
|
||||||
isTwoFactorChecking: boolean;
|
isTwoFactorChecking: boolean;
|
||||||
token: string;
|
token: string;
|
||||||
tokens: Record<string, string>;
|
tokens: Record<string, string | TokenInfo[]>;
|
||||||
twoFactorActivated: boolean;
|
twoFactorActivated: boolean;
|
||||||
twoFactorSecret: string;
|
twoFactorSecret: string;
|
||||||
avatar: string;
|
avatar: string;
|
||||||
|
|||||||
+32
-49
@@ -6,8 +6,6 @@ import { AppModel } from '../data/open';
|
|||||||
import { SystemModel } from '../data/system';
|
import { SystemModel } from '../data/system';
|
||||||
import { SubscriptionModel } from '../data/subscription';
|
import { SubscriptionModel } from '../data/subscription';
|
||||||
import { CrontabViewModel } from '../data/cronView';
|
import { CrontabViewModel } from '../data/cronView';
|
||||||
import { ScenarioModel } from '../data/scenario';
|
|
||||||
import { ScenarioLogModel } from '../data/scenarioLog';
|
|
||||||
import { sequelize } from '../data';
|
import { sequelize } from '../data';
|
||||||
|
|
||||||
export default async () => {
|
export default async () => {
|
||||||
@@ -19,55 +17,40 @@ export default async () => {
|
|||||||
await EnvModel.sync();
|
await EnvModel.sync();
|
||||||
await SubscriptionModel.sync();
|
await SubscriptionModel.sync();
|
||||||
await CrontabViewModel.sync();
|
await CrontabViewModel.sync();
|
||||||
await ScenarioModel.sync();
|
|
||||||
await ScenarioLogModel.sync();
|
|
||||||
|
|
||||||
// 初始化新增字段
|
// 初始化新增字段
|
||||||
try {
|
const migrations = [
|
||||||
await sequelize.query(
|
{
|
||||||
'alter table CrontabViews add column filterRelation VARCHAR(255)',
|
table: 'CrontabViews',
|
||||||
);
|
column: 'filterRelation',
|
||||||
} catch (error) {}
|
type: 'VARCHAR(255)',
|
||||||
try {
|
},
|
||||||
await sequelize.query(
|
{ table: 'Subscriptions', column: 'proxy', type: 'VARCHAR(255)' },
|
||||||
'alter table Subscriptions add column proxy VARCHAR(255)',
|
{ table: 'CrontabViews', column: 'type', type: 'NUMBER' },
|
||||||
);
|
{ table: 'Subscriptions', column: 'autoAddCron', type: 'NUMBER' },
|
||||||
} catch (error) {}
|
{ table: 'Subscriptions', column: 'autoDelCron', type: 'NUMBER' },
|
||||||
try {
|
{ table: 'Crontabs', column: 'sub_id', type: 'NUMBER' },
|
||||||
await sequelize.query('alter table CrontabViews add column type NUMBER');
|
{ table: 'Crontabs', column: 'extra_schedules', type: 'JSON' },
|
||||||
} catch (error) {}
|
{ table: 'Crontabs', column: 'task_before', type: 'TEXT' },
|
||||||
try {
|
{ table: 'Crontabs', column: 'task_after', type: 'TEXT' },
|
||||||
await sequelize.query(
|
{ table: 'Crontabs', column: 'log_name', type: 'VARCHAR(255)' },
|
||||||
'alter table Subscriptions add column autoAddCron NUMBER',
|
{
|
||||||
);
|
table: 'Crontabs',
|
||||||
} catch (error) {}
|
column: 'allow_multiple_instances',
|
||||||
try {
|
type: 'NUMBER',
|
||||||
await sequelize.query(
|
},
|
||||||
'alter table Subscriptions add column autoDelCron NUMBER',
|
{ table: 'Envs', column: 'isPinned', type: 'NUMBER' },
|
||||||
);
|
];
|
||||||
} catch (error) {}
|
|
||||||
try {
|
for (const migration of migrations) {
|
||||||
await sequelize.query('alter table Crontabs add column sub_id NUMBER');
|
try {
|
||||||
} catch (error) {}
|
await sequelize.query(
|
||||||
try {
|
`alter table ${migration.table} add column ${migration.column} ${migration.type}`,
|
||||||
await sequelize.query(
|
);
|
||||||
'alter table Crontabs add column extra_schedules JSON',
|
} catch (error) {
|
||||||
);
|
// Column already exists or other error, continue
|
||||||
} catch (error) {}
|
}
|
||||||
try {
|
}
|
||||||
await sequelize.query('alter table Crontabs add column task_before TEXT');
|
|
||||||
} catch (error) {}
|
|
||||||
try {
|
|
||||||
await sequelize.query('alter table Crontabs add column task_after TEXT');
|
|
||||||
} catch (error) {}
|
|
||||||
try {
|
|
||||||
await sequelize.query(
|
|
||||||
'alter table Crontabs add column log_name VARCHAR(255)',
|
|
||||||
);
|
|
||||||
} catch (error) { }
|
|
||||||
try {
|
|
||||||
await sequelize.query('alter table Envs add column isPinned NUMBER');
|
|
||||||
} catch (error) {}
|
|
||||||
|
|
||||||
Logger.info('✌️ DB loaded');
|
Logger.info('✌️ DB loaded');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
+15
-3
@@ -1,8 +1,9 @@
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
import fs from 'fs/promises';
|
import fs from 'fs/promises';
|
||||||
|
import os from 'os';
|
||||||
import chokidar from 'chokidar';
|
import chokidar from 'chokidar';
|
||||||
import config from '../config/index';
|
import config from '../config/index';
|
||||||
import { fileExist, promiseExec, rmPath } from '../config/util';
|
import Logger from './logger';
|
||||||
|
|
||||||
async function linkToNodeModule(src: string, dst?: string) {
|
async function linkToNodeModule(src: string, dst?: string) {
|
||||||
const target = path.join(config.rootPath, 'node_modules', dst || src);
|
const target = path.join(config.rootPath, 'node_modules', dst || src);
|
||||||
@@ -17,8 +18,18 @@ async function linkToNodeModule(src: string, dst?: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function linkCommand() {
|
async function linkCommand() {
|
||||||
const commandPath = await promiseExec('which node');
|
const homeDir = os.homedir();
|
||||||
const commandDir = path.dirname(commandPath);
|
let userBinDir = path.join(homeDir, 'bin');
|
||||||
|
|
||||||
|
try {
|
||||||
|
await fs.mkdir(userBinDir, { recursive: true });
|
||||||
|
await linkCommandToDir(userBinDir);
|
||||||
|
} catch (error) {
|
||||||
|
Logger.error('Linking command failed:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function linkCommandToDir(commandDir: string) {
|
||||||
const linkShell = [
|
const linkShell = [
|
||||||
{
|
{
|
||||||
src: 'update.sh',
|
src: 'update.sh',
|
||||||
@@ -42,6 +53,7 @@ async function linkCommand() {
|
|||||||
await fs.unlink(tmpTarget);
|
await fs.unlink(tmpTarget);
|
||||||
}
|
}
|
||||||
} catch (error) { }
|
} catch (error) { }
|
||||||
|
|
||||||
await fs.symlink(source, tmpTarget);
|
await fs.symlink(source, tmpTarget);
|
||||||
await fs.rename(tmpTarget, target);
|
await fs.rename(tmpTarget, target);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import rewrite from 'express-urlrewrite';
|
|||||||
import { errors } from 'celebrate';
|
import { errors } from 'celebrate';
|
||||||
import { serveEnv } from '../config/serverEnv';
|
import { serveEnv } from '../config/serverEnv';
|
||||||
import { IKeyvStore, shareStore } from '../shared/store';
|
import { IKeyvStore, shareStore } from '../shared/store';
|
||||||
|
import { isValidToken } from '../shared/auth';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
export default ({ app }: { app: Application }) => {
|
export default ({ app }: { app: Application }) => {
|
||||||
@@ -77,11 +78,8 @@ export default ({ app }: { app: Application }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const authInfo = await shareStore.getAuthInfo();
|
const authInfo = await shareStore.getAuthInfo();
|
||||||
if (authInfo && headerToken) {
|
if (isValidToken(authInfo, headerToken, req.platform)) {
|
||||||
const { token = '', tokens = {} } = authInfo;
|
return next();
|
||||||
if (headerToken === token || tokens[req.platform] === headerToken) {
|
|
||||||
return next();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const errorCode = headerToken ? 'invalid_token' : 'credentials_required';
|
const errorCode = headerToken ? 'invalid_token' : 'credentials_required';
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import { AuthDataType, SystemModel } from '../data/system';
|
|||||||
import SystemService from '../services/system';
|
import SystemService from '../services/system';
|
||||||
import UserService from '../services/user';
|
import UserService from '../services/user';
|
||||||
import { writeFile, readFile } from 'fs/promises';
|
import { writeFile, readFile } from 'fs/promises';
|
||||||
import { createRandomString, fileExist, safeJSONParse } from '../config/util';
|
import { createRandomString, fileExist, safeJSONParse, isPidRunning } from '../config/util';
|
||||||
import OpenService from '../services/open';
|
import OpenService from '../services/open';
|
||||||
import { shareStore } from '../shared/store';
|
import { shareStore } from '../shared/store';
|
||||||
import Logger from './logger';
|
import Logger from './logger';
|
||||||
@@ -132,7 +132,32 @@ export default async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// 初始化更新所有任务状态为空闲
|
// 初始化更新所有任务状态为空闲
|
||||||
await CrontabModel.update({ status: CrontabStatus.idle }, { where: {} });
|
// 但保留仍在运行的任务的状态
|
||||||
|
const allCrons = await CrontabModel.findAll({
|
||||||
|
attributes: ['id', 'pid'],
|
||||||
|
raw: true,
|
||||||
|
});
|
||||||
|
const idsToReset: number[] = [];
|
||||||
|
|
||||||
|
for (const cron of allCrons) {
|
||||||
|
// 如果任务有 PID 且进程仍在运行,则保持其状态
|
||||||
|
if (cron.pid != null && isPidRunning(cron.pid)) {
|
||||||
|
// 保留当前状态(running 或 queued)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// 收集需要重置的任务 ID
|
||||||
|
if (cron.id) {
|
||||||
|
idsToReset.push(cron.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 批量更新所有需要重置的任务
|
||||||
|
if (idsToReset.length > 0) {
|
||||||
|
await CrontabModel.update(
|
||||||
|
{ status: CrontabStatus.idle, pid: undefined },
|
||||||
|
{ where: { id: { [Op.in]: idsToReset } } }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// 初始化时执行一次所有的 ql repo 任务
|
// 初始化时执行一次所有的 ql repo 任务
|
||||||
CrontabModel.findAll({
|
CrontabModel.findAll({
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { Container } from 'typedi';
|
|||||||
import SystemService from '../services/system';
|
import SystemService from '../services/system';
|
||||||
import ScheduleService, { ScheduleTaskType } from '../services/schedule';
|
import ScheduleService, { ScheduleTaskType } from '../services/schedule';
|
||||||
import SubscriptionService from '../services/subscription';
|
import SubscriptionService from '../services/subscription';
|
||||||
|
import SshKeyService from '../services/sshKey';
|
||||||
import config from '../config';
|
import config from '../config';
|
||||||
import { fileExist } from '../config/util';
|
import { fileExist } from '../config/util';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
@@ -10,6 +11,7 @@ export default async () => {
|
|||||||
const systemService = Container.get(SystemService);
|
const systemService = Container.get(SystemService);
|
||||||
const scheduleService = Container.get(ScheduleService);
|
const scheduleService = Container.get(ScheduleService);
|
||||||
const subscriptionService = Container.get(SubscriptionService);
|
const subscriptionService = Container.get(SubscriptionService);
|
||||||
|
const sshKeyService = Container.get(SshKeyService);
|
||||||
|
|
||||||
// 生成内置token
|
// 生成内置token
|
||||||
let tokenCommand = `ts-node-transpile-only ${join(
|
let tokenCommand = `ts-node-transpile-only ${join(
|
||||||
@@ -57,6 +59,11 @@ export default async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
systemService.updateTimezone(data.info);
|
systemService.updateTimezone(data.info);
|
||||||
|
|
||||||
|
// Apply global SSH key if configured
|
||||||
|
if (data.info.globalSshKey) {
|
||||||
|
await sshKeyService.addGlobalSSHKey(data.info.globalSshKey, 'global');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await subscriptionService.setSshConfig();
|
await subscriptionService.setSshConfig();
|
||||||
|
|||||||
+11
-12
@@ -4,6 +4,7 @@ import { Container } from 'typedi';
|
|||||||
import SockService from '../services/sock';
|
import SockService from '../services/sock';
|
||||||
import { getPlatform } from '../config/util';
|
import { getPlatform } from '../config/util';
|
||||||
import { shareStore } from '../shared/store';
|
import { shareStore } from '../shared/store';
|
||||||
|
import { isValidToken } from '../shared/auth';
|
||||||
|
|
||||||
export default async ({ server }: { server: Server }) => {
|
export default async ({ server }: { server: Server }) => {
|
||||||
const echo = sockJs.createServer({ prefix: '/api/ws', log: () => {} });
|
const echo = sockJs.createServer({ prefix: '/api/ws', log: () => {} });
|
||||||
@@ -17,21 +18,19 @@ export default async ({ server }: { server: Server }) => {
|
|||||||
const authInfo = await shareStore.getAuthInfo();
|
const authInfo = await shareStore.getAuthInfo();
|
||||||
const platform = getPlatform(conn.headers['user-agent'] || '') || 'desktop';
|
const platform = getPlatform(conn.headers['user-agent'] || '') || 'desktop';
|
||||||
const headerToken = conn.url.replace(`${conn.pathname}?token=`, '');
|
const headerToken = conn.url.replace(`${conn.pathname}?token=`, '');
|
||||||
if (authInfo) {
|
|
||||||
const { token = '', tokens = {} } = authInfo;
|
|
||||||
if (headerToken === token || tokens[platform] === headerToken) {
|
|
||||||
sockService.addClient(conn);
|
|
||||||
|
|
||||||
conn.on('data', (message) => {
|
if (isValidToken(authInfo, headerToken, platform)) {
|
||||||
conn.write(message);
|
sockService.addClient(conn);
|
||||||
});
|
|
||||||
|
|
||||||
conn.on('close', function () {
|
conn.on('data', (message) => {
|
||||||
sockService.removeClient(conn);
|
conn.write(message);
|
||||||
});
|
});
|
||||||
|
|
||||||
return;
|
conn.on('close', function () {
|
||||||
}
|
sockService.removeClient(conn);
|
||||||
|
});
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
conn.close('404');
|
conn.close('404');
|
||||||
|
|||||||
@@ -97,6 +97,18 @@ message UpdateCronRequest {
|
|||||||
|
|
||||||
message DeleteCronsRequest { repeated int32 ids = 1; }
|
message DeleteCronsRequest { repeated int32 ids = 1; }
|
||||||
|
|
||||||
|
message GetCronsRequest {
|
||||||
|
optional string searchValue = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetCronByIdRequest { int32 id = 1; }
|
||||||
|
|
||||||
|
message EnableCronsRequest { repeated int32 ids = 1; }
|
||||||
|
|
||||||
|
message DisableCronsRequest { repeated int32 ids = 1; }
|
||||||
|
|
||||||
|
message RunCronsRequest { repeated int32 ids = 1; }
|
||||||
|
|
||||||
message CronsResponse {
|
message CronsResponse {
|
||||||
int32 code = 1;
|
int32 code = 1;
|
||||||
repeated CronItem data = 2;
|
repeated CronItem data = 2;
|
||||||
@@ -254,4 +266,9 @@ service Api {
|
|||||||
rpc CreateCron(CreateCronRequest) returns (CronResponse) {}
|
rpc CreateCron(CreateCronRequest) returns (CronResponse) {}
|
||||||
rpc UpdateCron(UpdateCronRequest) returns (CronResponse) {}
|
rpc UpdateCron(UpdateCronRequest) returns (CronResponse) {}
|
||||||
rpc DeleteCrons(DeleteCronsRequest) returns (Response) {}
|
rpc DeleteCrons(DeleteCronsRequest) returns (Response) {}
|
||||||
|
rpc GetCrons(GetCronsRequest) returns (CronsResponse) {}
|
||||||
|
rpc GetCronById(GetCronByIdRequest) returns (CronResponse) {}
|
||||||
|
rpc EnableCrons(EnableCronsRequest) returns (Response) {}
|
||||||
|
rpc DisableCrons(DisableCronsRequest) returns (Response) {}
|
||||||
|
rpc RunCrons(RunCronsRequest) returns (Response) {}
|
||||||
}
|
}
|
||||||
@@ -281,6 +281,26 @@ export interface DeleteCronsRequest {
|
|||||||
ids: number[];
|
ids: number[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface GetCronsRequest {
|
||||||
|
searchValue?: string | undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GetCronByIdRequest {
|
||||||
|
id: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface EnableCronsRequest {
|
||||||
|
ids: number[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DisableCronsRequest {
|
||||||
|
ids: number[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface RunCronsRequest {
|
||||||
|
ids: number[];
|
||||||
|
}
|
||||||
|
|
||||||
export interface CronsResponse {
|
export interface CronsResponse {
|
||||||
code: number;
|
code: number;
|
||||||
data: CronItem[];
|
data: CronItem[];
|
||||||
@@ -2207,6 +2227,332 @@ export const DeleteCronsRequest: MessageFns<DeleteCronsRequest> = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function createBaseGetCronsRequest(): GetCronsRequest {
|
||||||
|
return { searchValue: undefined };
|
||||||
|
}
|
||||||
|
|
||||||
|
export const GetCronsRequest: MessageFns<GetCronsRequest> = {
|
||||||
|
encode(message: GetCronsRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
|
||||||
|
if (message.searchValue !== undefined) {
|
||||||
|
writer.uint32(10).string(message.searchValue);
|
||||||
|
}
|
||||||
|
return writer;
|
||||||
|
},
|
||||||
|
|
||||||
|
decode(input: BinaryReader | Uint8Array, length?: number): GetCronsRequest {
|
||||||
|
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
|
||||||
|
let end = length === undefined ? reader.len : reader.pos + length;
|
||||||
|
const message = createBaseGetCronsRequest();
|
||||||
|
while (reader.pos < end) {
|
||||||
|
const tag = reader.uint32();
|
||||||
|
switch (tag >>> 3) {
|
||||||
|
case 1: {
|
||||||
|
if (tag !== 10) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
message.searchValue = reader.string();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ((tag & 7) === 4 || tag === 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
reader.skip(tag & 7);
|
||||||
|
}
|
||||||
|
return message;
|
||||||
|
},
|
||||||
|
|
||||||
|
fromJSON(object: any): GetCronsRequest {
|
||||||
|
return { searchValue: isSet(object.searchValue) ? globalThis.String(object.searchValue) : undefined };
|
||||||
|
},
|
||||||
|
|
||||||
|
toJSON(message: GetCronsRequest): unknown {
|
||||||
|
const obj: any = {};
|
||||||
|
if (message.searchValue !== undefined) {
|
||||||
|
obj.searchValue = message.searchValue;
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
},
|
||||||
|
|
||||||
|
create<I extends Exact<DeepPartial<GetCronsRequest>, I>>(base?: I): GetCronsRequest {
|
||||||
|
return GetCronsRequest.fromPartial(base ?? ({} as any));
|
||||||
|
},
|
||||||
|
fromPartial<I extends Exact<DeepPartial<GetCronsRequest>, I>>(object: I): GetCronsRequest {
|
||||||
|
const message = createBaseGetCronsRequest();
|
||||||
|
message.searchValue = object.searchValue ?? undefined;
|
||||||
|
return message;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
function createBaseGetCronByIdRequest(): GetCronByIdRequest {
|
||||||
|
return { id: 0 };
|
||||||
|
}
|
||||||
|
|
||||||
|
export const GetCronByIdRequest: MessageFns<GetCronByIdRequest> = {
|
||||||
|
encode(message: GetCronByIdRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
|
||||||
|
if (message.id !== 0) {
|
||||||
|
writer.uint32(8).int32(message.id);
|
||||||
|
}
|
||||||
|
return writer;
|
||||||
|
},
|
||||||
|
|
||||||
|
decode(input: BinaryReader | Uint8Array, length?: number): GetCronByIdRequest {
|
||||||
|
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
|
||||||
|
let end = length === undefined ? reader.len : reader.pos + length;
|
||||||
|
const message = createBaseGetCronByIdRequest();
|
||||||
|
while (reader.pos < end) {
|
||||||
|
const tag = reader.uint32();
|
||||||
|
switch (tag >>> 3) {
|
||||||
|
case 1: {
|
||||||
|
if (tag !== 8) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
message.id = reader.int32();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ((tag & 7) === 4 || tag === 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
reader.skip(tag & 7);
|
||||||
|
}
|
||||||
|
return message;
|
||||||
|
},
|
||||||
|
|
||||||
|
fromJSON(object: any): GetCronByIdRequest {
|
||||||
|
return { id: isSet(object.id) ? globalThis.Number(object.id) : 0 };
|
||||||
|
},
|
||||||
|
|
||||||
|
toJSON(message: GetCronByIdRequest): unknown {
|
||||||
|
const obj: any = {};
|
||||||
|
if (message.id !== 0) {
|
||||||
|
obj.id = Math.round(message.id);
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
},
|
||||||
|
|
||||||
|
create<I extends Exact<DeepPartial<GetCronByIdRequest>, I>>(base?: I): GetCronByIdRequest {
|
||||||
|
return GetCronByIdRequest.fromPartial(base ?? ({} as any));
|
||||||
|
},
|
||||||
|
fromPartial<I extends Exact<DeepPartial<GetCronByIdRequest>, I>>(object: I): GetCronByIdRequest {
|
||||||
|
const message = createBaseGetCronByIdRequest();
|
||||||
|
message.id = object.id ?? 0;
|
||||||
|
return message;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
function createBaseEnableCronsRequest(): EnableCronsRequest {
|
||||||
|
return { ids: [] };
|
||||||
|
}
|
||||||
|
|
||||||
|
export const EnableCronsRequest: MessageFns<EnableCronsRequest> = {
|
||||||
|
encode(message: EnableCronsRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
|
||||||
|
writer.uint32(10).fork();
|
||||||
|
for (const v of message.ids) {
|
||||||
|
writer.int32(v);
|
||||||
|
}
|
||||||
|
writer.join();
|
||||||
|
return writer;
|
||||||
|
},
|
||||||
|
|
||||||
|
decode(input: BinaryReader | Uint8Array, length?: number): EnableCronsRequest {
|
||||||
|
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
|
||||||
|
let end = length === undefined ? reader.len : reader.pos + length;
|
||||||
|
const message = createBaseEnableCronsRequest();
|
||||||
|
while (reader.pos < end) {
|
||||||
|
const tag = reader.uint32();
|
||||||
|
switch (tag >>> 3) {
|
||||||
|
case 1: {
|
||||||
|
if (tag === 8) {
|
||||||
|
message.ids.push(reader.int32());
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tag === 10) {
|
||||||
|
const end2 = reader.uint32() + reader.pos;
|
||||||
|
while (reader.pos < end2) {
|
||||||
|
message.ids.push(reader.int32());
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ((tag & 7) === 4 || tag === 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
reader.skip(tag & 7);
|
||||||
|
}
|
||||||
|
return message;
|
||||||
|
},
|
||||||
|
|
||||||
|
fromJSON(object: any): EnableCronsRequest {
|
||||||
|
return { ids: globalThis.Array.isArray(object?.ids) ? object.ids.map((e: any) => globalThis.Number(e)) : [] };
|
||||||
|
},
|
||||||
|
|
||||||
|
toJSON(message: EnableCronsRequest): unknown {
|
||||||
|
const obj: any = {};
|
||||||
|
if (message.ids?.length) {
|
||||||
|
obj.ids = message.ids.map((e) => Math.round(e));
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
},
|
||||||
|
|
||||||
|
create<I extends Exact<DeepPartial<EnableCronsRequest>, I>>(base?: I): EnableCronsRequest {
|
||||||
|
return EnableCronsRequest.fromPartial(base ?? ({} as any));
|
||||||
|
},
|
||||||
|
fromPartial<I extends Exact<DeepPartial<EnableCronsRequest>, I>>(object: I): EnableCronsRequest {
|
||||||
|
const message = createBaseEnableCronsRequest();
|
||||||
|
message.ids = object.ids?.map((e) => e) || [];
|
||||||
|
return message;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
function createBaseDisableCronsRequest(): DisableCronsRequest {
|
||||||
|
return { ids: [] };
|
||||||
|
}
|
||||||
|
|
||||||
|
export const DisableCronsRequest: MessageFns<DisableCronsRequest> = {
|
||||||
|
encode(message: DisableCronsRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
|
||||||
|
writer.uint32(10).fork();
|
||||||
|
for (const v of message.ids) {
|
||||||
|
writer.int32(v);
|
||||||
|
}
|
||||||
|
writer.join();
|
||||||
|
return writer;
|
||||||
|
},
|
||||||
|
|
||||||
|
decode(input: BinaryReader | Uint8Array, length?: number): DisableCronsRequest {
|
||||||
|
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
|
||||||
|
let end = length === undefined ? reader.len : reader.pos + length;
|
||||||
|
const message = createBaseDisableCronsRequest();
|
||||||
|
while (reader.pos < end) {
|
||||||
|
const tag = reader.uint32();
|
||||||
|
switch (tag >>> 3) {
|
||||||
|
case 1: {
|
||||||
|
if (tag === 8) {
|
||||||
|
message.ids.push(reader.int32());
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tag === 10) {
|
||||||
|
const end2 = reader.uint32() + reader.pos;
|
||||||
|
while (reader.pos < end2) {
|
||||||
|
message.ids.push(reader.int32());
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ((tag & 7) === 4 || tag === 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
reader.skip(tag & 7);
|
||||||
|
}
|
||||||
|
return message;
|
||||||
|
},
|
||||||
|
|
||||||
|
fromJSON(object: any): DisableCronsRequest {
|
||||||
|
return { ids: globalThis.Array.isArray(object?.ids) ? object.ids.map((e: any) => globalThis.Number(e)) : [] };
|
||||||
|
},
|
||||||
|
|
||||||
|
toJSON(message: DisableCronsRequest): unknown {
|
||||||
|
const obj: any = {};
|
||||||
|
if (message.ids?.length) {
|
||||||
|
obj.ids = message.ids.map((e) => Math.round(e));
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
},
|
||||||
|
|
||||||
|
create<I extends Exact<DeepPartial<DisableCronsRequest>, I>>(base?: I): DisableCronsRequest {
|
||||||
|
return DisableCronsRequest.fromPartial(base ?? ({} as any));
|
||||||
|
},
|
||||||
|
fromPartial<I extends Exact<DeepPartial<DisableCronsRequest>, I>>(object: I): DisableCronsRequest {
|
||||||
|
const message = createBaseDisableCronsRequest();
|
||||||
|
message.ids = object.ids?.map((e) => e) || [];
|
||||||
|
return message;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
function createBaseRunCronsRequest(): RunCronsRequest {
|
||||||
|
return { ids: [] };
|
||||||
|
}
|
||||||
|
|
||||||
|
export const RunCronsRequest: MessageFns<RunCronsRequest> = {
|
||||||
|
encode(message: RunCronsRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
|
||||||
|
writer.uint32(10).fork();
|
||||||
|
for (const v of message.ids) {
|
||||||
|
writer.int32(v);
|
||||||
|
}
|
||||||
|
writer.join();
|
||||||
|
return writer;
|
||||||
|
},
|
||||||
|
|
||||||
|
decode(input: BinaryReader | Uint8Array, length?: number): RunCronsRequest {
|
||||||
|
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
|
||||||
|
let end = length === undefined ? reader.len : reader.pos + length;
|
||||||
|
const message = createBaseRunCronsRequest();
|
||||||
|
while (reader.pos < end) {
|
||||||
|
const tag = reader.uint32();
|
||||||
|
switch (tag >>> 3) {
|
||||||
|
case 1: {
|
||||||
|
if (tag === 8) {
|
||||||
|
message.ids.push(reader.int32());
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tag === 10) {
|
||||||
|
const end2 = reader.uint32() + reader.pos;
|
||||||
|
while (reader.pos < end2) {
|
||||||
|
message.ids.push(reader.int32());
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ((tag & 7) === 4 || tag === 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
reader.skip(tag & 7);
|
||||||
|
}
|
||||||
|
return message;
|
||||||
|
},
|
||||||
|
|
||||||
|
fromJSON(object: any): RunCronsRequest {
|
||||||
|
return { ids: globalThis.Array.isArray(object?.ids) ? object.ids.map((e: any) => globalThis.Number(e)) : [] };
|
||||||
|
},
|
||||||
|
|
||||||
|
toJSON(message: RunCronsRequest): unknown {
|
||||||
|
const obj: any = {};
|
||||||
|
if (message.ids?.length) {
|
||||||
|
obj.ids = message.ids.map((e) => Math.round(e));
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
},
|
||||||
|
|
||||||
|
create<I extends Exact<DeepPartial<RunCronsRequest>, I>>(base?: I): RunCronsRequest {
|
||||||
|
return RunCronsRequest.fromPartial(base ?? ({} as any));
|
||||||
|
},
|
||||||
|
fromPartial<I extends Exact<DeepPartial<RunCronsRequest>, I>>(object: I): RunCronsRequest {
|
||||||
|
const message = createBaseRunCronsRequest();
|
||||||
|
message.ids = object.ids?.map((e) => e) || [];
|
||||||
|
return message;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
function createBaseCronsResponse(): CronsResponse {
|
function createBaseCronsResponse(): CronsResponse {
|
||||||
return { code: 0, data: [], message: undefined };
|
return { code: 0, data: [], message: undefined };
|
||||||
}
|
}
|
||||||
@@ -3976,6 +4322,51 @@ export const ApiService = {
|
|||||||
responseSerialize: (value: Response) => Buffer.from(Response.encode(value).finish()),
|
responseSerialize: (value: Response) => Buffer.from(Response.encode(value).finish()),
|
||||||
responseDeserialize: (value: Buffer) => Response.decode(value),
|
responseDeserialize: (value: Buffer) => Response.decode(value),
|
||||||
},
|
},
|
||||||
|
getCrons: {
|
||||||
|
path: "/com.ql.api.Api/GetCrons",
|
||||||
|
requestStream: false,
|
||||||
|
responseStream: false,
|
||||||
|
requestSerialize: (value: GetCronsRequest) => Buffer.from(GetCronsRequest.encode(value).finish()),
|
||||||
|
requestDeserialize: (value: Buffer) => GetCronsRequest.decode(value),
|
||||||
|
responseSerialize: (value: CronsResponse) => Buffer.from(CronsResponse.encode(value).finish()),
|
||||||
|
responseDeserialize: (value: Buffer) => CronsResponse.decode(value),
|
||||||
|
},
|
||||||
|
getCronById: {
|
||||||
|
path: "/com.ql.api.Api/GetCronById",
|
||||||
|
requestStream: false,
|
||||||
|
responseStream: false,
|
||||||
|
requestSerialize: (value: GetCronByIdRequest) => Buffer.from(GetCronByIdRequest.encode(value).finish()),
|
||||||
|
requestDeserialize: (value: Buffer) => GetCronByIdRequest.decode(value),
|
||||||
|
responseSerialize: (value: CronResponse) => Buffer.from(CronResponse.encode(value).finish()),
|
||||||
|
responseDeserialize: (value: Buffer) => CronResponse.decode(value),
|
||||||
|
},
|
||||||
|
enableCrons: {
|
||||||
|
path: "/com.ql.api.Api/EnableCrons",
|
||||||
|
requestStream: false,
|
||||||
|
responseStream: false,
|
||||||
|
requestSerialize: (value: EnableCronsRequest) => Buffer.from(EnableCronsRequest.encode(value).finish()),
|
||||||
|
requestDeserialize: (value: Buffer) => EnableCronsRequest.decode(value),
|
||||||
|
responseSerialize: (value: Response) => Buffer.from(Response.encode(value).finish()),
|
||||||
|
responseDeserialize: (value: Buffer) => Response.decode(value),
|
||||||
|
},
|
||||||
|
disableCrons: {
|
||||||
|
path: "/com.ql.api.Api/DisableCrons",
|
||||||
|
requestStream: false,
|
||||||
|
responseStream: false,
|
||||||
|
requestSerialize: (value: DisableCronsRequest) => Buffer.from(DisableCronsRequest.encode(value).finish()),
|
||||||
|
requestDeserialize: (value: Buffer) => DisableCronsRequest.decode(value),
|
||||||
|
responseSerialize: (value: Response) => Buffer.from(Response.encode(value).finish()),
|
||||||
|
responseDeserialize: (value: Buffer) => Response.decode(value),
|
||||||
|
},
|
||||||
|
runCrons: {
|
||||||
|
path: "/com.ql.api.Api/RunCrons",
|
||||||
|
requestStream: false,
|
||||||
|
responseStream: false,
|
||||||
|
requestSerialize: (value: RunCronsRequest) => Buffer.from(RunCronsRequest.encode(value).finish()),
|
||||||
|
requestDeserialize: (value: Buffer) => RunCronsRequest.decode(value),
|
||||||
|
responseSerialize: (value: Response) => Buffer.from(Response.encode(value).finish()),
|
||||||
|
responseDeserialize: (value: Buffer) => Response.decode(value),
|
||||||
|
},
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export interface ApiServer extends UntypedServiceImplementation {
|
export interface ApiServer extends UntypedServiceImplementation {
|
||||||
@@ -3993,6 +4384,11 @@ export interface ApiServer extends UntypedServiceImplementation {
|
|||||||
createCron: handleUnaryCall<CreateCronRequest, CronResponse>;
|
createCron: handleUnaryCall<CreateCronRequest, CronResponse>;
|
||||||
updateCron: handleUnaryCall<UpdateCronRequest, CronResponse>;
|
updateCron: handleUnaryCall<UpdateCronRequest, CronResponse>;
|
||||||
deleteCrons: handleUnaryCall<DeleteCronsRequest, Response>;
|
deleteCrons: handleUnaryCall<DeleteCronsRequest, Response>;
|
||||||
|
getCrons: handleUnaryCall<GetCronsRequest, CronsResponse>;
|
||||||
|
getCronById: handleUnaryCall<GetCronByIdRequest, CronResponse>;
|
||||||
|
enableCrons: handleUnaryCall<EnableCronsRequest, Response>;
|
||||||
|
disableCrons: handleUnaryCall<DisableCronsRequest, Response>;
|
||||||
|
runCrons: handleUnaryCall<RunCronsRequest, Response>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ApiClient extends Client {
|
export interface ApiClient extends Client {
|
||||||
@@ -4206,6 +4602,81 @@ export interface ApiClient extends Client {
|
|||||||
options: Partial<CallOptions>,
|
options: Partial<CallOptions>,
|
||||||
callback: (error: ServiceError | null, response: Response) => void,
|
callback: (error: ServiceError | null, response: Response) => void,
|
||||||
): ClientUnaryCall;
|
): ClientUnaryCall;
|
||||||
|
getCrons(
|
||||||
|
request: GetCronsRequest,
|
||||||
|
callback: (error: ServiceError | null, response: CronsResponse) => void,
|
||||||
|
): ClientUnaryCall;
|
||||||
|
getCrons(
|
||||||
|
request: GetCronsRequest,
|
||||||
|
metadata: Metadata,
|
||||||
|
callback: (error: ServiceError | null, response: CronsResponse) => void,
|
||||||
|
): ClientUnaryCall;
|
||||||
|
getCrons(
|
||||||
|
request: GetCronsRequest,
|
||||||
|
metadata: Metadata,
|
||||||
|
options: Partial<CallOptions>,
|
||||||
|
callback: (error: ServiceError | null, response: CronsResponse) => void,
|
||||||
|
): ClientUnaryCall;
|
||||||
|
getCronById(
|
||||||
|
request: GetCronByIdRequest,
|
||||||
|
callback: (error: ServiceError | null, response: CronResponse) => void,
|
||||||
|
): ClientUnaryCall;
|
||||||
|
getCronById(
|
||||||
|
request: GetCronByIdRequest,
|
||||||
|
metadata: Metadata,
|
||||||
|
callback: (error: ServiceError | null, response: CronResponse) => void,
|
||||||
|
): ClientUnaryCall;
|
||||||
|
getCronById(
|
||||||
|
request: GetCronByIdRequest,
|
||||||
|
metadata: Metadata,
|
||||||
|
options: Partial<CallOptions>,
|
||||||
|
callback: (error: ServiceError | null, response: CronResponse) => void,
|
||||||
|
): ClientUnaryCall;
|
||||||
|
enableCrons(
|
||||||
|
request: EnableCronsRequest,
|
||||||
|
callback: (error: ServiceError | null, response: Response) => void,
|
||||||
|
): ClientUnaryCall;
|
||||||
|
enableCrons(
|
||||||
|
request: EnableCronsRequest,
|
||||||
|
metadata: Metadata,
|
||||||
|
callback: (error: ServiceError | null, response: Response) => void,
|
||||||
|
): ClientUnaryCall;
|
||||||
|
enableCrons(
|
||||||
|
request: EnableCronsRequest,
|
||||||
|
metadata: Metadata,
|
||||||
|
options: Partial<CallOptions>,
|
||||||
|
callback: (error: ServiceError | null, response: Response) => void,
|
||||||
|
): ClientUnaryCall;
|
||||||
|
disableCrons(
|
||||||
|
request: DisableCronsRequest,
|
||||||
|
callback: (error: ServiceError | null, response: Response) => void,
|
||||||
|
): ClientUnaryCall;
|
||||||
|
disableCrons(
|
||||||
|
request: DisableCronsRequest,
|
||||||
|
metadata: Metadata,
|
||||||
|
callback: (error: ServiceError | null, response: Response) => void,
|
||||||
|
): ClientUnaryCall;
|
||||||
|
disableCrons(
|
||||||
|
request: DisableCronsRequest,
|
||||||
|
metadata: Metadata,
|
||||||
|
options: Partial<CallOptions>,
|
||||||
|
callback: (error: ServiceError | null, response: Response) => void,
|
||||||
|
): ClientUnaryCall;
|
||||||
|
runCrons(
|
||||||
|
request: RunCronsRequest,
|
||||||
|
callback: (error: ServiceError | null, response: Response) => void,
|
||||||
|
): ClientUnaryCall;
|
||||||
|
runCrons(
|
||||||
|
request: RunCronsRequest,
|
||||||
|
metadata: Metadata,
|
||||||
|
callback: (error: ServiceError | null, response: Response) => void,
|
||||||
|
): ClientUnaryCall;
|
||||||
|
runCrons(
|
||||||
|
request: RunCronsRequest,
|
||||||
|
metadata: Metadata,
|
||||||
|
options: Partial<CallOptions>,
|
||||||
|
callback: (error: ServiceError | null, response: Response) => void,
|
||||||
|
): ClientUnaryCall;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ApiClient = makeGenericClientConstructor(ApiService, "com.ql.api.Api") as unknown as {
|
export const ApiClient = makeGenericClientConstructor(ApiService, "com.ql.api.Api") as unknown as {
|
||||||
|
|||||||
@@ -30,6 +30,12 @@ import {
|
|||||||
UpdateCronRequest,
|
UpdateCronRequest,
|
||||||
DeleteCronsRequest,
|
DeleteCronsRequest,
|
||||||
CronResponse,
|
CronResponse,
|
||||||
|
GetCronsRequest,
|
||||||
|
CronsResponse,
|
||||||
|
GetCronByIdRequest,
|
||||||
|
EnableCronsRequest,
|
||||||
|
DisableCronsRequest,
|
||||||
|
RunCronsRequest,
|
||||||
} from '../protos/api';
|
} from '../protos/api';
|
||||||
import { NotificationInfo } from '../data/notify';
|
import { NotificationInfo } from '../data/notify';
|
||||||
|
|
||||||
@@ -323,3 +329,116 @@ export const deleteCrons = async (
|
|||||||
callback(e);
|
callback(e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getCrons = async (
|
||||||
|
call: ServerUnaryCall<GetCronsRequest, CronsResponse>,
|
||||||
|
callback: sendUnaryData<CronsResponse>,
|
||||||
|
) => {
|
||||||
|
try {
|
||||||
|
const cronService = Container.get(CronService);
|
||||||
|
const result = await cronService.crontabs({
|
||||||
|
searchValue: call.request.searchValue || '',
|
||||||
|
page: '0',
|
||||||
|
size: '0',
|
||||||
|
sorter: '',
|
||||||
|
filters: '',
|
||||||
|
queryString: '',
|
||||||
|
});
|
||||||
|
const data = result.data.map((x) => normalizeCronData(x as CronItem));
|
||||||
|
callback(null, {
|
||||||
|
code: 200,
|
||||||
|
data: data.filter((x): x is CronItem => x !== undefined),
|
||||||
|
});
|
||||||
|
} catch (e: any) {
|
||||||
|
callback(null, {
|
||||||
|
code: 500,
|
||||||
|
data: [],
|
||||||
|
message: e.message,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getCronById = async (
|
||||||
|
call: ServerUnaryCall<GetCronByIdRequest, CronResponse>,
|
||||||
|
callback: sendUnaryData<CronResponse>,
|
||||||
|
) => {
|
||||||
|
try {
|
||||||
|
if (!call.request.id) {
|
||||||
|
return callback(null, {
|
||||||
|
code: 400,
|
||||||
|
data: undefined,
|
||||||
|
message: 'id parameter is required',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const cronService = Container.get(CronService);
|
||||||
|
const data = (await cronService.getDb({ id: call.request.id })) as CronItem;
|
||||||
|
callback(null, { code: 200, data: normalizeCronData(data) });
|
||||||
|
} catch (e: any) {
|
||||||
|
callback(null, {
|
||||||
|
code: 404,
|
||||||
|
data: undefined,
|
||||||
|
message: e.message,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const enableCrons = async (
|
||||||
|
call: ServerUnaryCall<EnableCronsRequest, Response>,
|
||||||
|
callback: sendUnaryData<Response>,
|
||||||
|
) => {
|
||||||
|
try {
|
||||||
|
if (!call.request.ids || call.request.ids.length === 0) {
|
||||||
|
return callback(null, {
|
||||||
|
code: 400,
|
||||||
|
message: 'ids parameter is required',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const cronService = Container.get(CronService);
|
||||||
|
await cronService.enabled(call.request.ids);
|
||||||
|
callback(null, { code: 200 });
|
||||||
|
} catch (e: any) {
|
||||||
|
callback(e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const disableCrons = async (
|
||||||
|
call: ServerUnaryCall<DisableCronsRequest, Response>,
|
||||||
|
callback: sendUnaryData<Response>,
|
||||||
|
) => {
|
||||||
|
try {
|
||||||
|
if (!call.request.ids || call.request.ids.length === 0) {
|
||||||
|
return callback(null, {
|
||||||
|
code: 400,
|
||||||
|
message: 'ids parameter is required',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const cronService = Container.get(CronService);
|
||||||
|
await cronService.disabled(call.request.ids);
|
||||||
|
callback(null, { code: 200 });
|
||||||
|
} catch (e: any) {
|
||||||
|
callback(e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const runCrons = async (
|
||||||
|
call: ServerUnaryCall<RunCronsRequest, Response>,
|
||||||
|
callback: sendUnaryData<Response>,
|
||||||
|
) => {
|
||||||
|
try {
|
||||||
|
if (!call.request.ids || call.request.ids.length === 0) {
|
||||||
|
return callback(null, {
|
||||||
|
code: 400,
|
||||||
|
message: 'ids parameter is required',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const cronService = Container.get(CronService);
|
||||||
|
await cronService.run(call.request.ids);
|
||||||
|
callback(null, { code: 200 });
|
||||||
|
} catch (e: any) {
|
||||||
|
callback(e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
@@ -17,14 +17,11 @@ const check = async (
|
|||||||
return callback(null, { status: 1 });
|
return callback(null, { status: 1 });
|
||||||
}
|
}
|
||||||
|
|
||||||
const panelErrLog = await promiseExec(
|
const qinglongErrLog = await promiseExec(
|
||||||
`tail -n 300 ~/.pm2/logs/panel-error.log`,
|
`tail -n 300 ~/.pm2/logs/qinglong-error.log`,
|
||||||
);
|
|
||||||
const scheduleErrLog = await promiseExec(
|
|
||||||
`tail -n 300 ~/.pm2/logs/schedule-error.log`,
|
|
||||||
);
|
);
|
||||||
return callback(
|
return callback(
|
||||||
new Error(`${scheduleErrLog || ''}\n${panelErrLog || ''}\n${res}`.trim()),
|
new Error(`${qinglongErrLog || ''}\n${res}`.trim()),
|
||||||
);
|
);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|||||||
+45
-16
@@ -9,6 +9,7 @@ import {
|
|||||||
getFileContentByName,
|
getFileContentByName,
|
||||||
fileExist,
|
fileExist,
|
||||||
killTask,
|
killTask,
|
||||||
|
killAllTasks,
|
||||||
getUniqPath,
|
getUniqPath,
|
||||||
safeJSONParse,
|
safeJSONParse,
|
||||||
isDemoEnv,
|
isDemoEnv,
|
||||||
@@ -24,10 +25,11 @@ import pickBy from 'lodash/pickBy';
|
|||||||
import omit from 'lodash/omit';
|
import omit from 'lodash/omit';
|
||||||
import { writeFileWithLock } from '../shared/utils';
|
import { writeFileWithLock } from '../shared/utils';
|
||||||
import { ScheduleType } from '../interface/schedule';
|
import { ScheduleType } from '../interface/schedule';
|
||||||
|
import { logStreamManager } from '../shared/logStreamManager';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class CronService {
|
export default class CronService {
|
||||||
constructor(@Inject('logger') private logger: winston.Logger) { }
|
constructor(@Inject('logger') private logger: winston.Logger) {}
|
||||||
|
|
||||||
private isNodeCron(cron: Crontab) {
|
private isNodeCron(cron: Crontab) {
|
||||||
const { schedule, extra_schedules } = cron;
|
const { schedule, extra_schedules } = cron;
|
||||||
@@ -56,7 +58,9 @@ export default class CronService {
|
|||||||
}
|
}
|
||||||
let uniqPath = await getUniqPath(command, `${id}`);
|
let uniqPath = await getUniqPath(command, `${id}`);
|
||||||
if (log_name) {
|
if (log_name) {
|
||||||
const normalizedLogName = log_name.startsWith('/') ? log_name : path.join(config.logPath, log_name);
|
const normalizedLogName = log_name.startsWith('/')
|
||||||
|
? log_name
|
||||||
|
: path.join(config.logPath, log_name);
|
||||||
if (normalizedLogName.startsWith(config.logPath)) {
|
if (normalizedLogName.startsWith(config.logPath)) {
|
||||||
uniqPath = log_name;
|
uniqPath = log_name;
|
||||||
}
|
}
|
||||||
@@ -161,7 +165,7 @@ export default class CronService {
|
|||||||
let cron;
|
let cron;
|
||||||
try {
|
try {
|
||||||
cron = await this.getDb({ id });
|
cron = await this.getDb({ id });
|
||||||
} catch (err) { }
|
} catch (err) {}
|
||||||
if (!cron) {
|
if (!cron) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -461,12 +465,17 @@ export default class CronService {
|
|||||||
public async stop(ids: number[]) {
|
public async stop(ids: number[]) {
|
||||||
const docs = await CrontabModel.findAll({ where: { id: ids } });
|
const docs = await CrontabModel.findAll({ where: { id: ids } });
|
||||||
for (const doc of docs) {
|
for (const doc of docs) {
|
||||||
if (doc.pid) {
|
// Kill all running instances of this task
|
||||||
try {
|
try {
|
||||||
await killTask(doc.pid);
|
const command = this.makeCommand(doc);
|
||||||
} catch (error) {
|
await killAllTasks(command);
|
||||||
this.logger.error(error);
|
this.logger.info(
|
||||||
}
|
`[panel][停止所有运行中的任务实例] 任务ID: ${doc.id}, 命令: ${command}`,
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error(
|
||||||
|
`[panel][停止任务失败] 任务ID: ${doc.id}, 错误: ${error}`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -497,7 +506,10 @@ export default class CronService {
|
|||||||
|
|
||||||
let { id, command, log_name } = cron;
|
let { id, command, log_name } = cron;
|
||||||
|
|
||||||
const uniqPath = log_name === '/dev/null' ? (await getUniqPath(command, `${id}`)) : log_name;
|
const uniqPath =
|
||||||
|
log_name === '/dev/null' || !log_name
|
||||||
|
? await getUniqPath(command, `${id}`)
|
||||||
|
: log_name;
|
||||||
const logTime = dayjs().format('YYYY-MM-DD-HH-mm-ss-SSS');
|
const logTime = dayjs().format('YYYY-MM-DD-HH-mm-ss-SSS');
|
||||||
const logDirPath = path.resolve(config.logPath, `${uniqPath}`);
|
const logDirPath = path.resolve(config.logPath, `${uniqPath}`);
|
||||||
await fs.mkdir(logDirPath, { recursive: true });
|
await fs.mkdir(logDirPath, { recursive: true });
|
||||||
@@ -516,7 +528,7 @@ export default class CronService {
|
|||||||
{ where: { id } },
|
{ where: { id } },
|
||||||
);
|
);
|
||||||
cp.stdout.on('data', async (data) => {
|
cp.stdout.on('data', async (data) => {
|
||||||
await fs.appendFile(absolutePath, data.toString());
|
await logStreamManager.write(absolutePath, data.toString());
|
||||||
});
|
});
|
||||||
cp.stderr.on('data', async (data) => {
|
cp.stderr.on('data', async (data) => {
|
||||||
this.logger.info(
|
this.logger.info(
|
||||||
@@ -524,7 +536,7 @@ export default class CronService {
|
|||||||
command,
|
command,
|
||||||
data.toString(),
|
data.toString(),
|
||||||
);
|
);
|
||||||
await fs.appendFile(absolutePath, data.toString());
|
await logStreamManager.write(absolutePath, data.toString());
|
||||||
});
|
});
|
||||||
cp.on('error', async (err) => {
|
cp.on('error', async (err) => {
|
||||||
this.logger.error(
|
this.logger.error(
|
||||||
@@ -532,7 +544,7 @@ export default class CronService {
|
|||||||
command,
|
command,
|
||||||
err,
|
err,
|
||||||
);
|
);
|
||||||
await fs.appendFile(absolutePath, JSON.stringify(err));
|
await logStreamManager.write(absolutePath, JSON.stringify(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
cp.on('exit', async (code) => {
|
cp.on('exit', async (code) => {
|
||||||
@@ -541,6 +553,8 @@ export default class CronService {
|
|||||||
JSON.stringify(params),
|
JSON.stringify(params),
|
||||||
code,
|
code,
|
||||||
);
|
);
|
||||||
|
// Close the stream after task completion
|
||||||
|
await logStreamManager.closeStream(absolutePath);
|
||||||
await CrontabModel.update(
|
await CrontabModel.update(
|
||||||
{ status: CrontabStatus.idle, pid: undefined },
|
{ status: CrontabStatus.idle, pid: undefined },
|
||||||
{ where: { id } },
|
{ where: { id } },
|
||||||
@@ -627,7 +641,11 @@ export default class CronService {
|
|||||||
if (!command.startsWith(TASK_PREFIX) && !command.startsWith(QL_PREFIX)) {
|
if (!command.startsWith(TASK_PREFIX) && !command.startsWith(QL_PREFIX)) {
|
||||||
command = `${TASK_PREFIX}${tab.command}`;
|
command = `${TASK_PREFIX}${tab.command}`;
|
||||||
}
|
}
|
||||||
let commandVariable = `real_time=${Boolean(realTime)} log_name=${tab.log_name} no_tee=true ID=${tab.id} `;
|
let commandVariable = `real_time=${Boolean(realTime)} no_tee=true ID=${tab.id} `;
|
||||||
|
// Only include log_name if it has a truthy value to avoid passing null/undefined to shell
|
||||||
|
if (tab.log_name) {
|
||||||
|
commandVariable += `log_name=${tab.log_name} `;
|
||||||
|
}
|
||||||
if (tab.task_before) {
|
if (tab.task_before) {
|
||||||
commandVariable += `task_before='${tab.task_before
|
commandVariable += `task_before='${tab.task_before
|
||||||
.replace(/'/g, "'\\''")
|
.replace(/'/g, "'\\''")
|
||||||
@@ -669,12 +687,23 @@ export default class CronService {
|
|||||||
|
|
||||||
await writeFileWithLock(config.crontabFile, crontab_string);
|
await writeFileWithLock(config.crontabFile, crontab_string);
|
||||||
|
|
||||||
execSync(`crontab ${config.crontabFile}`);
|
try {
|
||||||
|
execSync(`crontab ${config.crontabFile}`);
|
||||||
|
} catch (error: any) {
|
||||||
|
const errorMsg = error.message || String(error);
|
||||||
|
this.logger.error('[crontab] Failed to update system crontab:', errorMsg);
|
||||||
|
}
|
||||||
|
|
||||||
await CrontabModel.update({ saved: true }, { where: {} });
|
await CrontabModel.update({ saved: true }, { where: {} });
|
||||||
}
|
}
|
||||||
|
|
||||||
public importCrontab() {
|
public importCrontab() {
|
||||||
exec('crontab -l', (error, stdout, stderr) => {
|
exec('crontab -l', (error, stdout) => {
|
||||||
|
if (error) {
|
||||||
|
const errorMsg = error.message || String(error);
|
||||||
|
this.logger.error('[crontab] Failed to read system crontab:', errorMsg);
|
||||||
|
}
|
||||||
|
|
||||||
const lines = stdout.split('\n');
|
const lines = stdout.split('\n');
|
||||||
const namePrefix = new Date().getTime();
|
const namePrefix = new Date().getTime();
|
||||||
|
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ export default class DependenceService {
|
|||||||
query: any = {},
|
query: any = {},
|
||||||
): Promise<Dependence[]> {
|
): Promise<Dependence[]> {
|
||||||
let condition = query;
|
let condition = query;
|
||||||
if (DependenceTypes[type]) {
|
if (type && DependenceTypes[type] !== undefined) {
|
||||||
condition.type = DependenceTypes[type];
|
condition.type = DependenceTypes[type];
|
||||||
}
|
}
|
||||||
if (status) {
|
if (status) {
|
||||||
|
|||||||
@@ -1,348 +0,0 @@
|
|||||||
// Graph Execution Engine for Visual Workflow
|
|
||||||
import winston from 'winston';
|
|
||||||
|
|
||||||
interface WorkflowNode {
|
|
||||||
id: string;
|
|
||||||
type: string;
|
|
||||||
position: { x: number; y: number };
|
|
||||||
data: any;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface WorkflowEdge {
|
|
||||||
id: string;
|
|
||||||
source: string;
|
|
||||||
target: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface WorkflowGraph {
|
|
||||||
nodes: WorkflowNode[];
|
|
||||||
edges: WorkflowEdge[];
|
|
||||||
}
|
|
||||||
|
|
||||||
interface ExecutionContext {
|
|
||||||
triggerData: any;
|
|
||||||
variables: Map<string, any>;
|
|
||||||
executedNodes: Set<string>;
|
|
||||||
results: Map<string, any>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class GraphExecutor {
|
|
||||||
private logger: winston.Logger;
|
|
||||||
|
|
||||||
constructor(logger: winston.Logger) {
|
|
||||||
this.logger = logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute a workflow graph
|
|
||||||
*/
|
|
||||||
public async executeGraph(
|
|
||||||
workflowGraph: WorkflowGraph,
|
|
||||||
triggerData: any,
|
|
||||||
executor: any, // ScenarioService instance
|
|
||||||
): Promise<{ success: boolean; results: any; executedNodes: string[] }> {
|
|
||||||
const context: ExecutionContext = {
|
|
||||||
triggerData,
|
|
||||||
variables: new Map(),
|
|
||||||
executedNodes: new Set(),
|
|
||||||
results: new Map(),
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Find trigger nodes (entry points)
|
|
||||||
const triggerNodes = workflowGraph.nodes.filter(
|
|
||||||
(node) => node.type === 'trigger',
|
|
||||||
);
|
|
||||||
|
|
||||||
if (triggerNodes.length === 0) {
|
|
||||||
throw new Error('No trigger node found in workflow');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Execute from each trigger node
|
|
||||||
for (const triggerNode of triggerNodes) {
|
|
||||||
await this.executeNode(
|
|
||||||
triggerNode,
|
|
||||||
workflowGraph,
|
|
||||||
context,
|
|
||||||
executor,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
success: true,
|
|
||||||
results: Object.fromEntries(context.results),
|
|
||||||
executedNodes: Array.from(context.executedNodes),
|
|
||||||
};
|
|
||||||
} catch (error: any) {
|
|
||||||
this.logger.error('Graph execution failed:', error);
|
|
||||||
return {
|
|
||||||
success: false,
|
|
||||||
results: { error: error.message },
|
|
||||||
executedNodes: Array.from(context.executedNodes),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute a single node and its connected nodes
|
|
||||||
*/
|
|
||||||
private async executeNode(
|
|
||||||
node: WorkflowNode,
|
|
||||||
graph: WorkflowGraph,
|
|
||||||
context: ExecutionContext,
|
|
||||||
executor: any,
|
|
||||||
): Promise<any> {
|
|
||||||
// Skip if already executed
|
|
||||||
if (context.executedNodes.has(node.id)) {
|
|
||||||
return context.results.get(node.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.logger.info(`Executing node: ${node.id} (${node.type})`);
|
|
||||||
context.executedNodes.add(node.id);
|
|
||||||
|
|
||||||
let result: any = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Execute based on node type
|
|
||||||
switch (node.type) {
|
|
||||||
case 'trigger':
|
|
||||||
result = await this.executeTriggerNode(node, context, executor);
|
|
||||||
break;
|
|
||||||
case 'condition':
|
|
||||||
result = await this.executeConditionNode(node, context, executor);
|
|
||||||
break;
|
|
||||||
case 'action':
|
|
||||||
result = await this.executeActionNode(node, context, executor);
|
|
||||||
break;
|
|
||||||
case 'control':
|
|
||||||
result = await this.executeControlNode(node, context, executor);
|
|
||||||
break;
|
|
||||||
case 'logic_gate':
|
|
||||||
result = await this.executeLogicGateNode(node, context, executor);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
this.logger.warn(`Unknown node type: ${node.type}`);
|
|
||||||
result = { skipped: true };
|
|
||||||
}
|
|
||||||
|
|
||||||
context.results.set(node.id, result);
|
|
||||||
|
|
||||||
// Find and execute next nodes
|
|
||||||
const nextEdges = graph.edges.filter((edge) => edge.source === node.id);
|
|
||||||
|
|
||||||
for (const edge of nextEdges) {
|
|
||||||
const nextNode = graph.nodes.find((n) => n.id === edge.target);
|
|
||||||
if (nextNode) {
|
|
||||||
await this.executeNode(nextNode, graph, context, executor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
} catch (error: any) {
|
|
||||||
this.logger.error(`Node execution failed: ${node.id}`, error);
|
|
||||||
context.results.set(node.id, { error: error.message });
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async executeTriggerNode(
|
|
||||||
node: WorkflowNode,
|
|
||||||
context: ExecutionContext,
|
|
||||||
executor: any,
|
|
||||||
): Promise<any> {
|
|
||||||
// Trigger nodes just pass through the trigger data
|
|
||||||
return { triggered: true, data: context.triggerData };
|
|
||||||
}
|
|
||||||
|
|
||||||
private async executeConditionNode(
|
|
||||||
node: WorkflowNode,
|
|
||||||
context: ExecutionContext,
|
|
||||||
executor: any,
|
|
||||||
): Promise<any> {
|
|
||||||
const { field, operator, value } = node.data;
|
|
||||||
|
|
||||||
// Get field value from trigger data or variables
|
|
||||||
let fieldValue = this.getFieldValue(field, context);
|
|
||||||
|
|
||||||
// Evaluate condition
|
|
||||||
const matched = this.evaluateCondition(fieldValue, operator, value);
|
|
||||||
|
|
||||||
this.logger.info(
|
|
||||||
`Condition ${node.id}: ${field} ${operator} ${value} = ${matched}`,
|
|
||||||
);
|
|
||||||
|
|
||||||
return { matched, fieldValue, expectedValue: value };
|
|
||||||
}
|
|
||||||
|
|
||||||
private async executeActionNode(
|
|
||||||
node: WorkflowNode,
|
|
||||||
context: ExecutionContext,
|
|
||||||
executor: any,
|
|
||||||
): Promise<any> {
|
|
||||||
const { actionType } = node.data;
|
|
||||||
|
|
||||||
switch (actionType) {
|
|
||||||
case 'run_task':
|
|
||||||
return await executor.executeRunTask(node.data);
|
|
||||||
case 'set_variable':
|
|
||||||
return await executor.executeSetVariable(node.data);
|
|
||||||
case 'execute_command':
|
|
||||||
return await executor.executeCommand(node.data);
|
|
||||||
case 'send_notification':
|
|
||||||
return await executor.executeSendNotification(node.data);
|
|
||||||
default:
|
|
||||||
throw new Error(`Unknown action type: ${actionType}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async executeControlNode(
|
|
||||||
node: WorkflowNode,
|
|
||||||
context: ExecutionContext,
|
|
||||||
executor: any,
|
|
||||||
): Promise<any> {
|
|
||||||
const { controlType } = node.data;
|
|
||||||
|
|
||||||
switch (controlType) {
|
|
||||||
case 'delay':
|
|
||||||
const delayMs = (node.data.delaySeconds || 0) * 1000;
|
|
||||||
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
||||||
return { delayed: delayMs };
|
|
||||||
case 'retry':
|
|
||||||
// Retry logic handled by caller
|
|
||||||
return { retryConfig: node.data };
|
|
||||||
case 'circuit_breaker':
|
|
||||||
// Circuit breaker logic handled by caller
|
|
||||||
return { circuitBreakerConfig: node.data };
|
|
||||||
default:
|
|
||||||
throw new Error(`Unknown control type: ${controlType}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async executeLogicGateNode(
|
|
||||||
node: WorkflowNode,
|
|
||||||
context: ExecutionContext,
|
|
||||||
executor: any,
|
|
||||||
): Promise<any> {
|
|
||||||
const { gateType } = node.data;
|
|
||||||
// Logic gates are evaluated by checking incoming edges
|
|
||||||
return { gateType, passed: true };
|
|
||||||
}
|
|
||||||
|
|
||||||
private getFieldValue(field: string, context: ExecutionContext): any {
|
|
||||||
// Support dot notation for nested fields
|
|
||||||
const parts = field.split('.');
|
|
||||||
let value: any = context.triggerData;
|
|
||||||
|
|
||||||
for (const part of parts) {
|
|
||||||
if (value && typeof value === 'object' && part in value) {
|
|
||||||
value = value[part];
|
|
||||||
} else {
|
|
||||||
// Check variables
|
|
||||||
if (context.variables.has(field)) {
|
|
||||||
return context.variables.get(field);
|
|
||||||
}
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
private evaluateCondition(
|
|
||||||
fieldValue: any,
|
|
||||||
operator: string,
|
|
||||||
expectedValue: any,
|
|
||||||
): boolean {
|
|
||||||
switch (operator) {
|
|
||||||
case 'equals':
|
|
||||||
return fieldValue == expectedValue;
|
|
||||||
case 'not_equals':
|
|
||||||
return fieldValue != expectedValue;
|
|
||||||
case 'greater_than':
|
|
||||||
return Number(fieldValue) > Number(expectedValue);
|
|
||||||
case 'less_than':
|
|
||||||
return Number(fieldValue) < Number(expectedValue);
|
|
||||||
case 'contains':
|
|
||||||
return String(fieldValue).includes(String(expectedValue));
|
|
||||||
case 'not_contains':
|
|
||||||
return !String(fieldValue).includes(String(expectedValue));
|
|
||||||
default:
|
|
||||||
this.logger.warn(`Unknown operator: ${operator}`);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validate a workflow graph
|
|
||||||
*/
|
|
||||||
public validateGraph(workflowGraph: WorkflowGraph): {
|
|
||||||
valid: boolean;
|
|
||||||
errors: string[];
|
|
||||||
} {
|
|
||||||
const errors: string[] = [];
|
|
||||||
|
|
||||||
// Check for at least one trigger node
|
|
||||||
const triggerNodes = workflowGraph.nodes.filter(
|
|
||||||
(node) => node.type === 'trigger',
|
|
||||||
);
|
|
||||||
if (triggerNodes.length === 0) {
|
|
||||||
errors.push('Workflow must have at least one trigger node');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for cycles (simple check)
|
|
||||||
const visited = new Set<string>();
|
|
||||||
const recursionStack = new Set<string>();
|
|
||||||
|
|
||||||
const hasCycle = (nodeId: string): boolean => {
|
|
||||||
visited.add(nodeId);
|
|
||||||
recursionStack.add(nodeId);
|
|
||||||
|
|
||||||
const outgoingEdges = workflowGraph.edges.filter(
|
|
||||||
(edge) => edge.source === nodeId,
|
|
||||||
);
|
|
||||||
|
|
||||||
for (const edge of outgoingEdges) {
|
|
||||||
if (!visited.has(edge.target)) {
|
|
||||||
if (hasCycle(edge.target)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} else if (recursionStack.has(edge.target)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
recursionStack.delete(nodeId);
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
for (const node of workflowGraph.nodes) {
|
|
||||||
if (!visited.has(node.id) && hasCycle(node.id)) {
|
|
||||||
errors.push('Workflow contains cycles');
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for disconnected nodes (excluding triggers)
|
|
||||||
const connectedNodes = new Set<string>();
|
|
||||||
workflowGraph.edges.forEach((edge) => {
|
|
||||||
connectedNodes.add(edge.source);
|
|
||||||
connectedNodes.add(edge.target);
|
|
||||||
});
|
|
||||||
|
|
||||||
const disconnectedNodes = workflowGraph.nodes.filter(
|
|
||||||
(node) =>
|
|
||||||
node.type !== 'trigger' && !connectedNodes.has(node.id),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (disconnectedNodes.length > 0) {
|
|
||||||
errors.push(
|
|
||||||
`Disconnected nodes found: ${disconnectedNodes.map((n) => n.id).join(', ')}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
valid: errors.length === 0,
|
|
||||||
errors,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+19
-5
@@ -550,19 +550,33 @@ export default class NotificationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async lark() {
|
private async lark() {
|
||||||
let { larkKey } = this.params;
|
let { larkKey, larkSecret } = this.params;
|
||||||
|
|
||||||
if (!larkKey.startsWith('http')) {
|
if (!larkKey.startsWith('http')) {
|
||||||
larkKey = `https://open.feishu.cn/open-apis/bot/v2/hook/${larkKey}`;
|
larkKey = `https://open.feishu.cn/open-apis/bot/v2/hook/${larkKey}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const body: Record<string, any> = {
|
||||||
|
msg_type: 'text',
|
||||||
|
content: { text: `${this.title}\n\n${this.content}` },
|
||||||
|
};
|
||||||
|
|
||||||
|
// Add signature if secret is provided
|
||||||
|
// Note: Feishu's signature algorithm uses timestamp+"\n"+secret as the HMAC key
|
||||||
|
// and signs an empty message, which differs from typical HMAC usage
|
||||||
|
if (larkSecret) {
|
||||||
|
const timestamp = Math.floor(Date.now() / 1000).toString();
|
||||||
|
const stringToSign = `${timestamp}\n${larkSecret}`;
|
||||||
|
const hmac = crypto.createHmac('sha256', stringToSign);
|
||||||
|
const sign = hmac.digest('base64');
|
||||||
|
body.timestamp = timestamp;
|
||||||
|
body.sign = sign;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await httpClient.post(larkKey, {
|
const res = await httpClient.post(larkKey, {
|
||||||
...this.gotOption,
|
...this.gotOption,
|
||||||
json: {
|
json: body,
|
||||||
msg_type: 'text',
|
|
||||||
content: { text: `${this.title}\n\n${this.content}` },
|
|
||||||
},
|
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
});
|
});
|
||||||
if (res.StatusCode === 0 || res.code === 0) {
|
if (res.StatusCode === 0 || res.code === 0) {
|
||||||
|
|||||||
@@ -1,557 +0,0 @@
|
|||||||
import { Service, Inject } from 'typedi';
|
|
||||||
import winston from 'winston';
|
|
||||||
import { Scenario, ScenarioModel } from '../data/scenario';
|
|
||||||
import { ScenarioLog, ScenarioLogModel } from '../data/scenarioLog';
|
|
||||||
import { Op } from 'sequelize';
|
|
||||||
import CronService from './cron';
|
|
||||||
import EnvService from './env';
|
|
||||||
import dayjs from 'dayjs';
|
|
||||||
import { exec } from 'child_process';
|
|
||||||
import { promisify } from 'util';
|
|
||||||
import config from '../config';
|
|
||||||
import fs from 'fs/promises';
|
|
||||||
import path from 'path';
|
|
||||||
import chokidar from 'chokidar';
|
|
||||||
import { GraphExecutor } from './graphExecutor';
|
|
||||||
|
|
||||||
const execAsync = promisify(exec);
|
|
||||||
|
|
||||||
@Service()
|
|
||||||
export default class ScenarioService {
|
|
||||||
private watchers: Map<number, any> = new Map();
|
|
||||||
private webhookTokens: Map<number, string> = new Map();
|
|
||||||
private graphExecutor: GraphExecutor;
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
@Inject('logger') private logger: winston.Logger,
|
|
||||||
private cronService: CronService,
|
|
||||||
private envService: EnvService,
|
|
||||||
) {
|
|
||||||
this.graphExecutor = new GraphExecutor(logger);
|
|
||||||
this.initializeWatchers();
|
|
||||||
}
|
|
||||||
|
|
||||||
private async initializeWatchers() {
|
|
||||||
try {
|
|
||||||
const scenarios = await this.list({ isEnabled: 1 });
|
|
||||||
for (const scenario of scenarios) {
|
|
||||||
if (scenario.triggerType === 'variable') {
|
|
||||||
await this.setupVariableWatcher(scenario);
|
|
||||||
} else if (scenario.triggerType === 'system_event') {
|
|
||||||
await this.setupSystemEventWatcher(scenario);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
this.logger.error('Failed to initialize scenario watchers:', error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public async create(payload: Scenario): Promise<Scenario> {
|
|
||||||
const scenario = await ScenarioModel.create(payload, { returning: true });
|
|
||||||
|
|
||||||
if (scenario.isEnabled === 1) {
|
|
||||||
await this.enableScenarioTrigger(scenario);
|
|
||||||
}
|
|
||||||
|
|
||||||
return scenario;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async update(payload: Partial<Scenario>): Promise<Scenario> {
|
|
||||||
const oldScenario = await this.getDb({ id: payload.id });
|
|
||||||
await ScenarioModel.update(payload, { where: { id: payload.id } });
|
|
||||||
const newScenario = await this.getDb({ id: payload.id });
|
|
||||||
|
|
||||||
// Handle trigger changes
|
|
||||||
if (oldScenario.isEnabled === 1) {
|
|
||||||
await this.disableScenarioTrigger(oldScenario);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newScenario.isEnabled === 1) {
|
|
||||||
await this.enableScenarioTrigger(newScenario);
|
|
||||||
}
|
|
||||||
|
|
||||||
return newScenario;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async remove(ids: number[]): Promise<number> {
|
|
||||||
for (const id of ids) {
|
|
||||||
const scenario = await this.getDb({ id });
|
|
||||||
if (scenario) {
|
|
||||||
await this.disableScenarioTrigger(scenario);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return await ScenarioModel.destroy({ where: { id: ids } });
|
|
||||||
}
|
|
||||||
|
|
||||||
public async list(
|
|
||||||
searchText?: string | { isEnabled: number },
|
|
||||||
): Promise<Scenario[]> {
|
|
||||||
let where: any = {};
|
|
||||||
|
|
||||||
if (typeof searchText === 'string') {
|
|
||||||
where = {
|
|
||||||
[Op.or]: [
|
|
||||||
{ name: { [Op.like]: `%${searchText}%` } },
|
|
||||||
{ description: { [Op.like]: `%${searchText}%` } },
|
|
||||||
],
|
|
||||||
};
|
|
||||||
} else if (typeof searchText === 'object') {
|
|
||||||
where = searchText;
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await ScenarioModel.findAll({
|
|
||||||
where,
|
|
||||||
order: [['createdAt', 'DESC']],
|
|
||||||
});
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async getDb(query: any): Promise<Scenario> {
|
|
||||||
const doc: any = await ScenarioModel.findOne({ where: { ...query } });
|
|
||||||
return doc && (doc.get({ plain: true }) as Scenario);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async enableScenarioTrigger(scenario: Scenario) {
|
|
||||||
switch (scenario.triggerType) {
|
|
||||||
case 'variable':
|
|
||||||
await this.setupVariableWatcher(scenario);
|
|
||||||
break;
|
|
||||||
case 'webhook':
|
|
||||||
this.setupWebhookTrigger(scenario);
|
|
||||||
break;
|
|
||||||
case 'time':
|
|
||||||
await this.setupTimeTrigger(scenario);
|
|
||||||
break;
|
|
||||||
case 'system_event':
|
|
||||||
await this.setupSystemEventWatcher(scenario);
|
|
||||||
break;
|
|
||||||
case 'task_status':
|
|
||||||
// Task status triggers are handled in the cron execution flow
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async disableScenarioTrigger(scenario: Scenario) {
|
|
||||||
if (scenario.triggerType === 'variable' || scenario.triggerType === 'system_event') {
|
|
||||||
const watcher = this.watchers.get(scenario.id!);
|
|
||||||
if (watcher) {
|
|
||||||
await watcher.close();
|
|
||||||
this.watchers.delete(scenario.id!);
|
|
||||||
}
|
|
||||||
} else if (scenario.triggerType === 'webhook') {
|
|
||||||
this.webhookTokens.delete(scenario.id!);
|
|
||||||
} else if (scenario.triggerType === 'time') {
|
|
||||||
// Remove time trigger (would need to cancel scheduled task)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async setupVariableWatcher(scenario: Scenario) {
|
|
||||||
if (!scenario.triggerConfig || !scenario.triggerConfig.watchPath) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const watchPath = scenario.triggerConfig.watchPath;
|
|
||||||
const watcher = chokidar.watch(watchPath, {
|
|
||||||
persistent: true,
|
|
||||||
ignoreInitial: true,
|
|
||||||
}) as any;
|
|
||||||
|
|
||||||
watcher.on('change', async (filePath: string) => {
|
|
||||||
this.logger.info(
|
|
||||||
`Variable change detected for scenario ${scenario.name}: ${filePath}`,
|
|
||||||
);
|
|
||||||
await this.triggerScenario(scenario.id!, { filePath, type: 'change' });
|
|
||||||
});
|
|
||||||
|
|
||||||
this.watchers.set(scenario.id!, watcher);
|
|
||||||
}
|
|
||||||
|
|
||||||
private setupWebhookTrigger(scenario: Scenario) {
|
|
||||||
// Generate a unique token for this webhook
|
|
||||||
const token = scenario.triggerConfig?.token || this.generateWebhookToken();
|
|
||||||
this.webhookTokens.set(scenario.id!, token);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async setupTimeTrigger(scenario: Scenario) {
|
|
||||||
// This would integrate with the existing cron system
|
|
||||||
// For now, we'll create a cron job that triggers the scenario
|
|
||||||
if (scenario.triggerConfig && scenario.triggerConfig.schedule) {
|
|
||||||
// Would create a cron entry that calls triggerScenario
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async setupSystemEventWatcher(scenario: Scenario) {
|
|
||||||
const eventType = scenario.triggerConfig?.eventType;
|
|
||||||
|
|
||||||
if (eventType === 'disk_space' || eventType === 'memory') {
|
|
||||||
// Set up periodic checks
|
|
||||||
const interval = scenario.triggerConfig?.checkInterval || 60000; // Default 1 minute
|
|
||||||
|
|
||||||
const checkSystem = async () => {
|
|
||||||
const metrics = await this.getSystemMetrics();
|
|
||||||
const threshold = scenario.triggerConfig?.threshold;
|
|
||||||
|
|
||||||
let shouldTrigger = false;
|
|
||||||
if (eventType === 'disk_space' && metrics.diskUsagePercent > threshold) {
|
|
||||||
shouldTrigger = true;
|
|
||||||
} else if (eventType === 'memory' && metrics.memoryUsagePercent > threshold) {
|
|
||||||
shouldTrigger = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (shouldTrigger) {
|
|
||||||
await this.triggerScenario(scenario.id!, metrics);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const timer = setInterval(checkSystem, interval);
|
|
||||||
this.watchers.set(scenario.id!, { close: () => clearInterval(timer) });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async getSystemMetrics() {
|
|
||||||
try {
|
|
||||||
// Get disk usage
|
|
||||||
const { stdout: diskOutput } = await execAsync("df -h / | tail -1 | awk '{print $5}' | sed 's/%//'");
|
|
||||||
const diskUsagePercent = parseInt(diskOutput.trim());
|
|
||||||
|
|
||||||
// Get memory usage
|
|
||||||
const { stdout: memOutput } = await execAsync("free | grep Mem | awk '{print ($3/$2) * 100.0}'");
|
|
||||||
const memoryUsagePercent = parseFloat(memOutput.trim());
|
|
||||||
|
|
||||||
return { diskUsagePercent, memoryUsagePercent };
|
|
||||||
} catch (error) {
|
|
||||||
this.logger.error('Failed to get system metrics:', error);
|
|
||||||
return { diskUsagePercent: 0, memoryUsagePercent: 0 };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private generateWebhookToken(): string {
|
|
||||||
return Math.random().toString(36).substring(2, 15) +
|
|
||||||
Math.random().toString(36).substring(2, 15);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async triggerScenario(
|
|
||||||
scenarioId: number,
|
|
||||||
triggerData: any,
|
|
||||||
): Promise<void> {
|
|
||||||
const scenario = await this.getDb({ id: scenarioId });
|
|
||||||
|
|
||||||
if (!scenario || scenario.isEnabled !== 1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update last triggered time
|
|
||||||
await ScenarioModel.update(
|
|
||||||
{ lastTriggeredAt: new Date() },
|
|
||||||
{ where: { id: scenarioId } },
|
|
||||||
);
|
|
||||||
|
|
||||||
// Check if circuit breaker is triggered
|
|
||||||
if (
|
|
||||||
scenario.consecutiveFailures &&
|
|
||||||
scenario.failureThreshold &&
|
|
||||||
scenario.consecutiveFailures >= scenario.failureThreshold
|
|
||||||
) {
|
|
||||||
this.logger.warn(
|
|
||||||
`Scenario ${scenario.name} is disabled due to consecutive failures`,
|
|
||||||
);
|
|
||||||
await ScenarioModel.update(
|
|
||||||
{ isEnabled: 0 },
|
|
||||||
{ where: { id: scenarioId } },
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply delay if configured
|
|
||||||
if (scenario.delayExecution && scenario.delayExecution > 0) {
|
|
||||||
setTimeout(
|
|
||||||
() => this.executeScenario(scenario, triggerData),
|
|
||||||
scenario.delayExecution * 1000,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
await this.executeScenario(scenario, triggerData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async executeScenario(
|
|
||||||
scenario: Scenario,
|
|
||||||
triggerData: any,
|
|
||||||
retryCount: number = 0,
|
|
||||||
): Promise<void> {
|
|
||||||
const startTime = Date.now();
|
|
||||||
const log: Partial<ScenarioLog> = {
|
|
||||||
scenarioId: scenario.id!,
|
|
||||||
scenarioName: scenario.name,
|
|
||||||
triggerData,
|
|
||||||
retriesAttempted: retryCount,
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Check if this is a graph-based workflow
|
|
||||||
if (scenario.workflowGraph && scenario.workflowGraph.nodes && scenario.workflowGraph.nodes.length > 0) {
|
|
||||||
// Execute using graph executor
|
|
||||||
const result = await this.graphExecutor.executeGraph(
|
|
||||||
scenario.workflowGraph,
|
|
||||||
triggerData,
|
|
||||||
this,
|
|
||||||
);
|
|
||||||
|
|
||||||
log.conditionsMatched = true; // Graph execution handles conditions internally
|
|
||||||
log.executionStatus = result.success ? 'success' : 'failure';
|
|
||||||
log.executionDetails = result.results;
|
|
||||||
log.executionTime = Date.now() - startTime;
|
|
||||||
|
|
||||||
if (!result.success) {
|
|
||||||
throw new Error(JSON.stringify(result.results));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Legacy execution path for form-based scenarios
|
|
||||||
// Evaluate conditions
|
|
||||||
const conditionsMatched = await this.evaluateConditions(
|
|
||||||
scenario.conditions || [],
|
|
||||||
scenario.conditionLogic || 'AND',
|
|
||||||
triggerData,
|
|
||||||
);
|
|
||||||
|
|
||||||
log.conditionsMatched = conditionsMatched;
|
|
||||||
|
|
||||||
if (!conditionsMatched) {
|
|
||||||
log.executionStatus = 'success';
|
|
||||||
log.executionDetails = { message: 'Conditions not matched, skipped' };
|
|
||||||
await this.createLog(log);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Execute actions
|
|
||||||
const actionResults = await this.executeActions(scenario.actions || []);
|
|
||||||
|
|
||||||
log.executionStatus = 'success';
|
|
||||||
log.executionDetails = actionResults;
|
|
||||||
log.executionTime = Date.now() - startTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update scenario stats
|
|
||||||
await ScenarioModel.update(
|
|
||||||
{
|
|
||||||
lastExecutedAt: new Date(),
|
|
||||||
executionCount: (scenario.executionCount || 0) + 1,
|
|
||||||
successCount: (scenario.successCount || 0) + 1,
|
|
||||||
consecutiveFailures: 0,
|
|
||||||
},
|
|
||||||
{ where: { id: scenario.id } },
|
|
||||||
);
|
|
||||||
|
|
||||||
await this.createLog(log);
|
|
||||||
} catch (error: any) {
|
|
||||||
log.executionStatus = 'failure';
|
|
||||||
log.errorMessage = error.message;
|
|
||||||
log.executionTime = Date.now() - startTime;
|
|
||||||
|
|
||||||
this.logger.error(`Scenario ${scenario.name} execution failed:`, error);
|
|
||||||
|
|
||||||
// Handle retry logic
|
|
||||||
const shouldRetry = scenario.retryStrategy &&
|
|
||||||
retryCount < (scenario.retryStrategy.maxRetries || 0);
|
|
||||||
|
|
||||||
if (shouldRetry) {
|
|
||||||
const delay = this.calculateRetryDelay(scenario.retryStrategy!, retryCount);
|
|
||||||
setTimeout(
|
|
||||||
() => this.executeScenario(scenario, triggerData, retryCount + 1),
|
|
||||||
delay,
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update failure stats
|
|
||||||
await ScenarioModel.update(
|
|
||||||
{
|
|
||||||
lastExecutedAt: new Date(),
|
|
||||||
executionCount: (scenario.executionCount || 0) + 1,
|
|
||||||
failureCount: (scenario.failureCount || 0) + 1,
|
|
||||||
consecutiveFailures: (scenario.consecutiveFailures || 0) + 1,
|
|
||||||
},
|
|
||||||
{ where: { id: scenario.id } },
|
|
||||||
);
|
|
||||||
|
|
||||||
await this.createLog(log);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async evaluateConditions(
|
|
||||||
conditions: any[],
|
|
||||||
logic: 'AND' | 'OR',
|
|
||||||
triggerData: any,
|
|
||||||
): Promise<boolean> {
|
|
||||||
if (conditions.length === 0) {
|
|
||||||
return true; // No conditions means always execute
|
|
||||||
}
|
|
||||||
|
|
||||||
const results = await Promise.all(
|
|
||||||
conditions.map((condition) => this.evaluateCondition(condition, triggerData)),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (logic === 'AND') {
|
|
||||||
return results.every((r) => r);
|
|
||||||
} else {
|
|
||||||
return results.some((r) => r);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async evaluateCondition(
|
|
||||||
condition: any,
|
|
||||||
triggerData: any,
|
|
||||||
): Promise<boolean> {
|
|
||||||
// Simple condition evaluation
|
|
||||||
// condition format: { field: string, operator: string, value: any }
|
|
||||||
const { field, operator, value } = condition;
|
|
||||||
const actualValue = this.getFieldValue(triggerData, field);
|
|
||||||
|
|
||||||
switch (operator) {
|
|
||||||
case 'equals':
|
|
||||||
return actualValue === value;
|
|
||||||
case 'not_equals':
|
|
||||||
return actualValue !== value;
|
|
||||||
case 'greater_than':
|
|
||||||
return actualValue > value;
|
|
||||||
case 'less_than':
|
|
||||||
return actualValue < value;
|
|
||||||
case 'contains':
|
|
||||||
return String(actualValue).includes(String(value));
|
|
||||||
case 'not_contains':
|
|
||||||
return !String(actualValue).includes(String(value));
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private getFieldValue(data: any, field: string): any {
|
|
||||||
const parts = field.split('.');
|
|
||||||
let value = data;
|
|
||||||
for (const part of parts) {
|
|
||||||
if (value && typeof value === 'object') {
|
|
||||||
value = value[part];
|
|
||||||
} else {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async executeActions(actions: any[]): Promise<any[]> {
|
|
||||||
const results = [];
|
|
||||||
|
|
||||||
for (const action of actions) {
|
|
||||||
try {
|
|
||||||
const result = await this.executeAction(action);
|
|
||||||
results.push({ action: action.type, success: true, result });
|
|
||||||
} catch (error: any) {
|
|
||||||
results.push({ action: action.type, success: false, error: error.message });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async executeAction(action: any): Promise<any> {
|
|
||||||
switch (action.type) {
|
|
||||||
case 'run_task':
|
|
||||||
// Execute a cron task
|
|
||||||
if (action.cronId) {
|
|
||||||
return await this.cronService.run([action.cronId]);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'set_variable':
|
|
||||||
// Set an environment variable
|
|
||||||
if (action.name && action.value !== undefined) {
|
|
||||||
return await this.envService.create([{
|
|
||||||
name: action.name,
|
|
||||||
value: action.value,
|
|
||||||
remarks: `Set by scenario: ${action.scenarioName || 'unknown'}`,
|
|
||||||
}]);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'send_notification':
|
|
||||||
// Would integrate with notification service
|
|
||||||
this.logger.info(`Notification: ${action.message}`);
|
|
||||||
break;
|
|
||||||
case 'execute_command':
|
|
||||||
// Execute a shell command
|
|
||||||
if (action.command) {
|
|
||||||
const { stdout, stderr } = await execAsync(action.command);
|
|
||||||
return { stdout, stderr };
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new Error(`Unknown action type: ${action.type}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private calculateRetryDelay(
|
|
||||||
retryStrategy: any,
|
|
||||||
retryCount: number,
|
|
||||||
): number {
|
|
||||||
const baseDelay = retryStrategy.retryDelay || 5;
|
|
||||||
const multiplier = retryStrategy.backoffMultiplier || 1;
|
|
||||||
return baseDelay * 1000 * Math.pow(multiplier, retryCount);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async createLog(log: Partial<ScenarioLog>): Promise<void> {
|
|
||||||
await ScenarioLogModel.create(log as any);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async getLogs(scenarioId?: number, limit: number = 100): Promise<ScenarioLog[]> {
|
|
||||||
const where = scenarioId ? { scenarioId } : {};
|
|
||||||
const logs = await ScenarioLogModel.findAll({
|
|
||||||
where,
|
|
||||||
order: [['createdAt', 'DESC']],
|
|
||||||
limit,
|
|
||||||
});
|
|
||||||
return logs;
|
|
||||||
}
|
|
||||||
|
|
||||||
public getWebhookToken(scenarioId: number): string | undefined {
|
|
||||||
return this.webhookTokens.get(scenarioId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async findByWebhookToken(token: string): Promise<Scenario | null> {
|
|
||||||
for (const [scenarioId, webhookToken] of this.webhookTokens.entries()) {
|
|
||||||
if (webhookToken === token) {
|
|
||||||
return await this.getDb({ id: scenarioId });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Public methods for graph executor
|
|
||||||
public async executeRunTask(data: any): Promise<any> {
|
|
||||||
if (data.cronId) {
|
|
||||||
return await this.cronService.run([data.cronId]);
|
|
||||||
}
|
|
||||||
throw new Error('cronId is required for run_task action');
|
|
||||||
}
|
|
||||||
|
|
||||||
public async executeSetVariable(data: any): Promise<any> {
|
|
||||||
if (data.name && data.value !== undefined) {
|
|
||||||
return await this.envService.create([{
|
|
||||||
name: data.name,
|
|
||||||
value: data.value,
|
|
||||||
remarks: `Set by scenario workflow`,
|
|
||||||
}]);
|
|
||||||
}
|
|
||||||
throw new Error('name and value are required for set_variable action');
|
|
||||||
}
|
|
||||||
|
|
||||||
public async executeCommand(data: any): Promise<any> {
|
|
||||||
if (data.command) {
|
|
||||||
const { stdout, stderr } = await execAsync(data.command);
|
|
||||||
return { stdout, stderr };
|
|
||||||
}
|
|
||||||
throw new Error('command is required for execute_command action');
|
|
||||||
}
|
|
||||||
|
|
||||||
public async executeSendNotification(data: any): Promise<any> {
|
|
||||||
// Log notification for now - can be extended to integrate with notification service
|
|
||||||
this.logger.info(`Notification: ${data.message || 'No message'}`);
|
|
||||||
return { sent: true, message: data.message };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -131,4 +131,32 @@ export default class SshKeyService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async addGlobalSSHKey(key: string, alias: string): Promise<void> {
|
||||||
|
await this.generatePrivateKeyFile(`~global_${alias}`, key);
|
||||||
|
// Create a global SSH config entry that matches all hosts
|
||||||
|
// This allows the key to be used for any Git repository
|
||||||
|
await this.generateGlobalSshConfig(`~global_${alias}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async removeGlobalSSHKey(alias: string): Promise<void> {
|
||||||
|
await this.removePrivateKeyFile(`~global_${alias}`);
|
||||||
|
await this.removeSshConfig(`~global_${alias}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async generateGlobalSshConfig(alias: string) {
|
||||||
|
// Create a config that matches all hosts, making this key globally available
|
||||||
|
const config = `Host *\n IdentityFile ${path.join(
|
||||||
|
this.sshPath,
|
||||||
|
alias,
|
||||||
|
)}\n StrictHostKeyChecking no\n`;
|
||||||
|
await writeFileWithLock(
|
||||||
|
`${path.join(this.sshPath, `${alias}.config`)}`,
|
||||||
|
config,
|
||||||
|
{
|
||||||
|
encoding: 'utf8',
|
||||||
|
mode: '600',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import { formatCommand, formatUrl } from '../config/subscription';
|
|||||||
import { CrontabModel } from '../data/cron';
|
import { CrontabModel } from '../data/cron';
|
||||||
import CrontabService from './cron';
|
import CrontabService from './cron';
|
||||||
import taskLimit from '../shared/pLimit';
|
import taskLimit from '../shared/pLimit';
|
||||||
|
import { logStreamManager } from '../shared/logStreamManager';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class SubscriptionService {
|
export default class SubscriptionService {
|
||||||
@@ -136,7 +137,7 @@ export default class SubscriptionService {
|
|||||||
let beforeStr = '';
|
let beforeStr = '';
|
||||||
try {
|
try {
|
||||||
if (doc.sub_before) {
|
if (doc.sub_before) {
|
||||||
await fs.appendFile(absolutePath, `\n## 执行before命令...\n\n`);
|
await logStreamManager.write(absolutePath, `\n## 执行before命令...\n\n`);
|
||||||
beforeStr = await promiseExec(doc.sub_before);
|
beforeStr = await promiseExec(doc.sub_before);
|
||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
@@ -144,7 +145,7 @@ export default class SubscriptionService {
|
|||||||
(error.stderr && error.stderr.toString()) || JSON.stringify(error);
|
(error.stderr && error.stderr.toString()) || JSON.stringify(error);
|
||||||
}
|
}
|
||||||
if (beforeStr) {
|
if (beforeStr) {
|
||||||
await fs.appendFile(absolutePath, `${beforeStr}\n`);
|
await logStreamManager.write(absolutePath, `${beforeStr}\n`);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onStart: async (cp: ChildProcessWithoutNullStreams, startTime) => {
|
onStart: async (cp: ChildProcessWithoutNullStreams, startTime) => {
|
||||||
@@ -163,7 +164,7 @@ export default class SubscriptionService {
|
|||||||
let afterStr = '';
|
let afterStr = '';
|
||||||
try {
|
try {
|
||||||
if (sub.sub_after) {
|
if (sub.sub_after) {
|
||||||
await fs.appendFile(absolutePath, `\n\n## 执行after命令...\n\n`);
|
await logStreamManager.write(absolutePath, `\n\n## 执行after命令...\n\n`);
|
||||||
afterStr = await promiseExec(sub.sub_after);
|
afterStr = await promiseExec(sub.sub_after);
|
||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
@@ -171,16 +172,19 @@ export default class SubscriptionService {
|
|||||||
(error.stderr && error.stderr.toString()) || JSON.stringify(error);
|
(error.stderr && error.stderr.toString()) || JSON.stringify(error);
|
||||||
}
|
}
|
||||||
if (afterStr) {
|
if (afterStr) {
|
||||||
await fs.appendFile(absolutePath, `${afterStr}\n`);
|
await logStreamManager.write(absolutePath, `${afterStr}\n`);
|
||||||
}
|
}
|
||||||
|
|
||||||
await fs.appendFile(
|
await logStreamManager.write(
|
||||||
absolutePath,
|
absolutePath,
|
||||||
`\n## 执行结束... ${endTime.format(
|
`\n## 执行结束... ${endTime.format(
|
||||||
'YYYY-MM-DD HH:mm:ss',
|
'YYYY-MM-DD HH:mm:ss',
|
||||||
)} 耗时 ${diff} 秒${LOG_END_SYMBOL}`,
|
)} 耗时 ${diff} 秒${LOG_END_SYMBOL}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Close the stream after task completion
|
||||||
|
await logStreamManager.closeStream(absolutePath);
|
||||||
|
|
||||||
await SubscriptionModel.update(
|
await SubscriptionModel.update(
|
||||||
{ status: SubscriptionStatus.idle, pid: undefined },
|
{ status: SubscriptionStatus.idle, pid: undefined },
|
||||||
{ where: { id: sub.id } },
|
{ where: { id: sub.id } },
|
||||||
@@ -195,12 +199,12 @@ export default class SubscriptionService {
|
|||||||
onError: async (message: string) => {
|
onError: async (message: string) => {
|
||||||
const sub = await this.getDb({ id: doc.id });
|
const sub = await this.getDb({ id: doc.id });
|
||||||
const absolutePath = await handleLogPath(sub.log_path as string);
|
const absolutePath = await handleLogPath(sub.log_path as string);
|
||||||
await fs.appendFile(absolutePath, `\n${message}`);
|
await logStreamManager.write(absolutePath, `\n${message}`);
|
||||||
},
|
},
|
||||||
onLog: async (message: string) => {
|
onLog: async (message: string) => {
|
||||||
const sub = await this.getDb({ id: doc.id });
|
const sub = await this.getDb({ id: doc.id });
|
||||||
const absolutePath = await handleLogPath(sub.log_path as string);
|
const absolutePath = await handleLogPath(sub.log_path as string);
|
||||||
await fs.appendFile(absolutePath, `\n${message}`);
|
await logStreamManager.write(absolutePath, `\n${message}`);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -530,6 +530,27 @@ export default class SystemService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async updateGlobalSshKey(info: SystemModelInfo) {
|
||||||
|
const oDoc = await this.getSystemConfig();
|
||||||
|
const result = await this.updateAuthDb({
|
||||||
|
...oDoc,
|
||||||
|
info: { ...oDoc.info, ...info },
|
||||||
|
});
|
||||||
|
|
||||||
|
// Apply the global SSH key
|
||||||
|
const SshKeyService = require('./sshKey').default;
|
||||||
|
const Container = require('typedi').Container;
|
||||||
|
const sshKeyService = Container.get(SshKeyService);
|
||||||
|
|
||||||
|
if (info.globalSshKey) {
|
||||||
|
await sshKeyService.addGlobalSSHKey(info.globalSshKey, 'global');
|
||||||
|
} else {
|
||||||
|
await sshKeyService.removeGlobalSSHKey('global');
|
||||||
|
}
|
||||||
|
|
||||||
|
return { code: 200, data: result };
|
||||||
|
}
|
||||||
|
|
||||||
public async cleanDependence(type: 'node' | 'python3') {
|
public async cleanDependence(type: 'node' | 'python3') {
|
||||||
if (!type || !['node', 'python3'].includes(type)) {
|
if (!type || !['node', 'python3'].includes(type)) {
|
||||||
return { code: 400, message: '参数错误' };
|
return { code: 400, message: '参数错误' };
|
||||||
|
|||||||
+139
-7
@@ -11,6 +11,7 @@ import {
|
|||||||
SystemModelInfo,
|
SystemModelInfo,
|
||||||
LoginStatus,
|
LoginStatus,
|
||||||
AuthInfo,
|
AuthInfo,
|
||||||
|
TokenInfo,
|
||||||
} from '../data/system';
|
} from '../data/system';
|
||||||
import { NotificationInfo } from '../data/notify';
|
import { NotificationInfo } from '../data/notify';
|
||||||
import NotificationService from './notify';
|
import NotificationService from './notify';
|
||||||
@@ -101,12 +102,23 @@ export default class UserService {
|
|||||||
algorithm: 'HS384',
|
algorithm: 'HS384',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const tokenInfo: TokenInfo = {
|
||||||
|
value: token,
|
||||||
|
timestamp,
|
||||||
|
ip,
|
||||||
|
address,
|
||||||
|
platform: req.platform,
|
||||||
|
};
|
||||||
|
|
||||||
|
const updatedTokens = this.addTokenToList(
|
||||||
|
tokens,
|
||||||
|
req.platform,
|
||||||
|
tokenInfo,
|
||||||
|
);
|
||||||
|
|
||||||
await this.updateAuthInfo(content, {
|
await this.updateAuthInfo(content, {
|
||||||
token,
|
token,
|
||||||
tokens: {
|
tokens: updatedTokens,
|
||||||
...tokens,
|
|
||||||
[req.platform]: token,
|
|
||||||
},
|
|
||||||
lastlogon: timestamp,
|
lastlogon: timestamp,
|
||||||
retries: 0,
|
retries: 0,
|
||||||
lastip: ip,
|
lastip: ip,
|
||||||
@@ -180,11 +192,37 @@ export default class UserService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async logout(platform: string): Promise<any> {
|
public async logout(platform: string, tokenValue: string): Promise<any> {
|
||||||
|
if (!platform || !tokenValue) {
|
||||||
|
this.logger.warn('Invalid logout parameters - empty platform or token');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const authInfo = await this.getAuthInfo();
|
const authInfo = await this.getAuthInfo();
|
||||||
|
|
||||||
|
// Verify the token exists before attempting to remove it
|
||||||
|
const tokenExists = this.findTokenInList(
|
||||||
|
authInfo.tokens,
|
||||||
|
platform,
|
||||||
|
tokenValue,
|
||||||
|
);
|
||||||
|
if (!tokenExists && authInfo.token !== tokenValue) {
|
||||||
|
// Token not found, but don't throw error - user may have already logged out
|
||||||
|
this.logger.info(
|
||||||
|
`Logout attempted for non-existent token on platform: ${platform}`,
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const updatedTokens = this.removeTokenFromList(
|
||||||
|
authInfo.tokens,
|
||||||
|
platform,
|
||||||
|
tokenValue,
|
||||||
|
);
|
||||||
|
|
||||||
await this.updateAuthInfo(authInfo, {
|
await this.updateAuthInfo(authInfo, {
|
||||||
token: '',
|
token: authInfo.token === tokenValue ? '' : authInfo.token,
|
||||||
tokens: { ...authInfo.tokens, [platform]: '' },
|
tokens: updatedTokens,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -364,6 +402,100 @@ export default class UserService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private normalizeTokens(
|
||||||
|
tokens: Record<string, string | TokenInfo[]>,
|
||||||
|
): Record<string, TokenInfo[]> {
|
||||||
|
const normalized: Record<string, TokenInfo[]> = {};
|
||||||
|
|
||||||
|
for (const [platform, value] of Object.entries(tokens)) {
|
||||||
|
if (typeof value === 'string') {
|
||||||
|
// Legacy format: convert string token to TokenInfo array
|
||||||
|
if (value) {
|
||||||
|
normalized[platform] = [
|
||||||
|
{
|
||||||
|
value,
|
||||||
|
timestamp: Date.now(),
|
||||||
|
ip: '',
|
||||||
|
address: '',
|
||||||
|
platform,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
normalized[platform] = [];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Already in new format
|
||||||
|
normalized[platform] = value || [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return normalized;
|
||||||
|
}
|
||||||
|
|
||||||
|
private addTokenToList(
|
||||||
|
tokens: Record<string, string | TokenInfo[]>,
|
||||||
|
platform: string,
|
||||||
|
tokenInfo: TokenInfo,
|
||||||
|
maxTokensPerPlatform: number = config.maxTokensPerPlatform,
|
||||||
|
): Record<string, TokenInfo[]> {
|
||||||
|
// Validate maxTokensPerPlatform parameter
|
||||||
|
if (!Number.isInteger(maxTokensPerPlatform) || maxTokensPerPlatform < 1) {
|
||||||
|
this.logger.warn(
|
||||||
|
`Invalid maxTokensPerPlatform value: ${maxTokensPerPlatform}, using default`,
|
||||||
|
);
|
||||||
|
maxTokensPerPlatform = config.maxTokensPerPlatform;
|
||||||
|
}
|
||||||
|
|
||||||
|
const normalized = this.normalizeTokens(tokens);
|
||||||
|
|
||||||
|
if (!normalized[platform]) {
|
||||||
|
normalized[platform] = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add new token
|
||||||
|
normalized[platform].unshift(tokenInfo);
|
||||||
|
|
||||||
|
// Limit the number of active tokens per platform
|
||||||
|
if (normalized[platform].length > maxTokensPerPlatform) {
|
||||||
|
normalized[platform] = normalized[platform].slice(
|
||||||
|
0,
|
||||||
|
maxTokensPerPlatform,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return normalized;
|
||||||
|
}
|
||||||
|
|
||||||
|
private removeTokenFromList(
|
||||||
|
tokens: Record<string, string | TokenInfo[]>,
|
||||||
|
platform: string,
|
||||||
|
tokenValue: string,
|
||||||
|
): Record<string, TokenInfo[]> {
|
||||||
|
const normalized = this.normalizeTokens(tokens);
|
||||||
|
|
||||||
|
if (normalized[platform]) {
|
||||||
|
normalized[platform] = normalized[platform].filter(
|
||||||
|
(t) => t.value !== tokenValue,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return normalized;
|
||||||
|
}
|
||||||
|
|
||||||
|
private findTokenInList(
|
||||||
|
tokens: Record<string, string | TokenInfo[]>,
|
||||||
|
platform: string,
|
||||||
|
tokenValue: string,
|
||||||
|
): TokenInfo | undefined {
|
||||||
|
const normalized = this.normalizeTokens(tokens);
|
||||||
|
|
||||||
|
if (normalized[platform]) {
|
||||||
|
return normalized[platform].find((t) => t.value === tokenValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
public async resetAuthInfo(info: Partial<AuthInfo>) {
|
public async resetAuthInfo(info: Partial<AuthInfo>) {
|
||||||
const { retries, twoFactorActivated, password, username } = info;
|
const { retries, twoFactorActivated, password, username } = info;
|
||||||
const authInfo = await this.getAuthInfo();
|
const authInfo = await this.getAuthInfo();
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
import { AuthInfo, TokenInfo } from '../data/system';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates if a token exists in the authentication info.
|
||||||
|
* Supports both legacy string tokens and new TokenInfo array format.
|
||||||
|
*
|
||||||
|
* @param authInfo - The authentication information
|
||||||
|
* @param headerToken - The token to validate
|
||||||
|
* @param platform - The platform (desktop, mobile)
|
||||||
|
* @returns true if the token is valid, false otherwise
|
||||||
|
*/
|
||||||
|
export function isValidToken(
|
||||||
|
authInfo: AuthInfo | null | undefined,
|
||||||
|
headerToken: string,
|
||||||
|
platform: string,
|
||||||
|
): boolean {
|
||||||
|
if (!authInfo || !headerToken) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { token = '', tokens = {} } = authInfo;
|
||||||
|
|
||||||
|
// Check legacy token field
|
||||||
|
if (headerToken === token) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check platform-specific tokens (support both legacy string and new TokenInfo[] format)
|
||||||
|
const platformTokens = tokens[platform];
|
||||||
|
|
||||||
|
// Handle null/undefined platformTokens
|
||||||
|
if (platformTokens === null || platformTokens === undefined) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof platformTokens === 'string') {
|
||||||
|
// Legacy format: single string token
|
||||||
|
return headerToken === platformTokens;
|
||||||
|
} else if (Array.isArray(platformTokens)) {
|
||||||
|
// New format: array of TokenInfo objects
|
||||||
|
return platformTokens.some((t: TokenInfo) => t && t.value === headerToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unexpected type - log warning and reject
|
||||||
|
return false;
|
||||||
|
}
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
import { createWriteStream, WriteStream } from 'fs';
|
||||||
|
import { EventEmitter } from 'events';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manages write streams for log files to improve performance by avoiding repeated file opens
|
||||||
|
*/
|
||||||
|
export class LogStreamManager extends EventEmitter {
|
||||||
|
private streams: Map<string, WriteStream> = new Map();
|
||||||
|
private pendingWrites: Map<string, Promise<void>> = new Map();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write data to a log file using a managed stream
|
||||||
|
* @param filePath - Absolute path to the log file
|
||||||
|
* @param data - Data to write to the log file
|
||||||
|
*/
|
||||||
|
async write(filePath: string, data: string): Promise<void> {
|
||||||
|
// Wait for any pending writes to this file to complete
|
||||||
|
const pending = this.pendingWrites.get(filePath);
|
||||||
|
if (pending) {
|
||||||
|
await pending;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a new promise for this write operation
|
||||||
|
const writePromise = new Promise<void>((resolve, reject) => {
|
||||||
|
let stream = this.streams.get(filePath);
|
||||||
|
|
||||||
|
if (!stream) {
|
||||||
|
// Create a new write stream if one doesn't exist
|
||||||
|
stream = createWriteStream(filePath, { flags: 'a' });
|
||||||
|
this.streams.set(filePath, stream);
|
||||||
|
|
||||||
|
// Handle stream errors
|
||||||
|
stream.on('error', (error) => {
|
||||||
|
this.emit('error', { filePath, error });
|
||||||
|
// Remove the stream from the map on error
|
||||||
|
this.streams.delete(filePath);
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write the data
|
||||||
|
const canContinue = stream.write(data, 'utf8', (error) => {
|
||||||
|
if (error) {
|
||||||
|
reject(error);
|
||||||
|
} else {
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Handle backpressure
|
||||||
|
if (!canContinue) {
|
||||||
|
stream.once('drain', () => {
|
||||||
|
// Stream is ready for more data
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.pendingWrites.set(filePath, writePromise);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await writePromise;
|
||||||
|
} finally {
|
||||||
|
this.pendingWrites.delete(filePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close the stream for a specific file path
|
||||||
|
* @param filePath - Absolute path to the log file
|
||||||
|
*/
|
||||||
|
async closeStream(filePath: string): Promise<void> {
|
||||||
|
// Wait for any pending writes to complete
|
||||||
|
const pending = this.pendingWrites.get(filePath);
|
||||||
|
if (pending) {
|
||||||
|
await pending.catch(() => {
|
||||||
|
// Ignore errors on pending writes during close
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const stream = this.streams.get(filePath);
|
||||||
|
if (stream) {
|
||||||
|
return new Promise<void>((resolve) => {
|
||||||
|
stream.end(() => {
|
||||||
|
this.streams.delete(filePath);
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close all open streams
|
||||||
|
*/
|
||||||
|
async closeAll(): Promise<void> {
|
||||||
|
const closePromises = Array.from(this.streams.keys()).map((filePath) =>
|
||||||
|
this.closeStream(filePath),
|
||||||
|
);
|
||||||
|
await Promise.all(closePromises);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the number of open streams
|
||||||
|
*/
|
||||||
|
getOpenStreamCount(): number {
|
||||||
|
return this.streams.size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Export a singleton instance for shared use
|
||||||
|
export const logStreamManager = new LogStreamManager();
|
||||||
@@ -2,10 +2,45 @@ import { spawn } from 'cross-spawn';
|
|||||||
import taskLimit from './pLimit';
|
import taskLimit from './pLimit';
|
||||||
import Logger from '../loaders/logger';
|
import Logger from '../loaders/logger';
|
||||||
import { ICron } from '../protos/cron';
|
import { ICron } from '../protos/cron';
|
||||||
|
import { CrontabModel, CrontabStatus } from '../data/cron';
|
||||||
|
import { killTask } from '../config/util';
|
||||||
|
|
||||||
export function runCron(cmd: string, cron: ICron): Promise<number | void> {
|
export function runCron(cmd: string, cron: ICron): Promise<number | void> {
|
||||||
return taskLimit.runWithCronLimit(cron, () => {
|
return taskLimit.runWithCronLimit(cron, () => {
|
||||||
return new Promise(async (resolve: any) => {
|
return new Promise(async (resolve: any) => {
|
||||||
|
// Check if the cron is already running and stop it (only if multiple instances are not allowed)
|
||||||
|
try {
|
||||||
|
const existingCron = await CrontabModel.findOne({
|
||||||
|
where: { id: Number(cron.id) },
|
||||||
|
});
|
||||||
|
|
||||||
|
// Default to single instance mode (0) for backward compatibility
|
||||||
|
const allowSingleInstances =
|
||||||
|
existingCron?.allow_multiple_instances === 0;
|
||||||
|
|
||||||
|
if (
|
||||||
|
allowSingleInstances &&
|
||||||
|
existingCron &&
|
||||||
|
existingCron.pid &&
|
||||||
|
(existingCron.status === CrontabStatus.running ||
|
||||||
|
existingCron.status === CrontabStatus.queued)
|
||||||
|
) {
|
||||||
|
Logger.info(
|
||||||
|
`[schedule][停止已运行任务] 任务ID: ${cron.id}, PID: ${existingCron.pid}`,
|
||||||
|
);
|
||||||
|
await killTask(existingCron.pid);
|
||||||
|
// Update the status to idle after killing
|
||||||
|
await CrontabModel.update(
|
||||||
|
{ status: CrontabStatus.idle, pid: undefined },
|
||||||
|
{ where: { id: Number(cron.id) } },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
Logger.error(
|
||||||
|
`[schedule][检查已运行任务失败] 任务ID: ${cron.id}, 错误: ${error}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Logger.info(
|
Logger.info(
|
||||||
`[schedule][开始执行任务] 参数 ${JSON.stringify({
|
`[schedule][开始执行任务] 参数 ${JSON.stringify({
|
||||||
...cron,
|
...cron,
|
||||||
|
|||||||
@@ -64,7 +64,11 @@ export const commonCronSchema = {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!/^(?!.*(?:^|\/)\.{1,2}(?:\/|$))(?:\/)?(?:[\w.-]+\/)*[\w.-]+\/?$/.test(value)) {
|
if (
|
||||||
|
!/^(?!.*(?:^|\/)\.{1,2}(?:\/|$))(?:\/)?(?:[\w.-]+\/)*[\w.-]+\/?$/.test(
|
||||||
|
value,
|
||||||
|
)
|
||||||
|
) {
|
||||||
return helpers.error('string.pattern.base');
|
return helpers.error('string.pattern.base');
|
||||||
}
|
}
|
||||||
if (value.length > 100) {
|
if (value.length > 100) {
|
||||||
@@ -77,4 +81,5 @@ export const commonCronSchema = {
|
|||||||
'string.max': '日志名称不能超过100个字符',
|
'string.max': '日志名称不能超过100个字符',
|
||||||
'string.unsafePath': '绝对路径必须在日志目录内或使用 /dev/null',
|
'string.unsafePath': '绝对路径必须在日志目录内或使用 /dev/null',
|
||||||
}),
|
}),
|
||||||
|
allow_multiple_instances: Joi.number().optional().valid(0, 1).allow(null),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,37 +1,56 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
export PATH="$HOME/bin:$PATH"
|
||||||
|
|
||||||
dir_shell=/ql/shell
|
dir_shell=/ql/shell
|
||||||
. $dir_shell/share.sh
|
. $dir_shell/share.sh
|
||||||
. $dir_shell/env.sh
|
|
||||||
|
export_ql_envs() {
|
||||||
|
export BACK_PORT="${ql_port}"
|
||||||
|
export GRPC_PORT="${ql_grpc_port}"
|
||||||
|
}
|
||||||
|
|
||||||
log_with_style() {
|
log_with_style() {
|
||||||
local level="$1"
|
local level="$1"
|
||||||
local message="$2"
|
local message="$2"
|
||||||
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
|
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
|
||||||
|
|
||||||
printf "\n[%s] [%7s] %s\n" "${timestamp}" "${level}" "${message}"
|
printf "\n[%s] [%7s] %s\n" "${timestamp}" "${level}" "${message}"
|
||||||
}
|
}
|
||||||
|
|
||||||
log_with_style "INFO" "🚀 1. 检测配置文件..."
|
# Fix DNS resolution issues in Alpine Linux
|
||||||
|
# Alpine uses musl libc which has known DNS resolver issues with certain domains
|
||||||
|
# Adding ndots:0 prevents unnecessary search domain appending
|
||||||
|
if [ -f /etc/alpine-release ]; then
|
||||||
|
if ! grep -q "^options ndots:0" /etc/resolv.conf 2>/dev/null; then
|
||||||
|
echo "options ndots:0" >> /etc/resolv.conf
|
||||||
|
log_with_style "INFO" "🔧 0. 已配置 DNS 解析优化 (ndots:0)"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
log_with_style "INFO" "🚀 1. 检测配置文件..."
|
||||||
|
load_ql_envs
|
||||||
|
export_ql_envs
|
||||||
|
. $dir_shell/env.sh
|
||||||
import_config "$@"
|
import_config "$@"
|
||||||
fix_config
|
fix_config
|
||||||
|
|
||||||
pm2 l &>/dev/null
|
# Try to initialize PM2, but don't fail if it doesn't work
|
||||||
|
pm2 l &>/dev/null || log_with_style "WARN" "PM2 初始化可能失败,将在启动时尝试使用备用方案"
|
||||||
|
|
||||||
log_with_style "INFO" "⚙️ 2. 启动 pm2 服务..."
|
log_with_style "INFO" "⚙️ 2. 启动 pm2 服务..."
|
||||||
reload_pm2
|
reload_pm2
|
||||||
|
|
||||||
if [[ $AutoStartBot == true ]]; then
|
if [[ $AutoStartBot == true ]]; then
|
||||||
log_with_style "INFO" "🤖 3. 启动 bot..."
|
log_with_style "INFO" "🤖 3. 启动 bot..."
|
||||||
nohup ql bot >$dir_log/bot.log 2>&1 &
|
nohup ql bot >$dir_log/bot.log 2>&1 &
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $EnableExtraShell == true ]]; then
|
if [[ $EnableExtraShell == true ]]; then
|
||||||
log_with_style "INFO" "🛠️ 4. 执行自定义脚本..."
|
log_with_style "INFO" "🛠️ 4. 执行自定义脚本..."
|
||||||
nohup ql extra >$dir_log/extra.log 2>&1 &
|
nohup ql extra >$dir_log/extra.log 2>&1 &
|
||||||
fi
|
fi
|
||||||
|
|
||||||
log_with_style "SUCCESS" "🎉 容器启动成功!"
|
log_with_style "SUCCESS" "🎉 容器启动成功!"
|
||||||
|
|
||||||
crond -f >/dev/null
|
crond -f >/dev/null
|
||||||
|
|
||||||
|
|||||||
+21
-35
@@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"private": true,
|
"private": true,
|
||||||
|
"packageManager": "pnpm@8.3.1",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "concurrently -n w: npm:start:*",
|
"start": "concurrently -n w: npm:start:*",
|
||||||
"start:back": "nodemon ./back/app.ts",
|
"start:back": "nodemon ./back/app.ts",
|
||||||
@@ -54,15 +55,12 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@bufbuild/protobuf": "^2.10.0",
|
|
||||||
"@grpc/grpc-js": "^1.14.0",
|
"@grpc/grpc-js": "^1.14.0",
|
||||||
"@grpc/proto-loader": "^0.8.0",
|
"@grpc/proto-loader": "^0.8.0",
|
||||||
"@keyv/sqlite": "^4.0.1",
|
|
||||||
"@otplib/preset-default": "^12.0.1",
|
"@otplib/preset-default": "^12.0.1",
|
||||||
"body-parser": "^1.20.3",
|
"body-parser": "^1.20.3",
|
||||||
"celebrate": "^15.0.3",
|
"celebrate": "^15.0.3",
|
||||||
"chokidar": "^4.0.1",
|
"chokidar": "^4.0.1",
|
||||||
"compression": "^1.7.4",
|
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"cron-parser": "^5.4.0",
|
"cron-parser": "^5.4.0",
|
||||||
"cross-spawn": "^7.0.6",
|
"cross-spawn": "^7.0.6",
|
||||||
@@ -72,63 +70,51 @@
|
|||||||
"express-jwt": "^8.4.1",
|
"express-jwt": "^8.4.1",
|
||||||
"express-rate-limit": "^7.4.1",
|
"express-rate-limit": "^7.4.1",
|
||||||
"express-urlrewrite": "^2.0.3",
|
"express-urlrewrite": "^2.0.3",
|
||||||
"helmet": "^8.1.0",
|
"undici": "^7.9.0",
|
||||||
"hpagent": "^1.2.0",
|
"hpagent": "^1.2.0",
|
||||||
"http-proxy-middleware": "^3.0.3",
|
"http-proxy-middleware": "^3.0.3",
|
||||||
"iconv-lite": "^0.6.3",
|
"iconv-lite": "^0.6.3",
|
||||||
"ip2region": "2.3.0",
|
|
||||||
"js-yaml": "^4.1.0",
|
"js-yaml": "^4.1.0",
|
||||||
"jsonwebtoken": "^9.0.2",
|
"jsonwebtoken": "^9.0.2",
|
||||||
"keyv": "^5.2.3",
|
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"multer": "1.4.5-lts.1",
|
"multer": "1.4.5-lts.1",
|
||||||
"node-schedule": "^2.1.0",
|
"node-schedule": "^2.1.0",
|
||||||
"nodemailer": "^6.9.16",
|
"nodemailer": "^6.9.16",
|
||||||
"nanoid": "^5.0.9",
|
|
||||||
"p-queue-cjs": "7.3.4",
|
"p-queue-cjs": "7.3.4",
|
||||||
"proper-lockfile": "^4.1.2",
|
"@bufbuild/protobuf": "^2.10.0",
|
||||||
"ps-tree": "^1.2.0",
|
"ps-tree": "^1.2.0",
|
||||||
"reflect-metadata": "^0.2.2",
|
"reflect-metadata": "^0.2.2",
|
||||||
"request-ip": "3.3.0",
|
|
||||||
"sequelize": "^6.37.5",
|
"sequelize": "^6.37.5",
|
||||||
"sockjs": "^0.3.24",
|
"sockjs": "^0.3.24",
|
||||||
"sqlite3": "git+https://github.com/whyour/node-sqlite3.git#v1.0.3",
|
"sqlite3": "git+https://github.com/whyour/node-sqlite3.git#v1.0.3",
|
||||||
"toad-scheduler": "^3.0.1",
|
"toad-scheduler": "^3.0.1",
|
||||||
"typedi": "^0.10.0",
|
"typedi": "^0.10.0",
|
||||||
"undici": "^7.9.0",
|
|
||||||
"uuid": "^11.0.3",
|
"uuid": "^11.0.3",
|
||||||
"winston": "^3.17.0",
|
"winston": "^3.17.0",
|
||||||
"winston-daily-rotate-file": "^5.0.0"
|
"winston-daily-rotate-file": "^5.0.0",
|
||||||
|
"request-ip": "3.3.0",
|
||||||
|
"ip2region": "2.3.0",
|
||||||
|
"keyv": "^5.2.3",
|
||||||
|
"@keyv/sqlite": "^4.0.1",
|
||||||
|
"proper-lockfile": "^4.1.2",
|
||||||
|
"compression": "^1.7.4",
|
||||||
|
"helmet": "^8.1.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"moment": "2.30.1",
|
||||||
"@ant-design/icons": "^5.0.1",
|
"@ant-design/icons": "^5.0.1",
|
||||||
"@ant-design/pro-layout": "6.38.22",
|
"@ant-design/pro-layout": "6.38.22",
|
||||||
"@codemirror/state": "^6.4.1",
|
|
||||||
"@codemirror/view": "^6.34.1",
|
"@codemirror/view": "^6.34.1",
|
||||||
"@flowgram.ai/core": "^1.0.2",
|
"@codemirror/state": "^6.4.1",
|
||||||
"@flowgram.ai/free-layout-editor": "^1.0.2",
|
|
||||||
"@flowgram.ai/reactive": "^1.0.2",
|
|
||||||
"@flowgram.ai/free-snap-plugin": "^1.0.2",
|
|
||||||
"@flowgram.ai/free-lines-plugin": "^1.0.2",
|
|
||||||
"@flowgram.ai/free-node-panel-plugin": "^1.0.2",
|
|
||||||
"@flowgram.ai/minimap-plugin": "^1.0.2",
|
|
||||||
"@flowgram.ai/free-container-plugin": "^1.0.2",
|
|
||||||
"@flowgram.ai/free-group-plugin": "^1.0.2",
|
|
||||||
"@flowgram.ai/form-materials": "^1.0.2",
|
|
||||||
"@flowgram.ai/panel-manager-plugin": "^1.0.2",
|
|
||||||
"@flowgram.ai/free-stack-plugin": "^1.0.2",
|
|
||||||
"@flowgram.ai/runtime-interface": "^1.0.2",
|
|
||||||
"@flowgram.ai/runtime-js": "^1.0.2",
|
|
||||||
"@monaco-editor/react": "4.2.1",
|
"@monaco-editor/react": "4.2.1",
|
||||||
"@react-hook/resize-observer": "^2.0.2",
|
"@react-hook/resize-observer": "^2.0.2",
|
||||||
|
"react-router-dom": "6.26.1",
|
||||||
"@types/body-parser": "^1.19.2",
|
"@types/body-parser": "^1.19.2",
|
||||||
"@types/compression": "^1.7.2",
|
|
||||||
"@types/cors": "^2.8.12",
|
"@types/cors": "^2.8.12",
|
||||||
"@types/cross-spawn": "^6.0.2",
|
"@types/cross-spawn": "^6.0.2",
|
||||||
"@types/express": "^4.17.13",
|
"@types/express": "^4.17.13",
|
||||||
"@types/express-jwt": "^6.0.4",
|
"@types/express-jwt": "^6.0.4",
|
||||||
"@types/file-saver": "2.0.2",
|
"@types/file-saver": "2.0.2",
|
||||||
"@types/helmet": "^4.0.0",
|
|
||||||
"@types/js-yaml": "^4.0.5",
|
"@types/js-yaml": "^4.0.5",
|
||||||
"@types/jsonwebtoken": "^8.5.8",
|
"@types/jsonwebtoken": "^8.5.8",
|
||||||
"@types/lodash": "^4.14.185",
|
"@types/lodash": "^4.14.185",
|
||||||
@@ -136,17 +122,17 @@
|
|||||||
"@types/node": "^17.0.21",
|
"@types/node": "^17.0.21",
|
||||||
"@types/node-schedule": "^1.3.2",
|
"@types/node-schedule": "^1.3.2",
|
||||||
"@types/nodemailer": "^6.4.4",
|
"@types/nodemailer": "^6.4.4",
|
||||||
"@types/proper-lockfile": "^4.1.4",
|
|
||||||
"@types/ps-tree": "^1.1.6",
|
|
||||||
"@types/qrcode.react": "^1.0.2",
|
"@types/qrcode.react": "^1.0.2",
|
||||||
"@types/react": "^18.0.20",
|
"@types/react": "^18.0.20",
|
||||||
"@types/react-copy-to-clipboard": "^5.0.4",
|
"@types/react-copy-to-clipboard": "^5.0.4",
|
||||||
"@types/react-dom": "^18.0.6",
|
"@types/react-dom": "^18.0.6",
|
||||||
"@types/request-ip": "0.0.41",
|
|
||||||
"@types/serve-handler": "^6.1.1",
|
"@types/serve-handler": "^6.1.1",
|
||||||
"@types/sockjs": "^0.3.33",
|
"@types/sockjs": "^0.3.33",
|
||||||
"@types/sockjs-client": "^1.5.1",
|
"@types/sockjs-client": "^1.5.1",
|
||||||
"@types/uuid": "^8.3.4",
|
"@types/uuid": "^8.3.4",
|
||||||
|
"@types/request-ip": "0.0.41",
|
||||||
|
"@types/proper-lockfile": "^4.1.4",
|
||||||
|
"@types/ps-tree": "^1.1.6",
|
||||||
"@uiw/codemirror-extensions-langs": "^4.21.9",
|
"@uiw/codemirror-extensions-langs": "^4.21.9",
|
||||||
"@uiw/react-codemirror": "^4.21.9",
|
"@uiw/react-codemirror": "^4.21.9",
|
||||||
"@umijs/max": "^4.4.4",
|
"@umijs/max": "^4.4.4",
|
||||||
@@ -158,9 +144,9 @@
|
|||||||
"axios": "^1.4.0",
|
"axios": "^1.4.0",
|
||||||
"compression-webpack-plugin": "9.2.0",
|
"compression-webpack-plugin": "9.2.0",
|
||||||
"concurrently": "^7.0.0",
|
"concurrently": "^7.0.0",
|
||||||
|
"react-hotkeys-hook": "^4.6.1",
|
||||||
"file-saver": "2.0.2",
|
"file-saver": "2.0.2",
|
||||||
"lint-staged": "^13.0.3",
|
"lint-staged": "^13.0.3",
|
||||||
"moment": "2.30.1",
|
|
||||||
"monaco-editor": "0.33.0",
|
"monaco-editor": "0.33.0",
|
||||||
"nodemon": "^3.0.1",
|
"nodemon": "^3.0.1",
|
||||||
"prettier": "^2.5.1",
|
"prettier": "^2.5.1",
|
||||||
@@ -176,9 +162,7 @@
|
|||||||
"react-dnd": "^16.0.1",
|
"react-dnd": "^16.0.1",
|
||||||
"react-dnd-html5-backend": "^16.0.1",
|
"react-dnd-html5-backend": "^16.0.1",
|
||||||
"react-dom": "18.3.1",
|
"react-dom": "18.3.1",
|
||||||
"react-hotkeys-hook": "^4.6.1",
|
|
||||||
"react-intl-universal": "^2.12.0",
|
"react-intl-universal": "^2.12.0",
|
||||||
"react-router-dom": "6.26.1",
|
|
||||||
"react-split-pane": "^0.1.92",
|
"react-split-pane": "^0.1.92",
|
||||||
"sockjs-client": "^1.6.0",
|
"sockjs-client": "^1.6.0",
|
||||||
"ts-node": "^10.9.2",
|
"ts-node": "^10.9.2",
|
||||||
@@ -186,6 +170,8 @@
|
|||||||
"tslib": "^2.4.0",
|
"tslib": "^2.4.0",
|
||||||
"typescript": "5.2.2",
|
"typescript": "5.2.2",
|
||||||
"vh-check": "^2.0.5",
|
"vh-check": "^2.0.5",
|
||||||
"virtualizedtableforantd4": "1.3.0"
|
"virtualizedtableforantd4": "1.3.0",
|
||||||
|
"@types/compression": "^1.7.2",
|
||||||
|
"@types/helmet": "^4.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
+22
-3765
File diff suppressed because it is too large
Load Diff
+18
-2
@@ -52,6 +52,7 @@ const push_config = {
|
|||||||
DD_BOT_TOKEN: '', // 钉钉机器人的 DD_BOT_TOKEN
|
DD_BOT_TOKEN: '', // 钉钉机器人的 DD_BOT_TOKEN
|
||||||
|
|
||||||
FSKEY: '', // 飞书机器人的 FSKEY
|
FSKEY: '', // 飞书机器人的 FSKEY
|
||||||
|
FSSECRET: '', // 飞书机器人的 FSSECRET,对应安全设置里的签名校验密钥
|
||||||
|
|
||||||
// 推送到个人QQ:http://127.0.0.1/send_private_msg
|
// 推送到个人QQ:http://127.0.0.1/send_private_msg
|
||||||
// 群:http://127.0.0.1/send_group_msg
|
// 群:http://127.0.0.1/send_group_msg
|
||||||
@@ -989,11 +990,26 @@ function aibotkNotify(text, desp) {
|
|||||||
|
|
||||||
function fsBotNotify(text, desp) {
|
function fsBotNotify(text, desp) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
const { FSKEY } = push_config;
|
const { FSKEY, FSSECRET } = push_config;
|
||||||
if (FSKEY) {
|
if (FSKEY) {
|
||||||
|
const body = { msg_type: 'text', content: { text: `${text}\n\n${desp}` } };
|
||||||
|
|
||||||
|
// Add signature if secret is provided
|
||||||
|
// Note: Feishu's signature algorithm uses timestamp+"\n"+secret as the HMAC key
|
||||||
|
// and signs an empty message, which differs from typical HMAC usage
|
||||||
|
if (FSSECRET) {
|
||||||
|
const crypto = require('crypto');
|
||||||
|
const timestamp = Math.floor(Date.now() / 1000).toString();
|
||||||
|
const stringToSign = `${timestamp}\n${FSSECRET}`;
|
||||||
|
const hmac = crypto.createHmac('sha256', stringToSign);
|
||||||
|
const sign = hmac.digest('base64');
|
||||||
|
body.timestamp = timestamp;
|
||||||
|
body.sign = sign;
|
||||||
|
}
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
url: `https://open.feishu.cn/open-apis/bot/v2/hook/${FSKEY}`,
|
url: `https://open.feishu.cn/open-apis/bot/v2/hook/${FSKEY}`,
|
||||||
json: { msg_type: 'text', content: { text: `${text}\n\n${desp}` } },
|
json: body,
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ push_config = {
|
|||||||
'DD_BOT_TOKEN': '', # 钉钉机器人的 DD_BOT_TOKEN
|
'DD_BOT_TOKEN': '', # 钉钉机器人的 DD_BOT_TOKEN
|
||||||
|
|
||||||
'FSKEY': '', # 飞书机器人的 FSKEY
|
'FSKEY': '', # 飞书机器人的 FSKEY
|
||||||
|
'FSSECRET': '', # 飞书机器人的 FSSECRET,对应安全设置里的签名校验密钥
|
||||||
|
|
||||||
'GOBOT_URL': '', # go-cqhttp
|
'GOBOT_URL': '', # go-cqhttp
|
||||||
# 推送到个人QQ:http://127.0.0.1/send_private_msg
|
# 推送到个人QQ:http://127.0.0.1/send_private_msg
|
||||||
@@ -233,6 +234,20 @@ def feishu_bot(title: str, content: str) -> None:
|
|||||||
|
|
||||||
url = f'https://open.feishu.cn/open-apis/bot/v2/hook/{push_config.get("FSKEY")}'
|
url = f'https://open.feishu.cn/open-apis/bot/v2/hook/{push_config.get("FSKEY")}'
|
||||||
data = {"msg_type": "text", "content": {"text": f"{title}\n\n{content}"}}
|
data = {"msg_type": "text", "content": {"text": f"{title}\n\n{content}"}}
|
||||||
|
|
||||||
|
# Add signature if secret is provided
|
||||||
|
# Note: Feishu's signature algorithm uses timestamp+"\n"+secret as the HMAC key
|
||||||
|
# and signs an empty message, which differs from typical HMAC usage
|
||||||
|
if push_config.get("FSSECRET"):
|
||||||
|
timestamp = str(int(time.time()))
|
||||||
|
string_to_sign = f'{timestamp}\n{push_config.get("FSSECRET")}'
|
||||||
|
hmac_code = hmac.new(
|
||||||
|
string_to_sign.encode("utf-8"), digestmod=hashlib.sha256
|
||||||
|
).digest()
|
||||||
|
sign = base64.b64encode(hmac_code).decode("utf-8")
|
||||||
|
data["timestamp"] = timestamp
|
||||||
|
data["sign"] = sign
|
||||||
|
|
||||||
response = requests.post(url, data=json.dumps(data)).json()
|
response = requests.post(url, data=json.dumps(data)).json()
|
||||||
|
|
||||||
if response.get("StatusCode") == 0 or response.get("code") == 0:
|
if response.get("StatusCode") == 0 or response.get("code") == 0:
|
||||||
|
|||||||
@@ -12,4 +12,32 @@ QLAPI.getEnvs({ searchValue: 'dddd' }).then((x) => {
|
|||||||
QLAPI.systemNotify({ title: '123', content: '231' }).then((x) => {
|
QLAPI.systemNotify({ title: '123', content: '231' }).then((x) => {
|
||||||
console.log('systemNotify', x);
|
console.log('systemNotify', x);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 查询定时任务 (Query cron tasks)
|
||||||
|
QLAPI.getCrons({ searchValue: 'test' }).then((x) => {
|
||||||
|
console.log('getCrons', x);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 通过ID查询定时任务 (Get cron by ID)
|
||||||
|
QLAPI.getCronById({ id: 1 }).then((x) => {
|
||||||
|
console.log('getCronById', x);
|
||||||
|
}).catch((err) => {
|
||||||
|
console.log('getCronById error', err);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 启用定时任务 (Enable cron tasks)
|
||||||
|
QLAPI.enableCrons({ ids: [1, 2] }).then((x) => {
|
||||||
|
console.log('enableCrons', x);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 禁用定时任务 (Disable cron tasks)
|
||||||
|
QLAPI.disableCrons({ ids: [1, 2] }).then((x) => {
|
||||||
|
console.log('disableCrons', x);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 手动执行定时任务 (Run cron tasks manually)
|
||||||
|
QLAPI.runCrons({ ids: [1] }).then((x) => {
|
||||||
|
console.log('runCrons', x);
|
||||||
|
});
|
||||||
|
|
||||||
console.log('test desc');
|
console.log('test desc');
|
||||||
|
|||||||
+8
-8
@@ -41,7 +41,7 @@ add_cron_api() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
local api=$(
|
local api=$(
|
||||||
curl -s --noproxy "*" "http://0.0.0.0:5700/open/crons?t=$currentTimeStamp" \
|
curl -s --noproxy "*" "http://0.0.0.0:${ql_port}/open/crons?t=$currentTimeStamp" \
|
||||||
-H "Authorization: Bearer ${__ql_token__}" \
|
-H "Authorization: Bearer ${__ql_token__}" \
|
||||||
-H "Content-Type: application/json;charset=UTF-8" \
|
-H "Content-Type: application/json;charset=UTF-8" \
|
||||||
--data-raw "{\"name\":\"${name//\"/\\\"}\",\"command\":\"${command//\"/\\\"}\",\"schedule\":\"$schedule\",\"sub_id\":$sub_id}" \
|
--data-raw "{\"name\":\"${name//\"/\\\"}\",\"command\":\"${command//\"/\\\"}\",\"schedule\":\"$schedule\",\"sub_id\":$sub_id}" \
|
||||||
@@ -71,7 +71,7 @@ update_cron_api() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
local api=$(
|
local api=$(
|
||||||
curl -s --noproxy "*" "http://0.0.0.0:5700/open/crons?t=$currentTimeStamp" \
|
curl -s --noproxy "*" "http://0.0.0.0:${ql_port}/open/crons?t=$currentTimeStamp" \
|
||||||
-X 'PUT' \
|
-X 'PUT' \
|
||||||
-H "Authorization: Bearer ${__ql_token__}" \
|
-H "Authorization: Bearer ${__ql_token__}" \
|
||||||
-H "Content-Type: application/json;charset=UTF-8" \
|
-H "Content-Type: application/json;charset=UTF-8" \
|
||||||
@@ -98,7 +98,7 @@ update_cron_command_api() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
local api=$(
|
local api=$(
|
||||||
curl -s --noproxy "*" "http://0.0.0.0:5700/open/crons?t=$currentTimeStamp" \
|
curl -s --noproxy "*" "http://0.0.0.0:${ql_port}/open/crons?t=$currentTimeStamp" \
|
||||||
-X 'PUT' \
|
-X 'PUT' \
|
||||||
-H "Authorization: Bearer ${__ql_token__}" \
|
-H "Authorization: Bearer ${__ql_token__}" \
|
||||||
-H "Content-Type: application/json;charset=UTF-8" \
|
-H "Content-Type: application/json;charset=UTF-8" \
|
||||||
@@ -118,7 +118,7 @@ del_cron_api() {
|
|||||||
local ids="$1"
|
local ids="$1"
|
||||||
local currentTimeStamp=$(date +%s)
|
local currentTimeStamp=$(date +%s)
|
||||||
local api=$(
|
local api=$(
|
||||||
curl -s --noproxy "*" "http://0.0.0.0:5700/open/crons?t=$currentTimeStamp" \
|
curl -s --noproxy "*" "http://0.0.0.0:${ql_port}/open/crons?t=$currentTimeStamp" \
|
||||||
-X 'DELETE' \
|
-X 'DELETE' \
|
||||||
-H "Authorization: Bearer ${__ql_token__}" \
|
-H "Authorization: Bearer ${__ql_token__}" \
|
||||||
-H "Content-Type: application/json;charset=UTF-8" \
|
-H "Content-Type: application/json;charset=UTF-8" \
|
||||||
@@ -143,7 +143,7 @@ update_cron() {
|
|||||||
local runningTime="${6:-0}"
|
local runningTime="${6:-0}"
|
||||||
local currentTimeStamp=$(date +%s)
|
local currentTimeStamp=$(date +%s)
|
||||||
local api=$(
|
local api=$(
|
||||||
curl -s --noproxy "*" "http://0.0.0.0:5700/open/crons/status?t=$currentTimeStamp" \
|
curl -s --noproxy "*" "http://0.0.0.0:${ql_port}/open/crons/status?t=$currentTimeStamp" \
|
||||||
-X 'PUT' \
|
-X 'PUT' \
|
||||||
-H "Authorization: Bearer ${__ql_token__}" \
|
-H "Authorization: Bearer ${__ql_token__}" \
|
||||||
-H "Content-Type: application/json;charset=UTF-8" \
|
-H "Content-Type: application/json;charset=UTF-8" \
|
||||||
@@ -165,7 +165,7 @@ notify_api() {
|
|||||||
local content="$2"
|
local content="$2"
|
||||||
local currentTimeStamp=$(date +%s)
|
local currentTimeStamp=$(date +%s)
|
||||||
local api=$(
|
local api=$(
|
||||||
curl -s --noproxy "*" "http://0.0.0.0:5700/open/system/notify?t=$currentTimeStamp" \
|
curl -s --noproxy "*" "http://0.0.0.0:${ql_port}/open/system/notify?t=$currentTimeStamp" \
|
||||||
-X 'PUT' \
|
-X 'PUT' \
|
||||||
-H "Authorization: Bearer ${__ql_token__}" \
|
-H "Authorization: Bearer ${__ql_token__}" \
|
||||||
-H "Content-Type: application/json;charset=UTF-8" \
|
-H "Content-Type: application/json;charset=UTF-8" \
|
||||||
@@ -185,7 +185,7 @@ find_cron_api() {
|
|||||||
local params="$1"
|
local params="$1"
|
||||||
local currentTimeStamp=$(date +%s)
|
local currentTimeStamp=$(date +%s)
|
||||||
local api=$(
|
local api=$(
|
||||||
curl -s --noproxy "*" "http://0.0.0.0:5700/open/crons/detail?$params&t=$currentTimeStamp" \
|
curl -s --noproxy "*" "http://0.0.0.0:${ql_port}/open/crons/detail?$params&t=$currentTimeStamp" \
|
||||||
-H "Authorization: Bearer ${__ql_token__}" \
|
-H "Authorization: Bearer ${__ql_token__}" \
|
||||||
-H "Content-Type: application/json;charset=UTF-8" \
|
-H "Content-Type: application/json;charset=UTF-8" \
|
||||||
--compressed
|
--compressed
|
||||||
@@ -204,7 +204,7 @@ update_auth_config() {
|
|||||||
local tip="$2"
|
local tip="$2"
|
||||||
local currentTimeStamp=$(date +%s)
|
local currentTimeStamp=$(date +%s)
|
||||||
local api=$(
|
local api=$(
|
||||||
curl -s --noproxy "*" "http://0.0.0.0:5700/open/system/auth/reset?t=$currentTimeStamp" \
|
curl -s --noproxy "*" "http://0.0.0.0:${ql_port}/open/system/auth/reset?t=$currentTimeStamp" \
|
||||||
-X 'PUT' \
|
-X 'PUT' \
|
||||||
-H "Authorization: Bearer ${__ql_token__}" \
|
-H "Authorization: Bearer ${__ql_token__}" \
|
||||||
-H "Content-Type: application/json;charset=UTF-8" \
|
-H "Content-Type: application/json;charset=UTF-8" \
|
||||||
|
|||||||
+3
-3
@@ -31,7 +31,7 @@ pm2_log() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
check_ql() {
|
check_ql() {
|
||||||
local api=$(curl -s --noproxy "*" "http://0.0.0.0:5700")
|
local api=$(curl -s --noproxy "*" "http://0.0.0.0:${ql_port}")
|
||||||
echo -e "\n=====> 检测面板\n\n$api\n"
|
echo -e "\n=====> 检测面板\n\n$api\n"
|
||||||
if [[ $api =~ "<div id=\"root\"></div>" ]]; then
|
if [[ $api =~ "<div id=\"root\"></div>" ]]; then
|
||||||
echo -e "=====> 面板服务启动正常\n"
|
echo -e "=====> 面板服务启动正常\n"
|
||||||
@@ -42,10 +42,10 @@ check_pm2() {
|
|||||||
pm2_log
|
pm2_log
|
||||||
local currentTimeStamp=$(date +%s)
|
local currentTimeStamp=$(date +%s)
|
||||||
local api=$(
|
local api=$(
|
||||||
curl -s --noproxy "*" "http://0.0.0.0:5700/api/system?t=$currentTimeStamp" \
|
curl -s --noproxy "*" "http://0.0.0.0:${ql_port}/api/system?t=$currentTimeStamp" \
|
||||||
-H 'Accept: */*' \
|
-H 'Accept: */*' \
|
||||||
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36' \
|
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36' \
|
||||||
-H 'Referer: http://0.0.0.0:5700/crontab' \
|
-H "Referer: http://0.0.0.0:${ql_port}/crontab" \
|
||||||
-H 'Accept-Language: en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7' \
|
-H 'Accept-Language: en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7' \
|
||||||
--compressed
|
--compressed
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ const { join } = require('path');
|
|||||||
class GrpcClient {
|
class GrpcClient {
|
||||||
static #config = {
|
static #config = {
|
||||||
protoPath: join(process.env.QL_DIR, 'back/protos/api.proto'),
|
protoPath: join(process.env.QL_DIR, 'back/protos/api.proto'),
|
||||||
serverAddress: '0.0.0.0:5500',
|
serverAddress: `0.0.0.0:${process.env.GRPC_PORT || '5500'}`,
|
||||||
protoOptions: {
|
protoOptions: {
|
||||||
keepCase: true,
|
keepCase: true,
|
||||||
longs: String,
|
longs: String,
|
||||||
@@ -33,6 +33,11 @@ class GrpcClient {
|
|||||||
'createCron',
|
'createCron',
|
||||||
'updateCron',
|
'updateCron',
|
||||||
'deleteCrons',
|
'deleteCrons',
|
||||||
|
'getCrons',
|
||||||
|
'getCronById',
|
||||||
|
'enableCrons',
|
||||||
|
'disableCrons',
|
||||||
|
'runCrons',
|
||||||
];
|
];
|
||||||
|
|
||||||
#client;
|
#client;
|
||||||
|
|||||||
+32
-11
@@ -59,15 +59,10 @@ list_own_user=$dir_list_tmp/own_user.list
|
|||||||
list_own_add=$dir_list_tmp/own_add.list
|
list_own_add=$dir_list_tmp/own_add.list
|
||||||
list_own_drop=$dir_list_tmp/own_drop.list
|
list_own_drop=$dir_list_tmp/own_drop.list
|
||||||
|
|
||||||
## 软连接及其原始文件对应关系
|
|
||||||
link_name=(
|
link_name=(
|
||||||
task
|
task
|
||||||
ql
|
ql
|
||||||
)
|
)
|
||||||
original_name=(
|
|
||||||
task.sh
|
|
||||||
update.sh
|
|
||||||
)
|
|
||||||
|
|
||||||
init_env() {
|
init_env() {
|
||||||
local pnpm_global_path=$(pnpm root -g 2>/dev/null)
|
local pnpm_global_path=$(pnpm root -g 2>/dev/null)
|
||||||
@@ -84,15 +79,20 @@ init_env() {
|
|||||||
export PYTHONUNBUFFERED=1
|
export PYTHONUNBUFFERED=1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
load_ql_envs() {
|
||||||
|
ql_base_url=${QlBaseUrl:-"/"}
|
||||||
|
ql_port=${QlPort:-"5700"}
|
||||||
|
ql_grpc_port=${QlGrpcPort:-"5500"}
|
||||||
|
current_branch=${QL_BRANCH:-""}
|
||||||
|
}
|
||||||
|
|
||||||
import_config() {
|
import_config() {
|
||||||
[[ -f $file_config_user ]] && . $file_config_user
|
[[ -f $file_config_user ]] && . $file_config_user
|
||||||
|
|
||||||
ql_base_url=${QlBaseUrl:-"/"}
|
load_ql_envs
|
||||||
ql_port=${QlPort:-"5700"}
|
|
||||||
command_timeout_time=${CommandTimeoutTime:-""}
|
command_timeout_time=${CommandTimeoutTime:-""}
|
||||||
file_extensions=${RepoFileExtensions:-"js py"}
|
file_extensions=${RepoFileExtensions:-"js py"}
|
||||||
proxy_url=${ProxyUrl:-""}
|
proxy_url=${ProxyUrl:-""}
|
||||||
current_branch=${QL_BRANCH:-""}
|
|
||||||
|
|
||||||
if [[ -n "${DefaultCronRule}" ]]; then
|
if [[ -n "${DefaultCronRule}" ]]; then
|
||||||
default_cron="${DefaultCronRule}"
|
default_cron="${DefaultCronRule}"
|
||||||
@@ -272,14 +272,35 @@ random_range() {
|
|||||||
|
|
||||||
delete_pm2() {
|
delete_pm2() {
|
||||||
cd $dir_root
|
cd $dir_root
|
||||||
pm2 delete ecosystem.config.js
|
# Try to delete PM2 processes, but don't fail if PM2 is not available
|
||||||
|
pm2 delete ecosystem.config.js 2>/dev/null || true
|
||||||
|
# Also try to kill any directly spawned node processes
|
||||||
|
pkill -f "node.*static/build/app.js" 2>/dev/null || true
|
||||||
}
|
}
|
||||||
|
|
||||||
reload_pm2() {
|
reload_pm2() {
|
||||||
cd $dir_root
|
cd $dir_root
|
||||||
restore_env_vars
|
restore_env_vars
|
||||||
pm2 flush &>/dev/null
|
|
||||||
pm2 startOrGracefulReload ecosystem.config.js --update-env
|
# Try to start PM2, but handle failures gracefully
|
||||||
|
if pm2 flush &>/dev/null && pm2 startOrGracefulReload ecosystem.config.js --update-env; then
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
local exit_code=$?
|
||||||
|
echo "警告: PM2 启动失败 (退出码: $exit_code),可能是由于硬件不兼容"
|
||||||
|
echo "正在尝试直接使用 Node.js 启动服务..."
|
||||||
|
|
||||||
|
# Kill any existing node processes for qinglong
|
||||||
|
pkill -f "node.*static/build/app.js" 2>/dev/null || true
|
||||||
|
|
||||||
|
# Start node directly in the background
|
||||||
|
nohup node static/build/app.js > $dir_log/qinglong.log 2>&1 &
|
||||||
|
local node_pid=$!
|
||||||
|
|
||||||
|
echo "已使用 Node.js 直接启动服务 (PID: $node_pid)"
|
||||||
|
echo "注意: 使用此模式时,部分 PM2 管理功能将不可用"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
diff_time() {
|
diff_time() {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
dir_shell=$QL_DIR/shell
|
dir_shell=$QL_DIR/shell
|
||||||
. $dir_shell/share.sh
|
. $dir_shell/share.sh
|
||||||
. $dir_shell/api.sh
|
. $dir_shell/api.sh
|
||||||
|
load_ql_envs
|
||||||
. $dir_shell/env.sh
|
. $dir_shell/env.sh
|
||||||
|
|
||||||
send_mark=$dir_shell/send_mark
|
send_mark=$dir_shell/send_mark
|
||||||
|
|||||||
+16
-11
@@ -1,6 +1,6 @@
|
|||||||
import intl from 'react-intl-universal';
|
import intl from 'react-intl-universal';
|
||||||
import React, { useRef, useState, useEffect } from 'react';
|
import React, { useRef, useState, useEffect } from 'react';
|
||||||
import { Tooltip, Typography } from 'antd';
|
import { Tooltip, Typography, message } from 'antd';
|
||||||
import { CopyOutlined, CheckOutlined } from '@ant-design/icons';
|
import { CopyOutlined, CheckOutlined } from '@ant-design/icons';
|
||||||
import { CopyToClipboard } from 'react-copy-to-clipboard';
|
import { CopyToClipboard } from 'react-copy-to-clipboard';
|
||||||
|
|
||||||
@@ -10,16 +10,21 @@ const Copy = ({ text }: { text: string }) => {
|
|||||||
const [copied, setCopied] = useState(false);
|
const [copied, setCopied] = useState(false);
|
||||||
const copyIdRef = useRef<number>();
|
const copyIdRef = useRef<number>();
|
||||||
|
|
||||||
const copyText = (e?: React.MouseEvent) => {
|
const handleCopy = (text: string, result: boolean) => {
|
||||||
|
if (result) {
|
||||||
|
setCopied(true);
|
||||||
|
message.success(intl.get('复制成功'));
|
||||||
|
|
||||||
|
cleanCopyId();
|
||||||
|
copyIdRef.current = window.setTimeout(() => {
|
||||||
|
setCopied(false);
|
||||||
|
}, 3000);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleClick = (e?: React.MouseEvent) => {
|
||||||
e?.preventDefault();
|
e?.preventDefault();
|
||||||
e?.stopPropagation();
|
e?.stopPropagation();
|
||||||
|
|
||||||
setCopied(true);
|
|
||||||
|
|
||||||
cleanCopyId();
|
|
||||||
copyIdRef.current = window.setTimeout(() => {
|
|
||||||
setCopied(false);
|
|
||||||
}, 3000);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const cleanCopyId = () => {
|
const cleanCopyId = () => {
|
||||||
@@ -27,8 +32,8 @@ const Copy = ({ text }: { text: string }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Link onClick={copyText} style={{ marginLeft: 1 }}>
|
<Link onClick={handleClick} style={{ marginLeft: 4 }}>
|
||||||
<CopyToClipboard text={text}>
|
<CopyToClipboard text={text} onCopy={handleCopy}>
|
||||||
<Tooltip
|
<Tooltip
|
||||||
key="copy"
|
key="copy"
|
||||||
title={copied ? intl.get('复制成功') : intl.get('复制')}
|
title={copied ? intl.get('复制成功') : intl.get('复制')}
|
||||||
|
|||||||
@@ -66,12 +66,6 @@ export default {
|
|||||||
icon: <IconFont type="ql-icon-log" />,
|
icon: <IconFont type="ql-icon-log" />,
|
||||||
component: '@/pages/log/index',
|
component: '@/pages/log/index',
|
||||||
},
|
},
|
||||||
{
|
|
||||||
path: '/scenario',
|
|
||||||
name: intl.get('场景模式'),
|
|
||||||
icon: <IconFont type="ql-icon-script" />,
|
|
||||||
component: '@/pages/scenario/index',
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
path: '/diff',
|
path: '/diff',
|
||||||
name: intl.get('对比工具'),
|
name: intl.get('对比工具'),
|
||||||
|
|||||||
+26
-64
@@ -104,7 +104,7 @@
|
|||||||
"序号": "Number",
|
"序号": "Number",
|
||||||
"备注": "Remarks",
|
"备注": "Remarks",
|
||||||
"更新时间": "Update Time",
|
"更新时间": "Update Time",
|
||||||
"创建时间": "Creation Time",
|
"创建时间": "Created Time",
|
||||||
"确认删除依赖": "Confirm to delete the dependency",
|
"确认删除依赖": "Confirm to delete the dependency",
|
||||||
"确认重新安装": "Confirm to reinstall",
|
"确认重新安装": "Confirm to reinstall",
|
||||||
"确认取消安装": "Confirm to cancel install",
|
"确认取消安装": "Confirm to cancel install",
|
||||||
@@ -252,7 +252,7 @@
|
|||||||
"登录日志": "Login Logs",
|
"登录日志": "Login Logs",
|
||||||
"其他设置": "Other Settings",
|
"其他设置": "Other Settings",
|
||||||
"关于": "About",
|
"关于": "About",
|
||||||
"成功": "Success",
|
"成功": "Successfully",
|
||||||
"失败": "Failure",
|
"失败": "Failure",
|
||||||
"登录时间": "Login Time",
|
"登录时间": "Login Time",
|
||||||
"登录地址": "Login Address",
|
"登录地址": "Login Address",
|
||||||
@@ -389,6 +389,7 @@
|
|||||||
"消息接收人": "message recipient",
|
"消息接收人": "message recipient",
|
||||||
"调用版本;专业版填写pro,个人版填写personal,为空默认使用专业版": "Version, you can specify 'pro' for the Professional version and 'personal' for the Personal version. If left blank, it will default to the Professional version.",
|
"调用版本;专业版填写pro,个人版填写personal,为空默认使用专业版": "Version, you can specify 'pro' for the Professional version and 'personal' for the Personal version. If left blank, it will default to the Professional version.",
|
||||||
"飞书群组机器人:https://www.feishu.cn/hc/zh-CN/articles/360024984973": "Feishu group bot: https://www.feishu.cn/hc/zh-CN/articles/360024984973",
|
"飞书群组机器人:https://www.feishu.cn/hc/zh-CN/articles/360024984973": "Feishu group bot: https://www.feishu.cn/hc/zh-CN/articles/360024984973",
|
||||||
|
"飞书群组机器人加签密钥,安全设置中开启签名校验后获得": "Feishu group bot signature secret, obtained after enabling signature verification in security settings",
|
||||||
"邮箱服务名称,比如126、163、Gmail、QQ等,支持列表https://github.com/nodemailer/nodemailer/blob/master/lib/well-known/services.json": "Email service name, e.g., 126, 163, Gmail, QQ, etc. Supported list: https://github.com/nodemailer/nodemailer/blob/master/lib/well-known/services.json",
|
"邮箱服务名称,比如126、163、Gmail、QQ等,支持列表https://github.com/nodemailer/nodemailer/blob/master/lib/well-known/services.json": "Email service name, e.g., 126, 163, Gmail, QQ, etc. Supported list: https://github.com/nodemailer/nodemailer/blob/master/lib/well-known/services.json",
|
||||||
"邮箱地址": "Email Address",
|
"邮箱地址": "Email Address",
|
||||||
"SMTP 登录密码,也可能为特殊口令,视具体邮件服务商说明而定": "The SMTP login password may also be a special passphrase, depending on the specific email service provider's instructions",
|
"SMTP 登录密码,也可能为特殊口令,视具体邮件服务商说明而定": "The SMTP login password may also be a special passphrase, depending on the specific email service provider's instructions",
|
||||||
@@ -522,67 +523,6 @@
|
|||||||
"SSH 文件缓存": "SSH file cache",
|
"SSH 文件缓存": "SSH file cache",
|
||||||
"清除依赖缓存": "Clean dependency cache",
|
"清除依赖缓存": "Clean dependency cache",
|
||||||
"清除成功": "Clean successful",
|
"清除成功": "Clean successful",
|
||||||
"场景模式": "Scenario Mode",
|
|
||||||
"新建场景": "New Scenario",
|
|
||||||
"编辑场景": "Edit Scenario",
|
|
||||||
"场景日志": "Scenario Logs",
|
|
||||||
"确定要删除场景": "Are you sure to delete scenario",
|
|
||||||
"场景已触发": "Scenario triggered",
|
|
||||||
"使用此 URL 接收外部触发": "Use this URL to receive external triggers",
|
|
||||||
"获取 Webhook URL 失败": "Failed to get Webhook URL",
|
|
||||||
"获取 Webhook": "Get Webhook",
|
|
||||||
"手动触发": "Manual Trigger",
|
|
||||||
"查看日志": "View Logs",
|
|
||||||
"变量监听": "Variable Monitor",
|
|
||||||
"任务状态": "Task Status",
|
|
||||||
"时间触发": "Time Trigger",
|
|
||||||
"系统事件": "System Event",
|
|
||||||
"描述": "Description",
|
|
||||||
"触发类型": "Trigger Type",
|
|
||||||
"执行次数": "Execution Count",
|
|
||||||
"成功/失败": "Success/Failure",
|
|
||||||
"最后触发": "Last Triggered",
|
|
||||||
"监听路径": "Watch Path",
|
|
||||||
"留空自动生成": "Leave blank to auto-generate",
|
|
||||||
"Cron 表达式": "Cron Expression",
|
|
||||||
"事件类型": "Event Type",
|
|
||||||
"磁盘空间": "Disk Space",
|
|
||||||
"内存使用": "Memory Usage",
|
|
||||||
"阈值": "Threshold",
|
|
||||||
"检查间隔": "Check Interval",
|
|
||||||
"任务 ID": "Task ID",
|
|
||||||
"条件配置": "Condition Configuration",
|
|
||||||
"条件逻辑": "Condition Logic",
|
|
||||||
"多个条件之间的关系": "Relationship between multiple conditions",
|
|
||||||
"全部满足": "All satisfied",
|
|
||||||
"任一满足": "Any satisfied",
|
|
||||||
"字段名": "Field Name",
|
|
||||||
"操作符": "Operator",
|
|
||||||
"添加条件": "Add Condition",
|
|
||||||
"动作配置": "Action Configuration",
|
|
||||||
"动作类型": "Action Type",
|
|
||||||
"运行任务": "Run Task",
|
|
||||||
"设置变量": "Set Variable",
|
|
||||||
"执行命令": "Execute Command",
|
|
||||||
"发送通知": "Send Notification",
|
|
||||||
"变量名": "Variable Name",
|
|
||||||
"变量值": "Variable Value",
|
|
||||||
"消息": "Message",
|
|
||||||
"添加动作": "Add Action",
|
|
||||||
"高级设置": "Advanced Settings",
|
|
||||||
"延迟执行": "Delay Execution",
|
|
||||||
"失败熔断阈值": "Failure Threshold",
|
|
||||||
"连续失败多少次后自动禁用": "Auto-disable after N consecutive failures",
|
|
||||||
"最大重试次数": "Max Retry Count",
|
|
||||||
"重试延迟": "Retry Delay",
|
|
||||||
"退避倍数": "Backoff Multiplier",
|
|
||||||
"每次重试延迟的乘数": "Multiplier for retry delay",
|
|
||||||
"时间": "Time",
|
|
||||||
"条件匹配": "Condition Matched",
|
|
||||||
"执行时间": "Execution Time",
|
|
||||||
"重试次数": "Retry Count",
|
|
||||||
"错误信息": "Error Message",
|
|
||||||
"共": "Total",
|
|
||||||
"日志名称": "Log Name",
|
"日志名称": "Log Name",
|
||||||
"自定义日志文件夹名称,用于区分不同任务的日志,留空则自动生成": "Custom log folder name to distinguish logs from different tasks. Leave blank to auto-generate",
|
"自定义日志文件夹名称,用于区分不同任务的日志,留空则自动生成": "Custom log folder name to distinguish logs from different tasks. Leave blank to auto-generate",
|
||||||
"自定义日志文件夹名称,用于区分不同任务的日志,留空则自动生成。支持绝对路径如 /dev/null": "Custom log folder name to distinguish logs from different tasks. Leave blank to auto-generate. Supports absolute paths like /dev/null",
|
"自定义日志文件夹名称,用于区分不同任务的日志,留空则自动生成。支持绝对路径如 /dev/null": "Custom log folder name to distinguish logs from different tasks. Leave blank to auto-generate. Supports absolute paths like /dev/null",
|
||||||
@@ -591,5 +531,27 @@
|
|||||||
"请输入自定义日志文件夹名称或绝对路径": "Please enter a custom log folder name or absolute path",
|
"请输入自定义日志文件夹名称或绝对路径": "Please enter a custom log folder name or absolute path",
|
||||||
"请输入自定义日志文件夹名称或 /dev/null": "Please enter a custom log folder name or /dev/null",
|
"请输入自定义日志文件夹名称或 /dev/null": "Please enter a custom log folder name or /dev/null",
|
||||||
"日志名称只能包含字母、数字、下划线和连字符": "Log name can only contain letters, numbers, underscores and hyphens",
|
"日志名称只能包含字母、数字、下划线和连字符": "Log name can only contain letters, numbers, underscores and hyphens",
|
||||||
"日志名称不能超过100个字符": "Log name cannot exceed 100 characters"
|
"日志名称不能超过100个字符": "Log name cannot exceed 100 characters",
|
||||||
|
"未启用": "Not enabled",
|
||||||
|
"默认为 CPU 个数": "Default is the number of CPUs",
|
||||||
|
"Minimum is 4": "Minimum is 4",
|
||||||
|
"实例模式": "Instance Mode",
|
||||||
|
"单实例模式:定时启动新任务前会自动停止旧任务;多实例模式:允许同时运行多个任务实例": "Single instance mode: automatically stop old task before starting new scheduled task; Multi-instance mode: allow multiple task instances to run simultaneously",
|
||||||
|
"请选择实例模式": "Please select instance mode",
|
||||||
|
"单实例": "Single Instance",
|
||||||
|
"多实例": "Multi-Instance",
|
||||||
|
"SSH密钥": "SSH Keys",
|
||||||
|
"别名": "Alias",
|
||||||
|
"编辑SSH密钥": "Edit SSH Key",
|
||||||
|
"创建SSH密钥": "Create SSH Key",
|
||||||
|
"更新SSH密钥成功": "SSH key updated successfully",
|
||||||
|
"创建SSH密钥成功": "SSH key created successfully",
|
||||||
|
"请输入SSH密钥别名": "Please enter SSH key alias",
|
||||||
|
"请输入SSH私钥": "Please enter SSH private key",
|
||||||
|
"请输入SSH私钥内容(以 -----BEGIN 开头)": "Please enter SSH private key content (starts with -----BEGIN)",
|
||||||
|
"确认删除SSH密钥": "Confirm to delete SSH key",
|
||||||
|
"批量": "Batch",
|
||||||
|
"全局SSH私钥": "Global SSH Private Key",
|
||||||
|
"用于访问所有私有仓库的全局SSH私钥": "Global SSH private key for accessing all private repositories",
|
||||||
|
"请输入完整的SSH私钥内容": "Please enter the complete SSH private key content"
|
||||||
}
|
}
|
||||||
|
|||||||
+24
-62
@@ -389,6 +389,7 @@
|
|||||||
"消息接收人": "消息接收人",
|
"消息接收人": "消息接收人",
|
||||||
"调用版本;专业版填写pro,个人版填写personal,为空默认使用专业版": "调用版本;专业版填写pro,个人版填写personal,为空默认使用专业版",
|
"调用版本;专业版填写pro,个人版填写personal,为空默认使用专业版": "调用版本;专业版填写pro,个人版填写personal,为空默认使用专业版",
|
||||||
"飞书群组机器人:https://www.feishu.cn/hc/zh-CN/articles/360024984973": "飞书群组机器人:https://www.feishu.cn/hc/zh-CN/articles/360024984973",
|
"飞书群组机器人:https://www.feishu.cn/hc/zh-CN/articles/360024984973": "飞书群组机器人:https://www.feishu.cn/hc/zh-CN/articles/360024984973",
|
||||||
|
"飞书群组机器人加签密钥,安全设置中开启签名校验后获得": "飞书群组机器人加签密钥,安全设置中开启签名校验后获得",
|
||||||
"邮箱服务名称,比如126、163、Gmail、QQ等,支持列表https://github.com/nodemailer/nodemailer/blob/master/lib/well-known/services.json": "邮箱服务名称,比如126、163、Gmail、QQ等,支持列表https://github.com/nodemailer/nodemailer/blob/master/lib/well-known/services.json",
|
"邮箱服务名称,比如126、163、Gmail、QQ等,支持列表https://github.com/nodemailer/nodemailer/blob/master/lib/well-known/services.json": "邮箱服务名称,比如126、163、Gmail、QQ等,支持列表https://github.com/nodemailer/nodemailer/blob/master/lib/well-known/services.json",
|
||||||
"邮箱地址": "邮箱地址",
|
"邮箱地址": "邮箱地址",
|
||||||
"SMTP 登录密码,也可能为特殊口令,视具体邮件服务商说明而定": "SMTP 登录密码,也可能为特殊口令,视具体邮件服务商说明而定",
|
"SMTP 登录密码,也可能为特殊口令,视具体邮件服务商说明而定": "SMTP 登录密码,也可能为特殊口令,视具体邮件服务商说明而定",
|
||||||
@@ -522,67 +523,6 @@
|
|||||||
"SSH 文件缓存": "SSH 文件缓存",
|
"SSH 文件缓存": "SSH 文件缓存",
|
||||||
"清除依赖缓存": "清除依赖缓存",
|
"清除依赖缓存": "清除依赖缓存",
|
||||||
"清除成功": "清除成功",
|
"清除成功": "清除成功",
|
||||||
"场景模式": "场景模式",
|
|
||||||
"新建场景": "新建场景",
|
|
||||||
"编辑场景": "编辑场景",
|
|
||||||
"场景日志": "场景日志",
|
|
||||||
"确定要删除场景": "确定要删除场景",
|
|
||||||
"场景已触发": "场景已触发",
|
|
||||||
"使用此 URL 接收外部触发": "使用此 URL 接收外部触发",
|
|
||||||
"获取 Webhook URL 失败": "获取 Webhook URL 失败",
|
|
||||||
"获取 Webhook": "获取 Webhook",
|
|
||||||
"手动触发": "手动触发",
|
|
||||||
"查看日志": "查看日志",
|
|
||||||
"变量监听": "变量监听",
|
|
||||||
"任务状态": "任务状态",
|
|
||||||
"时间触发": "时间触发",
|
|
||||||
"系统事件": "系统事件",
|
|
||||||
"描述": "描述",
|
|
||||||
"触发类型": "触发类型",
|
|
||||||
"执行次数": "执行次数",
|
|
||||||
"成功/失败": "成功/失败",
|
|
||||||
"最后触发": "最后触发",
|
|
||||||
"监听路径": "监听路径",
|
|
||||||
"留空自动生成": "留空自动生成",
|
|
||||||
"Cron 表达式": "Cron 表达式",
|
|
||||||
"事件类型": "事件类型",
|
|
||||||
"磁盘空间": "磁盘空间",
|
|
||||||
"内存使用": "内存使用",
|
|
||||||
"阈值": "阈值",
|
|
||||||
"检查间隔": "检查间隔",
|
|
||||||
"任务 ID": "任务 ID",
|
|
||||||
"条件配置": "条件配置",
|
|
||||||
"条件逻辑": "条件逻辑",
|
|
||||||
"多个条件之间的关系": "多个条件之间的关系",
|
|
||||||
"全部满足": "全部满足",
|
|
||||||
"任一满足": "任一满足",
|
|
||||||
"字段名": "字段名",
|
|
||||||
"操作符": "操作符",
|
|
||||||
"添加条件": "添加条件",
|
|
||||||
"动作配置": "动作配置",
|
|
||||||
"动作类型": "动作类型",
|
|
||||||
"运行任务": "运行任务",
|
|
||||||
"设置变量": "设置变量",
|
|
||||||
"执行命令": "执行命令",
|
|
||||||
"发送通知": "发送通知",
|
|
||||||
"变量名": "变量名",
|
|
||||||
"变量值": "变量值",
|
|
||||||
"消息": "消息",
|
|
||||||
"添加动作": "添加动作",
|
|
||||||
"高级设置": "高级设置",
|
|
||||||
"延迟执行": "延迟执行",
|
|
||||||
"失败熔断阈值": "失败熔断阈值",
|
|
||||||
"连续失败多少次后自动禁用": "连续失败多少次后自动禁用",
|
|
||||||
"最大重试次数": "最大重试次数",
|
|
||||||
"重试延迟": "重试延迟",
|
|
||||||
"退避倍数": "退避倍数",
|
|
||||||
"每次重试延迟的乘数": "每次重试延迟的乘数",
|
|
||||||
"时间": "时间",
|
|
||||||
"条件匹配": "条件匹配",
|
|
||||||
"执行时间": "执行时间",
|
|
||||||
"重试次数": "重试次数",
|
|
||||||
"错误信息": "错误信息",
|
|
||||||
"共": "共",
|
|
||||||
"日志名称": "日志名称",
|
"日志名称": "日志名称",
|
||||||
"自定义日志文件夹名称,用于区分不同任务的日志,留空则自动生成": "自定义日志文件夹名称,用于区分不同任务的日志,留空则自动生成",
|
"自定义日志文件夹名称,用于区分不同任务的日志,留空则自动生成": "自定义日志文件夹名称,用于区分不同任务的日志,留空则自动生成",
|
||||||
"自定义日志文件夹名称,用于区分不同任务的日志,留空则自动生成。支持绝对路径如 /dev/null": "自定义日志文件夹名称,用于区分不同任务的日志,留空则自动生成。支持绝对路径如 /dev/null",
|
"自定义日志文件夹名称,用于区分不同任务的日志,留空则自动生成。支持绝对路径如 /dev/null": "自定义日志文件夹名称,用于区分不同任务的日志,留空则自动生成。支持绝对路径如 /dev/null",
|
||||||
@@ -591,5 +531,27 @@
|
|||||||
"请输入自定义日志文件夹名称或绝对路径": "请输入自定义日志文件夹名称或绝对路径",
|
"请输入自定义日志文件夹名称或绝对路径": "请输入自定义日志文件夹名称或绝对路径",
|
||||||
"请输入自定义日志文件夹名称或 /dev/null": "请输入自定义日志文件夹名称或 /dev/null",
|
"请输入自定义日志文件夹名称或 /dev/null": "请输入自定义日志文件夹名称或 /dev/null",
|
||||||
"日志名称只能包含字母、数字、下划线和连字符": "日志名称只能包含字母、数字、下划线和连字符",
|
"日志名称只能包含字母、数字、下划线和连字符": "日志名称只能包含字母、数字、下划线和连字符",
|
||||||
"日志名称不能超过100个字符": "日志名称不能超过100个字符"
|
"日志名称不能超过100个字符": "日志名称不能超过100个字符",
|
||||||
|
"未启用": "未启用",
|
||||||
|
"默认为 CPU 个数": "默认为 CPU 个数",
|
||||||
|
"最小是 4": "最小是 4",
|
||||||
|
"实例模式": "实例模式",
|
||||||
|
"单实例模式:定时启动新任务前会自动停止旧任务;多实例模式:允许同时运行多个任务实例": "单实例模式:定时启动新任务前会自动停止旧任务;多实例模式:允许同时运行多个任务实例",
|
||||||
|
"请选择实例模式": "请选择实例模式",
|
||||||
|
"单实例": "单实例",
|
||||||
|
"多实例": "多实例",
|
||||||
|
"SSH密钥": "SSH密钥",
|
||||||
|
"别名": "别名",
|
||||||
|
"编辑SSH密钥": "编辑SSH密钥",
|
||||||
|
"创建SSH密钥": "创建SSH密钥",
|
||||||
|
"更新SSH密钥成功": "更新SSH密钥成功",
|
||||||
|
"创建SSH密钥成功": "创建SSH密钥成功",
|
||||||
|
"请输入SSH密钥别名": "请输入SSH密钥别名",
|
||||||
|
"请输入SSH私钥": "请输入SSH私钥",
|
||||||
|
"请输入SSH私钥内容(以 -----BEGIN 开头)": "请输入SSH私钥内容(以 -----BEGIN 开头)",
|
||||||
|
"确认删除SSH密钥": "确认删除SSH密钥",
|
||||||
|
"批量": "批量",
|
||||||
|
"全局SSH私钥": "全局SSH私钥",
|
||||||
|
"用于访问所有私有仓库的全局SSH私钥": "用于访问所有私有仓库的全局SSH私钥",
|
||||||
|
"请输入完整的SSH私钥内容": "请输入完整的SSH私钥内容"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import config from '@/utils/config';
|
|||||||
import { request } from '@/utils/http';
|
import { request } from '@/utils/http';
|
||||||
import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons';
|
import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons';
|
||||||
import { Button, Form, Input, Modal, Select, Space, message } from 'antd';
|
import { Button, Form, Input, Modal, Select, Space, message } from 'antd';
|
||||||
import cronParse from 'cron-parser';
|
import { CronExpressionParser } from 'cron-parser';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import intl from 'react-intl-universal';
|
import intl from 'react-intl-universal';
|
||||||
import { getScheduleType, scheduleTypeMap } from './const';
|
import { getScheduleType, scheduleTypeMap } from './const';
|
||||||
@@ -91,7 +91,7 @@ const CronModal = ({
|
|||||||
{ required: true },
|
{ required: true },
|
||||||
{
|
{
|
||||||
validator: (_, value) => {
|
validator: (_, value) => {
|
||||||
if (!value || cronParse.parseExpression(value).hasNext()) {
|
if (!value || CronExpressionParser.parse(value).hasNext()) {
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
return Promise.reject(intl.get('Cron表达式格式有误'));
|
return Promise.reject(intl.get('Cron表达式格式有误'));
|
||||||
@@ -180,6 +180,18 @@ const CronModal = ({
|
|||||||
<Form.Item name="labels" label={intl.get('标签')}>
|
<Form.Item name="labels" label={intl.get('标签')}>
|
||||||
<EditableTagGroup />
|
<EditableTagGroup />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="allow_multiple_instances"
|
||||||
|
label={intl.get('实例模式')}
|
||||||
|
tooltip={intl.get(
|
||||||
|
'单实例模式:定时启动新任务前会自动停止旧任务;多实例模式:允许同时运行多个任务实例',
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<Select placeholder={intl.get('请选择实例模式')}>
|
||||||
|
<Select.Option value={0}>{intl.get('单实例')}</Select.Option>
|
||||||
|
<Select.Option value={1}>{intl.get('多实例')}</Select.Option>
|
||||||
|
</Select>
|
||||||
|
</Form.Item>
|
||||||
<Form.Item
|
<Form.Item
|
||||||
name="log_name"
|
name="log_name"
|
||||||
label={intl.get('日志名称')}
|
label={intl.get('日志名称')}
|
||||||
@@ -194,7 +206,11 @@ const CronModal = ({
|
|||||||
if (value.length > 100) {
|
if (value.length > 100) {
|
||||||
return Promise.reject(intl.get('日志名称不能超过100个字符'));
|
return Promise.reject(intl.get('日志名称不能超过100个字符'));
|
||||||
}
|
}
|
||||||
if (!/^(?!.*(?:^|\/)\.{1,2}(?:\/|$))(?:\/)?(?:[\w.-]+\/)*[\w.-]+\/?$/.test(value)) {
|
if (
|
||||||
|
!/^(?!.*(?:^|\/)\.{1,2}(?:\/|$))(?:\/)?(?:[\w.-]+\/)*[\w.-]+\/?$/.test(
|
||||||
|
value,
|
||||||
|
)
|
||||||
|
) {
|
||||||
return Promise.reject(
|
return Promise.reject(
|
||||||
intl.get('日志名称只能包含字母、数字、下划线和连字符'),
|
intl.get('日志名称只能包含字母、数字、下划线和连字符'),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ export interface ICrontab {
|
|||||||
nextRunTime: Date;
|
nextRunTime: Date;
|
||||||
sub_id: number;
|
sub_id: number;
|
||||||
extra_schedules?: Array<{ schedule: string }>;
|
extra_schedules?: Array<{ schedule: string }>;
|
||||||
|
allow_multiple_instances?: 1 | 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum ScheduleType {
|
export enum ScheduleType {
|
||||||
|
|||||||
@@ -1,478 +0,0 @@
|
|||||||
import React, { useRef, useState, useCallback, useEffect } from 'react';
|
|
||||||
import { Button, Space, message, Drawer, Form, Input, Select, InputNumber } from 'antd';
|
|
||||||
import {
|
|
||||||
PlusOutlined,
|
|
||||||
PlayCircleOutlined,
|
|
||||||
SaveOutlined,
|
|
||||||
DeleteOutlined,
|
|
||||||
} from '@ant-design/icons';
|
|
||||||
import { FreeLayoutEditor } from '@flowgram.ai/free-layout-editor';
|
|
||||||
import { nanoid } from 'nanoid';
|
|
||||||
import type { FlowgramGraph, FlowgramNode, FlowgramEdge } from './types';
|
|
||||||
import { nodeTemplates } from './nodes';
|
|
||||||
import { flowgramToBackend, backendToFlowgram, validateWorkflow, createEdge } from './utils/dataConverter';
|
|
||||||
import './editor.css';
|
|
||||||
|
|
||||||
const { Option } = Select;
|
|
||||||
|
|
||||||
interface FlowgramEditorProps {
|
|
||||||
value?: FlowgramGraph;
|
|
||||||
onChange?: (graph: FlowgramGraph) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const FlowgramEditor: React.FC<FlowgramEditorProps> = ({ value, onChange }) => {
|
|
||||||
const editorRef = useRef<any>(null);
|
|
||||||
const [graph, setGraph] = useState<FlowgramGraph>(value || { nodes: [], edges: [] });
|
|
||||||
const [selectedNode, setSelectedNode] = useState<FlowgramNode | null>(null);
|
|
||||||
const [drawerVisible, setDrawerVisible] = useState(false);
|
|
||||||
const [draggedNode, setDraggedNode] = useState<FlowgramNode | null>(null);
|
|
||||||
const [form] = Form.useForm();
|
|
||||||
|
|
||||||
// Initialize editor
|
|
||||||
useEffect(() => {
|
|
||||||
if (value) {
|
|
||||||
setGraph(backendToFlowgram(value));
|
|
||||||
}
|
|
||||||
}, [value]);
|
|
||||||
|
|
||||||
// Notify parent of changes
|
|
||||||
const notifyChange = useCallback((newGraph: FlowgramGraph) => {
|
|
||||||
setGraph(newGraph);
|
|
||||||
if (onChange) {
|
|
||||||
onChange(flowgramToBackend(newGraph));
|
|
||||||
}
|
|
||||||
}, [onChange]);
|
|
||||||
|
|
||||||
// Add node to canvas
|
|
||||||
const addNode = useCallback((templateKey: string) => {
|
|
||||||
const template = nodeTemplates[templateKey as keyof typeof nodeTemplates];
|
|
||||||
if (!template) {
|
|
||||||
message.error('未知的节点类型');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const newNode = template();
|
|
||||||
// Position new node in center with some randomness
|
|
||||||
newNode.position = {
|
|
||||||
x: 200 + Math.random() * 300,
|
|
||||||
y: 100 + Math.random() * 200,
|
|
||||||
};
|
|
||||||
|
|
||||||
const newGraph = {
|
|
||||||
...graph,
|
|
||||||
nodes: [...graph.nodes, newNode],
|
|
||||||
};
|
|
||||||
|
|
||||||
notifyChange(newGraph);
|
|
||||||
message.success('节点已添加');
|
|
||||||
}, [graph, notifyChange]);
|
|
||||||
|
|
||||||
// Handle node click/double-click to open config
|
|
||||||
const handleNodeClick = useCallback((node: FlowgramNode) => {
|
|
||||||
setSelectedNode(node);
|
|
||||||
form.setFieldsValue(node.data);
|
|
||||||
setDrawerVisible(true);
|
|
||||||
}, [form]);
|
|
||||||
|
|
||||||
// Save node configuration
|
|
||||||
const handleSaveNodeConfig = useCallback(() => {
|
|
||||||
if (!selectedNode) return;
|
|
||||||
|
|
||||||
form.validateFields().then((values) => {
|
|
||||||
const updatedNodes = graph.nodes.map((node) =>
|
|
||||||
node.id === selectedNode.id
|
|
||||||
? { ...node, data: { ...node.data, ...values } }
|
|
||||||
: node
|
|
||||||
);
|
|
||||||
|
|
||||||
const newGraph = {
|
|
||||||
...graph,
|
|
||||||
nodes: updatedNodes,
|
|
||||||
};
|
|
||||||
|
|
||||||
notifyChange(newGraph);
|
|
||||||
setDrawerVisible(false);
|
|
||||||
message.success('节点配置已保存');
|
|
||||||
});
|
|
||||||
}, [selectedNode, form, graph, notifyChange]);
|
|
||||||
|
|
||||||
// Delete selected node
|
|
||||||
const handleDeleteNode = useCallback(() => {
|
|
||||||
if (!selectedNode) return;
|
|
||||||
|
|
||||||
const newGraph = {
|
|
||||||
nodes: graph.nodes.filter((n) => n.id !== selectedNode.id),
|
|
||||||
edges: graph.edges.filter((e) => e.source !== selectedNode.id && e.target !== selectedNode.id),
|
|
||||||
};
|
|
||||||
|
|
||||||
notifyChange(newGraph);
|
|
||||||
setDrawerVisible(false);
|
|
||||||
message.success('节点已删除');
|
|
||||||
}, [selectedNode, graph, notifyChange]);
|
|
||||||
|
|
||||||
// Connect two nodes
|
|
||||||
const handleConnect = useCallback((connection: { source: string; target: string }) => {
|
|
||||||
const edge = createEdge(connection.source, connection.target);
|
|
||||||
const newGraph = {
|
|
||||||
...graph,
|
|
||||||
edges: [...graph.edges, edge],
|
|
||||||
};
|
|
||||||
|
|
||||||
notifyChange(newGraph);
|
|
||||||
}, [graph, notifyChange]);
|
|
||||||
|
|
||||||
// Handle node drag start
|
|
||||||
const handleDragStart = useCallback((e: React.DragEvent, node: FlowgramNode) => {
|
|
||||||
setDraggedNode(node);
|
|
||||||
e.dataTransfer.effectAllowed = 'move';
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
// Handle node drag over
|
|
||||||
const handleDragOver = useCallback((e: React.DragEvent) => {
|
|
||||||
e.preventDefault();
|
|
||||||
e.dataTransfer.dropEffect = 'move';
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
// Handle node drop
|
|
||||||
const handleDrop = useCallback((e: React.DragEvent, targetNode: FlowgramNode) => {
|
|
||||||
e.preventDefault();
|
|
||||||
if (!draggedNode || draggedNode.id === targetNode.id) return;
|
|
||||||
|
|
||||||
// Reorder nodes
|
|
||||||
const draggedIndex = graph.nodes.findIndex(n => n.id === draggedNode.id);
|
|
||||||
const targetIndex = graph.nodes.findIndex(n => n.id === targetNode.id);
|
|
||||||
|
|
||||||
if (draggedIndex === -1 || targetIndex === -1) return;
|
|
||||||
|
|
||||||
const newNodes = [...graph.nodes];
|
|
||||||
const [removed] = newNodes.splice(draggedIndex, 1);
|
|
||||||
newNodes.splice(targetIndex, 0, removed);
|
|
||||||
|
|
||||||
const newGraph = {
|
|
||||||
...graph,
|
|
||||||
nodes: newNodes,
|
|
||||||
};
|
|
||||||
|
|
||||||
notifyChange(newGraph);
|
|
||||||
setDraggedNode(null);
|
|
||||||
}, [draggedNode, graph, notifyChange]);
|
|
||||||
|
|
||||||
// Validate workflow
|
|
||||||
const handleValidate = useCallback(() => {
|
|
||||||
const validation = validateWorkflow(graph);
|
|
||||||
if (validation.valid) {
|
|
||||||
message.success('工作流验证通过!');
|
|
||||||
} else {
|
|
||||||
message.error(`验证失败: ${validation.errors.join(', ')}`);
|
|
||||||
}
|
|
||||||
}, [graph]);
|
|
||||||
|
|
||||||
// Render node configuration form based on node type
|
|
||||||
const renderNodeConfigForm = () => {
|
|
||||||
if (!selectedNode) return null;
|
|
||||||
|
|
||||||
const { type, data } = selectedNode;
|
|
||||||
|
|
||||||
switch (type) {
|
|
||||||
case 'trigger':
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<Form.Item name="label" label="标签" rules={[{ required: true }]}>
|
|
||||||
<Input />
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item name="triggerType" label="触发类型" rules={[{ required: true }]}>
|
|
||||||
<Select>
|
|
||||||
<Option value="time">时间触发</Option>
|
|
||||||
<Option value="webhook">Webhook</Option>
|
|
||||||
<Option value="variable_monitor">变量监听</Option>
|
|
||||||
<Option value="task_status">任务状态</Option>
|
|
||||||
<Option value="system_event">系统事件</Option>
|
|
||||||
</Select>
|
|
||||||
</Form.Item>
|
|
||||||
{data.triggerType === 'time' && (
|
|
||||||
<Form.Item name={['config', 'schedule']} label="Cron表达式">
|
|
||||||
<Input placeholder="0 0 * * *" />
|
|
||||||
</Form.Item>
|
|
||||||
)}
|
|
||||||
{data.triggerType === 'variable_monitor' && (
|
|
||||||
<Form.Item name={['config', 'watchPath']} label="监听路径">
|
|
||||||
<Input placeholder="/path/to/watch" />
|
|
||||||
</Form.Item>
|
|
||||||
)}
|
|
||||||
{data.triggerType === 'system_event' && (
|
|
||||||
<>
|
|
||||||
<Form.Item name={['config', 'eventType']} label="事件类型">
|
|
||||||
<Select>
|
|
||||||
<Option value="disk">磁盘使用</Option>
|
|
||||||
<Option value="memory">内存使用</Option>
|
|
||||||
</Select>
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item name={['config', 'threshold']} label="阈值 (%)">
|
|
||||||
<InputNumber min={0} max={100} />
|
|
||||||
</Form.Item>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
|
|
||||||
case 'condition':
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<Form.Item name="label" label="标签" rules={[{ required: true }]}>
|
|
||||||
<Input />
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item name="field" label="字段" rules={[{ required: true }]}>
|
|
||||||
<Input placeholder="data.field" />
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item name="operator" label="操作符" rules={[{ required: true }]}>
|
|
||||||
<Select>
|
|
||||||
<Option value="equals">等于</Option>
|
|
||||||
<Option value="not_equals">不等于</Option>
|
|
||||||
<Option value="greater_than">大于</Option>
|
|
||||||
<Option value="less_than">小于</Option>
|
|
||||||
<Option value="contains">包含</Option>
|
|
||||||
<Option value="not_contains">不包含</Option>
|
|
||||||
</Select>
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item name="value" label="值" rules={[{ required: true }]}>
|
|
||||||
<Input />
|
|
||||||
</Form.Item>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
|
|
||||||
case 'action':
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<Form.Item name="label" label="标签" rules={[{ required: true }]}>
|
|
||||||
<Input />
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item name="actionType" label="动作类型" rules={[{ required: true }]}>
|
|
||||||
<Select>
|
|
||||||
<Option value="run_task">运行任务</Option>
|
|
||||||
<Option value="set_variable">设置变量</Option>
|
|
||||||
<Option value="execute_command">执行命令</Option>
|
|
||||||
<Option value="send_notification">发送通知</Option>
|
|
||||||
</Select>
|
|
||||||
</Form.Item>
|
|
||||||
{data.actionType === 'run_task' && (
|
|
||||||
<Form.Item name="cronId" label="任务ID" rules={[{ required: true }]}>
|
|
||||||
<InputNumber min={1} />
|
|
||||||
</Form.Item>
|
|
||||||
)}
|
|
||||||
{data.actionType === 'set_variable' && (
|
|
||||||
<>
|
|
||||||
<Form.Item name="name" label="变量名" rules={[{ required: true }]}>
|
|
||||||
<Input />
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item name="value" label="变量值" rules={[{ required: true }]}>
|
|
||||||
<Input />
|
|
||||||
</Form.Item>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
{data.actionType === 'execute_command' && (
|
|
||||||
<Form.Item name="command" label="命令" rules={[{ required: true }]}>
|
|
||||||
<Input.TextArea rows={3} />
|
|
||||||
</Form.Item>
|
|
||||||
)}
|
|
||||||
{data.actionType === 'send_notification' && (
|
|
||||||
<Form.Item name="message" label="消息" rules={[{ required: true }]}>
|
|
||||||
<Input.TextArea rows={3} />
|
|
||||||
</Form.Item>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
|
|
||||||
case 'control':
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<Form.Item name="label" label="标签" rules={[{ required: true }]}>
|
|
||||||
<Input />
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item name="controlType" label="控制类型" rules={[{ required: true }]}>
|
|
||||||
<Select>
|
|
||||||
<Option value="delay">延迟</Option>
|
|
||||||
<Option value="retry">重试</Option>
|
|
||||||
<Option value="circuit_breaker">熔断器</Option>
|
|
||||||
</Select>
|
|
||||||
</Form.Item>
|
|
||||||
{data.controlType === 'delay' && (
|
|
||||||
<Form.Item name="delaySeconds" label="延迟时间(秒)" rules={[{ required: true }]}>
|
|
||||||
<InputNumber min={1} />
|
|
||||||
</Form.Item>
|
|
||||||
)}
|
|
||||||
{data.controlType === 'retry' && (
|
|
||||||
<>
|
|
||||||
<Form.Item name="maxRetries" label="最大重试次数">
|
|
||||||
<InputNumber min={1} />
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item name="retryDelay" label="重试延迟(秒)">
|
|
||||||
<InputNumber min={1} />
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item name="backoffMultiplier" label="退避倍数">
|
|
||||||
<InputNumber min={1} step={0.1} />
|
|
||||||
</Form.Item>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
{data.controlType === 'circuit_breaker' && (
|
|
||||||
<Form.Item name="failureThreshold" label="失败阈值">
|
|
||||||
<InputNumber min={1} />
|
|
||||||
</Form.Item>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
|
|
||||||
case 'logic_gate':
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<Form.Item name="label" label="标签" rules={[{ required: true }]}>
|
|
||||||
<Input />
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item name="gateType" label="逻辑类型" rules={[{ required: true }]}>
|
|
||||||
<Select>
|
|
||||||
<Option value="AND">AND (与)</Option>
|
|
||||||
<Option value="OR">OR (或)</Option>
|
|
||||||
</Select>
|
|
||||||
</Form.Item>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
|
|
||||||
default:
|
|
||||||
return (
|
|
||||||
<Form.Item name="label" label="标签" rules={[{ required: true }]}>
|
|
||||||
<Input />
|
|
||||||
</Form.Item>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Simple render for now - full Flowgram integration would go here
|
|
||||||
return (
|
|
||||||
<div className="flowgram-editor-container">
|
|
||||||
{/* Toolbar */}
|
|
||||||
<div className="flowgram-toolbar">
|
|
||||||
<Space wrap>
|
|
||||||
<Button icon={<PlusOutlined />} onClick={() => addNode('start')}>开始</Button>
|
|
||||||
<Select
|
|
||||||
placeholder="添加触发器"
|
|
||||||
style={{ width: 120 }}
|
|
||||||
onSelect={(value) => addNode(value)}
|
|
||||||
value={undefined}
|
|
||||||
>
|
|
||||||
<Option value="trigger-time">时间触发</Option>
|
|
||||||
<Option value="trigger-webhook">Webhook</Option>
|
|
||||||
<Option value="trigger-variable">变量监听</Option>
|
|
||||||
<Option value="trigger-task">任务状态</Option>
|
|
||||||
<Option value="trigger-system">系统事件</Option>
|
|
||||||
</Select>
|
|
||||||
<Button onClick={() => addNode('condition')}>条件</Button>
|
|
||||||
<Select
|
|
||||||
placeholder="添加动作"
|
|
||||||
style={{ width: 120 }}
|
|
||||||
onSelect={(value) => addNode(value)}
|
|
||||||
value={undefined}
|
|
||||||
>
|
|
||||||
<Option value="action-run">运行任务</Option>
|
|
||||||
<Option value="action-variable">设置变量</Option>
|
|
||||||
<Option value="action-command">执行命令</Option>
|
|
||||||
<Option value="action-notify">发送通知</Option>
|
|
||||||
</Select>
|
|
||||||
<Select
|
|
||||||
placeholder="添加控制流"
|
|
||||||
style={{ width: 120 }}
|
|
||||||
onSelect={(value) => addNode(value)}
|
|
||||||
value={undefined}
|
|
||||||
>
|
|
||||||
<Option value="control-delay">延迟</Option>
|
|
||||||
<Option value="control-retry">重试</Option>
|
|
||||||
<Option value="control-breaker">熔断器</Option>
|
|
||||||
</Select>
|
|
||||||
<Select
|
|
||||||
placeholder="添加逻辑门"
|
|
||||||
style={{ width: 120 }}
|
|
||||||
onSelect={(value) => addNode(value)}
|
|
||||||
value={undefined}
|
|
||||||
>
|
|
||||||
<Option value="gate-and">AND</Option>
|
|
||||||
<Option value="gate-or">OR</Option>
|
|
||||||
</Select>
|
|
||||||
<Button onClick={() => addNode('end')}>结束</Button>
|
|
||||||
<Button icon={<PlayCircleOutlined />} onClick={handleValidate}>验证</Button>
|
|
||||||
</Space>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Canvas area - simplified view showing nodes */}
|
|
||||||
<div className="flowgram-canvas">
|
|
||||||
<div style={{ padding: '20px' }}>
|
|
||||||
<h3>工作流节点 ({graph.nodes.length})</h3>
|
|
||||||
<Space direction="vertical" style={{ width: '100%' }} className="flowgram-node-list">
|
|
||||||
{graph.nodes.map((node) => (
|
|
||||||
<div
|
|
||||||
key={node.id}
|
|
||||||
className={`flowgram-node-card ${draggedNode?.id === node.id ? 'flowgram-node-card-dragging' : ''}`}
|
|
||||||
onClick={() => handleNodeClick(node)}
|
|
||||||
draggable
|
|
||||||
onDragStart={(e) => handleDragStart(e, node)}
|
|
||||||
onDragOver={handleDragOver}
|
|
||||||
onDrop={(e) => handleDrop(e, node)}
|
|
||||||
style={{
|
|
||||||
background: draggedNode?.id === node.id ? '#f0f0f0' : '#fff',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div><strong>{node.data.label}</strong></div>
|
|
||||||
<div style={{ fontSize: '12px', color: '#999' }}>
|
|
||||||
类型: {node.type} | ID: {node.id}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</Space>
|
|
||||||
|
|
||||||
{graph.edges.length > 0 && (
|
|
||||||
<>
|
|
||||||
<h3 style={{ marginTop: '20px' }}>连接 ({graph.edges.length})</h3>
|
|
||||||
<Space direction="vertical" style={{ width: '100%' }}>
|
|
||||||
{graph.edges.map((edge) => (
|
|
||||||
<div
|
|
||||||
key={edge.id}
|
|
||||||
style={{
|
|
||||||
padding: '8px',
|
|
||||||
border: '1px solid #f0f0f0',
|
|
||||||
borderRadius: '4px',
|
|
||||||
fontSize: '12px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{edge.source} → {edge.target}
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</Space>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Node configuration drawer */}
|
|
||||||
<Drawer
|
|
||||||
title="节点配置"
|
|
||||||
placement="right"
|
|
||||||
width={400}
|
|
||||||
onClose={() => setDrawerVisible(false)}
|
|
||||||
open={drawerVisible}
|
|
||||||
extra={
|
|
||||||
<Space>
|
|
||||||
<Button danger icon={<DeleteOutlined />} onClick={handleDeleteNode}>
|
|
||||||
删除
|
|
||||||
</Button>
|
|
||||||
<Button type="primary" icon={<SaveOutlined />} onClick={handleSaveNodeConfig}>
|
|
||||||
保存
|
|
||||||
</Button>
|
|
||||||
</Space>
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<Form form={form} layout="vertical">
|
|
||||||
{renderNodeConfigForm()}
|
|
||||||
</Form>
|
|
||||||
</Drawer>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default FlowgramEditor;
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
.flowgram-editor-container {
|
|
||||||
border: 1px solid #d9d9d9;
|
|
||||||
border-radius: 4px;
|
|
||||||
padding: 16px;
|
|
||||||
min-height: 600px;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
}
|
|
||||||
|
|
||||||
.flowgram-editor-toolbar {
|
|
||||||
margin-bottom: 16px;
|
|
||||||
display: flex;
|
|
||||||
gap: 8px;
|
|
||||||
flex-wrap: wrap;
|
|
||||||
flex-shrink: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.flowgram-editor-canvas {
|
|
||||||
flex: 1;
|
|
||||||
min-height: 500px;
|
|
||||||
border: 1px dashed #d9d9d9;
|
|
||||||
border-radius: 4px;
|
|
||||||
padding: 16px;
|
|
||||||
background: #fafafa;
|
|
||||||
overflow-y: auto;
|
|
||||||
max-height: calc(80vh - 300px);
|
|
||||||
}
|
|
||||||
|
|
||||||
.flowgram-node-card {
|
|
||||||
padding: 12px;
|
|
||||||
background: white;
|
|
||||||
border: 1px solid #d9d9d9;
|
|
||||||
border-radius: 4px;
|
|
||||||
margin-bottom: 8px;
|
|
||||||
cursor: move;
|
|
||||||
user-select: none;
|
|
||||||
position: relative;
|
|
||||||
}
|
|
||||||
|
|
||||||
.flowgram-node-card:hover {
|
|
||||||
border-color: #40a9ff;
|
|
||||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
|
||||||
}
|
|
||||||
|
|
||||||
.flowgram-node-card-dragging {
|
|
||||||
opacity: 0.5;
|
|
||||||
cursor: grabbing;
|
|
||||||
}
|
|
||||||
|
|
||||||
.flowgram-node-list {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
gap: 8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.flowgram-toolbar {
|
|
||||||
padding: 12px;
|
|
||||||
background: #fff;
|
|
||||||
border-bottom: 1px solid #d9d9d9;
|
|
||||||
z-index: 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
.flowgram-canvas {
|
|
||||||
flex: 1;
|
|
||||||
overflow: auto;
|
|
||||||
background: #f5f5f5;
|
|
||||||
position: relative;
|
|
||||||
}
|
|
||||||
|
|
||||||
.node-card {
|
|
||||||
transition: all 0.3s;
|
|
||||||
}
|
|
||||||
|
|
||||||
.node-card:hover {
|
|
||||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
|
|
||||||
transform: translateY(-2px);
|
|
||||||
}
|
|
||||||
@@ -1,153 +0,0 @@
|
|||||||
// Flowgram Node Registry
|
|
||||||
import { nanoid } from 'nanoid';
|
|
||||||
import type {
|
|
||||||
StartNodeData,
|
|
||||||
TriggerNodeData,
|
|
||||||
ConditionNodeData,
|
|
||||||
ActionNodeData,
|
|
||||||
ControlNodeData,
|
|
||||||
LogicGateNodeData,
|
|
||||||
EndNodeData,
|
|
||||||
FlowgramNode
|
|
||||||
} from '../types';
|
|
||||||
|
|
||||||
// Node creation helpers
|
|
||||||
export function createStartNode(x: number = 100, y: number = 100): FlowgramNode {
|
|
||||||
return {
|
|
||||||
id: `start-${nanoid(8)}`,
|
|
||||||
type: 'start',
|
|
||||||
position: { x, y },
|
|
||||||
data: {
|
|
||||||
label: '开始',
|
|
||||||
} as StartNodeData,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function createTriggerNode(triggerType: string, x: number = 200, y: number = 100): FlowgramNode {
|
|
||||||
const labels: Record<string, string> = {
|
|
||||||
time: '时间触发',
|
|
||||||
webhook: 'Webhook触发',
|
|
||||||
variable_monitor: '变量监听',
|
|
||||||
task_status: '任务状态',
|
|
||||||
system_event: '系统事件',
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
|
||||||
id: `trigger-${nanoid(8)}`,
|
|
||||||
type: 'trigger',
|
|
||||||
position: { x, y },
|
|
||||||
data: {
|
|
||||||
label: labels[triggerType] || '触发器',
|
|
||||||
triggerType,
|
|
||||||
config: {},
|
|
||||||
} as TriggerNodeData,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function createConditionNode(x: number = 300, y: number = 100): FlowgramNode {
|
|
||||||
return {
|
|
||||||
id: `condition-${nanoid(8)}`,
|
|
||||||
type: 'condition',
|
|
||||||
position: { x, y },
|
|
||||||
data: {
|
|
||||||
label: '条件判断',
|
|
||||||
operator: 'equals',
|
|
||||||
field: '',
|
|
||||||
value: '',
|
|
||||||
} as ConditionNodeData,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function createActionNode(actionType: string, x: number = 400, y: number = 100): FlowgramNode {
|
|
||||||
const labels: Record<string, string> = {
|
|
||||||
run_task: '运行任务',
|
|
||||||
set_variable: '设置变量',
|
|
||||||
execute_command: '执行命令',
|
|
||||||
send_notification: '发送通知',
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
|
||||||
id: `action-${nanoid(8)}`,
|
|
||||||
type: 'action',
|
|
||||||
position: { x, y },
|
|
||||||
data: {
|
|
||||||
label: labels[actionType] || '动作',
|
|
||||||
actionType,
|
|
||||||
} as ActionNodeData,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function createControlNode(controlType: string, x: number = 500, y: number = 100): FlowgramNode {
|
|
||||||
const labels: Record<string, string> = {
|
|
||||||
delay: '延迟执行',
|
|
||||||
retry: '重试策略',
|
|
||||||
circuit_breaker: '熔断器',
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
|
||||||
id: `control-${nanoid(8)}`,
|
|
||||||
type: 'control',
|
|
||||||
position: { x, y },
|
|
||||||
data: {
|
|
||||||
label: labels[controlType] || '控制流',
|
|
||||||
controlType,
|
|
||||||
} as ControlNodeData,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function createLogicGateNode(gateType: 'AND' | 'OR', x: number = 300, y: number = 200): FlowgramNode {
|
|
||||||
return {
|
|
||||||
id: `gate-${nanoid(8)}`,
|
|
||||||
type: 'logic_gate',
|
|
||||||
position: { x, y },
|
|
||||||
data: {
|
|
||||||
label: gateType === 'AND' ? '逻辑与' : '逻辑或',
|
|
||||||
gateType,
|
|
||||||
} as LogicGateNodeData,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function createEndNode(x: number = 600, y: number = 100): FlowgramNode {
|
|
||||||
return {
|
|
||||||
id: `end-${nanoid(8)}`,
|
|
||||||
type: 'end',
|
|
||||||
position: { x, y },
|
|
||||||
data: {
|
|
||||||
label: '结束',
|
|
||||||
} as EndNodeData,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Node templates for quick creation
|
|
||||||
export const nodeTemplates = {
|
|
||||||
start: () => createStartNode(),
|
|
||||||
|
|
||||||
// Trigger templates
|
|
||||||
'trigger-time': () => createTriggerNode('time'),
|
|
||||||
'trigger-webhook': () => createTriggerNode('webhook'),
|
|
||||||
'trigger-variable': () => createTriggerNode('variable_monitor'),
|
|
||||||
'trigger-task': () => createTriggerNode('task_status'),
|
|
||||||
'trigger-system': () => createTriggerNode('system_event'),
|
|
||||||
|
|
||||||
// Condition template
|
|
||||||
condition: () => createConditionNode(),
|
|
||||||
|
|
||||||
// Action templates
|
|
||||||
'action-run': () => createActionNode('run_task'),
|
|
||||||
'action-variable': () => createActionNode('set_variable'),
|
|
||||||
'action-command': () => createActionNode('execute_command'),
|
|
||||||
'action-notify': () => createActionNode('send_notification'),
|
|
||||||
|
|
||||||
// Control templates
|
|
||||||
'control-delay': () => createControlNode('delay'),
|
|
||||||
'control-retry': () => createControlNode('retry'),
|
|
||||||
'control-breaker': () => createControlNode('circuit_breaker'),
|
|
||||||
|
|
||||||
// Logic gate templates
|
|
||||||
'gate-and': () => createLogicGateNode('AND'),
|
|
||||||
'gate-or': () => createLogicGateNode('OR'),
|
|
||||||
|
|
||||||
end: () => createEndNode(),
|
|
||||||
};
|
|
||||||
|
|
||||||
export type NodeTemplate = keyof typeof nodeTemplates;
|
|
||||||
@@ -1,76 +0,0 @@
|
|||||||
// Flowgram Types for Qinglong Scenario Mode
|
|
||||||
|
|
||||||
export interface FlowgramNodeData {
|
|
||||||
label: string;
|
|
||||||
[key: string]: any;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface FlowgramNode {
|
|
||||||
id: string;
|
|
||||||
type: string;
|
|
||||||
position: { x: number; y: number };
|
|
||||||
data: FlowgramNodeData;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface FlowgramEdge {
|
|
||||||
id: string;
|
|
||||||
source: string;
|
|
||||||
target: string;
|
|
||||||
[key: string]: any;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface FlowgramGraph {
|
|
||||||
nodes: FlowgramNode[];
|
|
||||||
edges: FlowgramEdge[];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Node type definitions
|
|
||||||
export type NodeType = 'start' | 'trigger' | 'condition' | 'action' | 'control' | 'logic_gate' | 'end';
|
|
||||||
|
|
||||||
export type TriggerType = 'time' | 'webhook' | 'variable_monitor' | 'task_status' | 'system_event';
|
|
||||||
export type ConditionOperator = 'equals' | 'not_equals' | 'greater_than' | 'less_than' | 'contains' | 'not_contains';
|
|
||||||
export type ActionType = 'run_task' | 'set_variable' | 'execute_command' | 'send_notification';
|
|
||||||
export type ControlType = 'delay' | 'retry' | 'circuit_breaker';
|
|
||||||
export type LogicGateType = 'AND' | 'OR';
|
|
||||||
|
|
||||||
// Node data interfaces
|
|
||||||
export interface StartNodeData extends FlowgramNodeData {
|
|
||||||
label: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface TriggerNodeData extends FlowgramNodeData {
|
|
||||||
triggerType: TriggerType;
|
|
||||||
config?: any;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ConditionNodeData extends FlowgramNodeData {
|
|
||||||
operator: ConditionOperator;
|
|
||||||
field: string;
|
|
||||||
value: any;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ActionNodeData extends FlowgramNodeData {
|
|
||||||
actionType: ActionType;
|
|
||||||
cronId?: number;
|
|
||||||
name?: string;
|
|
||||||
value?: string;
|
|
||||||
command?: string;
|
|
||||||
message?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ControlNodeData extends FlowgramNodeData {
|
|
||||||
controlType: ControlType;
|
|
||||||
delaySeconds?: number;
|
|
||||||
maxRetries?: number;
|
|
||||||
retryDelay?: number;
|
|
||||||
backoffMultiplier?: number;
|
|
||||||
failureThreshold?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface LogicGateNodeData extends FlowgramNodeData {
|
|
||||||
gateType: LogicGateType;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface EndNodeData extends FlowgramNodeData {
|
|
||||||
label: string;
|
|
||||||
}
|
|
||||||
@@ -1,118 +0,0 @@
|
|||||||
// Data format converter between Flowgram and backend
|
|
||||||
import type { FlowgramGraph, FlowgramNode, FlowgramEdge } from '../types';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert Flowgram graph to backend format
|
|
||||||
* Flowgram uses a similar node-edge structure, so minimal conversion needed
|
|
||||||
*/
|
|
||||||
export function flowgramToBackend(flowgramGraph: FlowgramGraph): any {
|
|
||||||
return {
|
|
||||||
nodes: flowgramGraph.nodes.map((node) => ({
|
|
||||||
id: node.id,
|
|
||||||
type: node.type,
|
|
||||||
position: node.position,
|
|
||||||
data: node.data,
|
|
||||||
})),
|
|
||||||
edges: flowgramGraph.edges.map((edge) => ({
|
|
||||||
id: edge.id,
|
|
||||||
source: edge.source,
|
|
||||||
target: edge.target,
|
|
||||||
})),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert backend format to Flowgram graph
|
|
||||||
*/
|
|
||||||
export function backendToFlowgram(backendGraph: any): FlowgramGraph {
|
|
||||||
if (!backendGraph || !backendGraph.nodes) {
|
|
||||||
return { nodes: [], edges: [] };
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
nodes: backendGraph.nodes.map((node: any) => ({
|
|
||||||
id: node.id,
|
|
||||||
type: node.type,
|
|
||||||
position: node.position || { x: 0, y: 0 },
|
|
||||||
data: node.data || {},
|
|
||||||
})),
|
|
||||||
edges: backendGraph.edges || [],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new edge between two nodes
|
|
||||||
*/
|
|
||||||
export function createEdge(source: string, target: string, id?: string): FlowgramEdge {
|
|
||||||
return {
|
|
||||||
id: id || `edge-${source}-${target}`,
|
|
||||||
source,
|
|
||||||
target,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validate workflow graph structure
|
|
||||||
*/
|
|
||||||
export function validateWorkflow(graph: FlowgramGraph): { valid: boolean; errors: string[] } {
|
|
||||||
const errors: string[] = [];
|
|
||||||
|
|
||||||
// Check for at least one node
|
|
||||||
if (!graph.nodes || graph.nodes.length === 0) {
|
|
||||||
errors.push('工作流至少需要一个节点');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for trigger or start node
|
|
||||||
const hasTrigger = graph.nodes.some((n) => n.type === 'trigger' || n.type === 'start');
|
|
||||||
if (!hasTrigger) {
|
|
||||||
errors.push('工作流需要至少一个触发器或开始节点');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for cycles (simple check)
|
|
||||||
const visited = new Set<string>();
|
|
||||||
const recStack = new Set<string>();
|
|
||||||
|
|
||||||
function hasCycle(nodeId: string): boolean {
|
|
||||||
visited.add(nodeId);
|
|
||||||
recStack.add(nodeId);
|
|
||||||
|
|
||||||
const outgoingEdges = graph.edges.filter((e) => e.source === nodeId);
|
|
||||||
for (const edge of outgoingEdges) {
|
|
||||||
if (!visited.has(edge.target)) {
|
|
||||||
if (hasCycle(edge.target)) return true;
|
|
||||||
} else if (recStack.has(edge.target)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
recStack.delete(nodeId);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const node of graph.nodes) {
|
|
||||||
if (!visited.has(node.id) && hasCycle(node.id)) {
|
|
||||||
errors.push('工作流包含循环依赖');
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for disconnected nodes
|
|
||||||
const connectedNodes = new Set<string>();
|
|
||||||
graph.edges.forEach((edge) => {
|
|
||||||
connectedNodes.add(edge.source);
|
|
||||||
connectedNodes.add(edge.target);
|
|
||||||
});
|
|
||||||
|
|
||||||
const disconnectedNodes = graph.nodes.filter(
|
|
||||||
(node) => !connectedNodes.has(node.id) && graph.nodes.length > 1
|
|
||||||
);
|
|
||||||
|
|
||||||
if (disconnectedNodes.length > 0) {
|
|
||||||
errors.push(`发现 ${disconnectedNodes.length} 个未连接的节点`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
valid: errors.length === 0,
|
|
||||||
errors,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,196 +0,0 @@
|
|||||||
import React, { useState, useEffect, useRef } from 'react';
|
|
||||||
import { Modal, Form, Input, message } from 'antd';
|
|
||||||
import { request } from '@/utils/http';
|
|
||||||
import intl from 'react-intl-universal';
|
|
||||||
import { FreeLayoutEditor } from '@flowgram.ai/free-layout-editor';
|
|
||||||
import '@flowgram.ai/free-layout-editor/index.css';
|
|
||||||
|
|
||||||
const { TextArea } = Input;
|
|
||||||
|
|
||||||
interface ScenarioModalProps {
|
|
||||||
visible: boolean;
|
|
||||||
scenario: any;
|
|
||||||
onCancel: () => void;
|
|
||||||
onSuccess: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
const ScenarioModal: React.FC<ScenarioModalProps> = ({
|
|
||||||
visible,
|
|
||||||
scenario,
|
|
||||||
onCancel,
|
|
||||||
onSuccess,
|
|
||||||
}) => {
|
|
||||||
const [form] = Form.useForm();
|
|
||||||
const [loading, setLoading] = useState(false);
|
|
||||||
const editorRef = useRef<any>(null);
|
|
||||||
const [workflowGraph, setWorkflowGraph] = useState<any>(null);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (visible) {
|
|
||||||
if (scenario) {
|
|
||||||
form.setFieldsValue({
|
|
||||||
name: scenario.name,
|
|
||||||
description: scenario.description || '',
|
|
||||||
});
|
|
||||||
setWorkflowGraph(scenario.workflowGraph || getInitialWorkflow());
|
|
||||||
} else {
|
|
||||||
form.resetFields();
|
|
||||||
setWorkflowGraph(getInitialWorkflow());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, [visible, scenario, form]);
|
|
||||||
|
|
||||||
const getInitialWorkflow = () => {
|
|
||||||
return {
|
|
||||||
nodes: [
|
|
||||||
{
|
|
||||||
id: 'trigger-1',
|
|
||||||
type: 'trigger',
|
|
||||||
position: { x: 100, y: 100 },
|
|
||||||
data: {
|
|
||||||
label: intl.get('触发器'),
|
|
||||||
triggerType: 'time',
|
|
||||||
config: {},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
edges: [],
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleSubmit = async () => {
|
|
||||||
try {
|
|
||||||
const values = await form.validateFields();
|
|
||||||
setLoading(true);
|
|
||||||
|
|
||||||
// Get workflow data from editor
|
|
||||||
const currentWorkflow = editorRef.current?.getData();
|
|
||||||
|
|
||||||
const endpoint = scenario ? '/api/scenarios' : '/api/scenarios';
|
|
||||||
const method = scenario ? 'put' : 'post';
|
|
||||||
const payload = {
|
|
||||||
...values,
|
|
||||||
workflowGraph: currentWorkflow || workflowGraph,
|
|
||||||
...(scenario ? { id: scenario.id } : {}),
|
|
||||||
};
|
|
||||||
|
|
||||||
const { code } = await request[method](endpoint, payload);
|
|
||||||
if (code === 200) {
|
|
||||||
message.success(
|
|
||||||
scenario ? intl.get('更新成功') : intl.get('创建成功'),
|
|
||||||
);
|
|
||||||
onSuccess();
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Failed to save scenario:', error);
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleWorkflowChange = (newWorkflow: any) => {
|
|
||||||
setWorkflowGraph(newWorkflow);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Modal
|
|
||||||
title={scenario ? intl.get('编辑场景') : intl.get('新建场景')}
|
|
||||||
open={visible}
|
|
||||||
onCancel={onCancel}
|
|
||||||
onOk={handleSubmit}
|
|
||||||
confirmLoading={loading}
|
|
||||||
width={1200}
|
|
||||||
destroyOnClose
|
|
||||||
style={{ top: 20 }}
|
|
||||||
>
|
|
||||||
<Form form={form} layout="vertical">
|
|
||||||
<Form.Item
|
|
||||||
name="name"
|
|
||||||
label={intl.get('名称')}
|
|
||||||
rules={[{ required: true }]}
|
|
||||||
>
|
|
||||||
<Input />
|
|
||||||
</Form.Item>
|
|
||||||
|
|
||||||
<Form.Item name="description" label={intl.get('描述')}>
|
|
||||||
<TextArea rows={2} />
|
|
||||||
</Form.Item>
|
|
||||||
|
|
||||||
<Form.Item label={intl.get('工作流设计')}>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
border: '1px solid #d9d9d9',
|
|
||||||
borderRadius: 4,
|
|
||||||
height: 500,
|
|
||||||
overflow: 'hidden',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<FreeLayoutEditor
|
|
||||||
ref={editorRef}
|
|
||||||
data={workflowGraph}
|
|
||||||
onChange={handleWorkflowChange}
|
|
||||||
nodeTypes={{
|
|
||||||
trigger: {
|
|
||||||
render: (node: any) => (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
padding: 10,
|
|
||||||
background: '#1890ff',
|
|
||||||
color: 'white',
|
|
||||||
borderRadius: 4,
|
|
||||||
minWidth: 150,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div>{node.data.label}</div>
|
|
||||||
<div style={{ fontSize: 12, marginTop: 4 }}>
|
|
||||||
{node.data.triggerType}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
condition: {
|
|
||||||
render: (node: any) => (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
padding: 10,
|
|
||||||
background: '#52c41a',
|
|
||||||
color: 'white',
|
|
||||||
borderRadius: 4,
|
|
||||||
minWidth: 150,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div>{node.data.label}</div>
|
|
||||||
<div style={{ fontSize: 12, marginTop: 4 }}>
|
|
||||||
{node.data.operator}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
action: {
|
|
||||||
render: (node: any) => (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
padding: 10,
|
|
||||||
background: '#fa8c16',
|
|
||||||
color: 'white',
|
|
||||||
borderRadius: 4,
|
|
||||||
minWidth: 150,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div>{node.data.label}</div>
|
|
||||||
<div style={{ fontSize: 12, marginTop: 4 }}>
|
|
||||||
{node.data.actionType}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</Form.Item>
|
|
||||||
</Form>
|
|
||||||
</Modal>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default ScenarioModal;
|
|
||||||
@@ -1,109 +0,0 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
|
||||||
import { Modal, Form, Input, Switch, message } from 'antd';
|
|
||||||
import FlowgramEditor from './flowgram/Editor';
|
|
||||||
import type { FlowgramGraph } from './flowgram/types';
|
|
||||||
|
|
||||||
interface FlowgramWorkflowModalProps {
|
|
||||||
visible: boolean;
|
|
||||||
scenario?: any;
|
|
||||||
onCancel: () => void;
|
|
||||||
onOk: (values: any) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
const FlowgramWorkflowModal: React.FC<FlowgramWorkflowModalProps> = ({
|
|
||||||
visible,
|
|
||||||
scenario,
|
|
||||||
onCancel,
|
|
||||||
onOk,
|
|
||||||
}) => {
|
|
||||||
const [form] = Form.useForm();
|
|
||||||
const [loading, setLoading] = useState(false);
|
|
||||||
const [workflowGraph, setWorkflowGraph] = useState<FlowgramGraph | undefined>();
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (visible && scenario) {
|
|
||||||
form.setFieldsValue({
|
|
||||||
name: scenario.name,
|
|
||||||
isDisabled: scenario.isDisabled === 1,
|
|
||||||
});
|
|
||||||
if (scenario.workflowGraph) {
|
|
||||||
setWorkflowGraph(scenario.workflowGraph);
|
|
||||||
}
|
|
||||||
} else if (visible) {
|
|
||||||
form.resetFields();
|
|
||||||
setWorkflowGraph(undefined);
|
|
||||||
}
|
|
||||||
}, [visible, scenario, form]);
|
|
||||||
|
|
||||||
const handleOk = async () => {
|
|
||||||
try {
|
|
||||||
const values = await form.validateFields();
|
|
||||||
|
|
||||||
// Validate workflow has nodes
|
|
||||||
if (!workflowGraph || workflowGraph.nodes.length === 0) {
|
|
||||||
message.error('请添加至少一个节点到工作流');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setLoading(true);
|
|
||||||
|
|
||||||
const submitData = {
|
|
||||||
...values,
|
|
||||||
workflowGraph,
|
|
||||||
isDisabled: values.isDisabled ? 1 : 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (scenario) {
|
|
||||||
submitData.id = scenario.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
await onOk(submitData);
|
|
||||||
form.resetFields();
|
|
||||||
setWorkflowGraph(undefined);
|
|
||||||
} catch (error) {
|
|
||||||
console.error('表单验证失败:', error);
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleCancel = () => {
|
|
||||||
form.resetFields();
|
|
||||||
setWorkflowGraph(undefined);
|
|
||||||
onCancel();
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Modal
|
|
||||||
title={scenario ? '编辑场景' : '新建场景'}
|
|
||||||
open={visible}
|
|
||||||
onOk={handleOk}
|
|
||||||
onCancel={handleCancel}
|
|
||||||
confirmLoading={loading}
|
|
||||||
width={1400}
|
|
||||||
style={{ top: 20 }}
|
|
||||||
bodyStyle={{ height: '80vh', overflow: 'auto' }}
|
|
||||||
maskClosable={false}
|
|
||||||
>
|
|
||||||
<Form form={form} layout="vertical">
|
|
||||||
<Form.Item
|
|
||||||
name="name"
|
|
||||||
label="场景名称"
|
|
||||||
rules={[{ required: true, message: '请输入场景名称' }]}
|
|
||||||
>
|
|
||||||
<Input placeholder="输入场景名称" />
|
|
||||||
</Form.Item>
|
|
||||||
|
|
||||||
<Form.Item name="isDisabled" label="启用状态" valuePropName="checked">
|
|
||||||
<Switch checkedChildren="启用" unCheckedChildren="禁用" />
|
|
||||||
</Form.Item>
|
|
||||||
|
|
||||||
<Form.Item label="工作流设计">
|
|
||||||
<FlowgramEditor value={workflowGraph} onChange={setWorkflowGraph} />
|
|
||||||
</Form.Item>
|
|
||||||
</Form>
|
|
||||||
</Modal>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default FlowgramWorkflowModal;
|
|
||||||
@@ -1,337 +0,0 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
|
||||||
import { PageContainer } from '@ant-design/pro-layout';
|
|
||||||
import {
|
|
||||||
Button,
|
|
||||||
Table,
|
|
||||||
Space,
|
|
||||||
Modal,
|
|
||||||
message,
|
|
||||||
Tag,
|
|
||||||
Switch,
|
|
||||||
Tooltip,
|
|
||||||
Dropdown,
|
|
||||||
MenuProps,
|
|
||||||
} from 'antd';
|
|
||||||
import {
|
|
||||||
PlusOutlined,
|
|
||||||
EditOutlined,
|
|
||||||
DeleteOutlined,
|
|
||||||
PlayCircleOutlined,
|
|
||||||
EllipsisOutlined,
|
|
||||||
FileTextOutlined,
|
|
||||||
LinkOutlined,
|
|
||||||
} from '@ant-design/icons';
|
|
||||||
import { request } from '@/utils/http';
|
|
||||||
import intl from 'react-intl-universal';
|
|
||||||
import ScenarioModal from './flowgramWorkflowModal';
|
|
||||||
import ScenarioLogModal from './logModal';
|
|
||||||
import dayjs from 'dayjs';
|
|
||||||
|
|
||||||
const Scenario = () => {
|
|
||||||
const [loading, setLoading] = useState(false);
|
|
||||||
const [scenarios, setScenarios] = useState<any[]>([]);
|
|
||||||
const [selectedScenario, setSelectedScenario] = useState<any>(null);
|
|
||||||
const [isModalVisible, setIsModalVisible] = useState(false);
|
|
||||||
const [isLogModalVisible, setIsLogModalVisible] = useState(false);
|
|
||||||
|
|
||||||
const fetchScenarios = async () => {
|
|
||||||
setLoading(true);
|
|
||||||
try {
|
|
||||||
const { code, data } = await request.get('/api/scenarios');
|
|
||||||
if (code === 200) {
|
|
||||||
setScenarios(data || []);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Failed to fetch scenarios:', error);
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
fetchScenarios();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const handleCreate = () => {
|
|
||||||
setSelectedScenario(null);
|
|
||||||
setIsModalVisible(true);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleEdit = (record: any) => {
|
|
||||||
setSelectedScenario(record);
|
|
||||||
setIsModalVisible(true);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleDelete = (record: any) => {
|
|
||||||
Modal.confirm({
|
|
||||||
title: intl.get('确认删除'),
|
|
||||||
content: `${intl.get('确定要删除场景')} "${record.name}" ${intl.get('吗')}?`,
|
|
||||||
onOk: async () => {
|
|
||||||
try {
|
|
||||||
const { code } = await request.delete('/api/scenarios', {
|
|
||||||
data: [record.id],
|
|
||||||
});
|
|
||||||
if (code === 200) {
|
|
||||||
message.success(intl.get('删除成功'));
|
|
||||||
fetchScenarios();
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Failed to delete scenario:', error);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleToggleEnabled = async (record: any) => {
|
|
||||||
try {
|
|
||||||
const { code } = await request.put('/api/scenarios', {
|
|
||||||
id: record.id,
|
|
||||||
isEnabled: record.isEnabled === 1 ? 0 : 1,
|
|
||||||
});
|
|
||||||
if (code === 200) {
|
|
||||||
message.success(intl.get('更新成功'));
|
|
||||||
fetchScenarios();
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Failed to toggle scenario:', error);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleTrigger = async (record: any) => {
|
|
||||||
try {
|
|
||||||
const { code } = await request.post(`/api/scenarios/${record.id}/trigger`, {});
|
|
||||||
if (code === 200) {
|
|
||||||
message.success(intl.get('场景已触发'));
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Failed to trigger scenario:', error);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleModalOk = async (values: any) => {
|
|
||||||
try {
|
|
||||||
if (selectedScenario) {
|
|
||||||
const { code } = await request.put('/api/scenarios', values);
|
|
||||||
if (code === 200) {
|
|
||||||
message.success(intl.get('更新成功'));
|
|
||||||
setIsModalVisible(false);
|
|
||||||
setSelectedScenario(null);
|
|
||||||
fetchScenarios();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const { code } = await request.post('/api/scenarios', values);
|
|
||||||
if (code === 200) {
|
|
||||||
message.success(intl.get('创建成功'));
|
|
||||||
setIsModalVisible(false);
|
|
||||||
setSelectedScenario(null);
|
|
||||||
fetchScenarios();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Failed to save scenario:', error);
|
|
||||||
message.error(intl.get('操作失败'));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleViewLogs = (record: any) => {
|
|
||||||
setSelectedScenario(record);
|
|
||||||
setIsLogModalVisible(true);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleGetWebhook = async (record: any) => {
|
|
||||||
try {
|
|
||||||
const { code, data } = await request.get(`/api/scenarios/${record.id}/webhook`);
|
|
||||||
if (code === 200) {
|
|
||||||
Modal.info({
|
|
||||||
title: 'Webhook URL',
|
|
||||||
content: (
|
|
||||||
<div>
|
|
||||||
<p>{intl.get('使用此 URL 接收外部触发')}:</p>
|
|
||||||
<code style={{ wordBreak: 'break-all' }}>{data.webhookUrl}</code>
|
|
||||||
</div>
|
|
||||||
),
|
|
||||||
width: 600,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
message.error(intl.get('获取 Webhook URL 失败'));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const getTriggerTypeName = (type: string) => {
|
|
||||||
const types: any = {
|
|
||||||
variable: intl.get('变量监听'),
|
|
||||||
webhook: 'Webhook',
|
|
||||||
task_status: intl.get('任务状态'),
|
|
||||||
time: intl.get('时间触发'),
|
|
||||||
system_event: intl.get('系统事件'),
|
|
||||||
};
|
|
||||||
return types[type] || type;
|
|
||||||
};
|
|
||||||
|
|
||||||
const getActionsMenu = (record: any): MenuProps => ({
|
|
||||||
items: [
|
|
||||||
{
|
|
||||||
key: 'trigger',
|
|
||||||
icon: <PlayCircleOutlined />,
|
|
||||||
label: intl.get('手动触发'),
|
|
||||||
onClick: () => handleTrigger(record),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: 'logs',
|
|
||||||
icon: <FileTextOutlined />,
|
|
||||||
label: intl.get('查看日志'),
|
|
||||||
onClick: () => handleViewLogs(record),
|
|
||||||
},
|
|
||||||
...(record.triggerType === 'webhook'
|
|
||||||
? [
|
|
||||||
{
|
|
||||||
key: 'webhook',
|
|
||||||
icon: <LinkOutlined />,
|
|
||||||
label: intl.get('获取 Webhook'),
|
|
||||||
onClick: () => handleGetWebhook(record),
|
|
||||||
},
|
|
||||||
]
|
|
||||||
: []),
|
|
||||||
{
|
|
||||||
type: 'divider' as const,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: 'edit',
|
|
||||||
icon: <EditOutlined />,
|
|
||||||
label: intl.get('编辑'),
|
|
||||||
onClick: () => handleEdit(record),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: 'delete',
|
|
||||||
icon: <DeleteOutlined />,
|
|
||||||
label: intl.get('删除'),
|
|
||||||
danger: true,
|
|
||||||
onClick: () => handleDelete(record),
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
|
||||||
|
|
||||||
const columns = [
|
|
||||||
{
|
|
||||||
title: intl.get('名称'),
|
|
||||||
dataIndex: 'name',
|
|
||||||
key: 'name',
|
|
||||||
width: 180,
|
|
||||||
ellipsis: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: intl.get('描述'),
|
|
||||||
dataIndex: 'description',
|
|
||||||
key: 'description',
|
|
||||||
ellipsis: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: intl.get('触发类型'),
|
|
||||||
dataIndex: 'triggerType',
|
|
||||||
key: 'triggerType',
|
|
||||||
width: 120,
|
|
||||||
render: (type: string) => (
|
|
||||||
<Tag color="blue">{getTriggerTypeName(type)}</Tag>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: intl.get('状态'),
|
|
||||||
dataIndex: 'isEnabled',
|
|
||||||
key: 'isEnabled',
|
|
||||||
width: 80,
|
|
||||||
render: (isEnabled: number, record: any) => (
|
|
||||||
<Switch
|
|
||||||
checked={isEnabled === 1}
|
|
||||||
onChange={() => handleToggleEnabled(record)}
|
|
||||||
/>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: intl.get('执行次数'),
|
|
||||||
dataIndex: 'executionCount',
|
|
||||||
key: 'executionCount',
|
|
||||||
width: 100,
|
|
||||||
render: (count: number) => count || 0,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: intl.get('成功/失败'),
|
|
||||||
key: 'stats',
|
|
||||||
width: 100,
|
|
||||||
render: (_: any, record: any) => (
|
|
||||||
<span>
|
|
||||||
<Tag color="success">{record.successCount || 0}</Tag>
|
|
||||||
<Tag color="error">{record.failureCount || 0}</Tag>
|
|
||||||
</span>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: intl.get('最后触发'),
|
|
||||||
dataIndex: 'lastTriggeredAt',
|
|
||||||
key: 'lastTriggeredAt',
|
|
||||||
width: 160,
|
|
||||||
render: (date: string) =>
|
|
||||||
date ? dayjs(date).format('YYYY-MM-DD HH:mm:ss') : '-',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: intl.get('操作'),
|
|
||||||
key: 'action',
|
|
||||||
width: 100,
|
|
||||||
fixed: 'right' as const,
|
|
||||||
render: (_: any, record: any) => (
|
|
||||||
<Dropdown menu={getActionsMenu(record)} trigger={['click']}>
|
|
||||||
<Button type="link" icon={<EllipsisOutlined />} />
|
|
||||||
</Dropdown>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
return (
|
|
||||||
<PageContainer
|
|
||||||
title={intl.get('场景模式')}
|
|
||||||
extra={[
|
|
||||||
<Button
|
|
||||||
key="create"
|
|
||||||
type="primary"
|
|
||||||
icon={<PlusOutlined />}
|
|
||||||
onClick={handleCreate}
|
|
||||||
>
|
|
||||||
{intl.get('新建场景')}
|
|
||||||
</Button>,
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
<Table
|
|
||||||
columns={columns}
|
|
||||||
dataSource={scenarios}
|
|
||||||
rowKey="id"
|
|
||||||
loading={loading}
|
|
||||||
scroll={{ x: 1200 }}
|
|
||||||
pagination={{
|
|
||||||
showSizeChanger: true,
|
|
||||||
showTotal: (total) => `${intl.get('共')} ${total} ${intl.get('项')}`,
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<ScenarioModal
|
|
||||||
visible={isModalVisible}
|
|
||||||
scenario={selectedScenario}
|
|
||||||
onCancel={() => {
|
|
||||||
setIsModalVisible(false);
|
|
||||||
setSelectedScenario(null);
|
|
||||||
}}
|
|
||||||
onOk={handleModalOk}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<ScenarioLogModal
|
|
||||||
visible={isLogModalVisible}
|
|
||||||
scenario={selectedScenario}
|
|
||||||
onCancel={() => {
|
|
||||||
setIsLogModalVisible(false);
|
|
||||||
setSelectedScenario(null);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</PageContainer>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Scenario;
|
|
||||||
@@ -1,130 +0,0 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
|
||||||
import { Modal, Table, Tag, Typography } from 'antd';
|
|
||||||
import { request } from '@/utils/http';
|
|
||||||
import intl from 'react-intl-universal';
|
|
||||||
import dayjs from 'dayjs';
|
|
||||||
|
|
||||||
const { Text } = Typography;
|
|
||||||
|
|
||||||
interface ScenarioLogModalProps {
|
|
||||||
visible: boolean;
|
|
||||||
scenario: any;
|
|
||||||
onCancel: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
const ScenarioLogModal: React.FC<ScenarioLogModalProps> = ({
|
|
||||||
visible,
|
|
||||||
scenario,
|
|
||||||
onCancel,
|
|
||||||
}) => {
|
|
||||||
const [loading, setLoading] = useState(false);
|
|
||||||
const [logs, setLogs] = useState<any[]>([]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (visible && scenario) {
|
|
||||||
fetchLogs();
|
|
||||||
}
|
|
||||||
}, [visible, scenario]);
|
|
||||||
|
|
||||||
const fetchLogs = async () => {
|
|
||||||
setLoading(true);
|
|
||||||
try {
|
|
||||||
const { code, data } = await request.get('/api/scenarios/logs', {
|
|
||||||
params: {
|
|
||||||
scenarioId: scenario.id,
|
|
||||||
limit: 100,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
if (code === 200) {
|
|
||||||
setLogs(data || []);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Failed to fetch logs:', error);
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const columns = [
|
|
||||||
{
|
|
||||||
title: intl.get('时间'),
|
|
||||||
dataIndex: 'createdAt',
|
|
||||||
key: 'createdAt',
|
|
||||||
width: 180,
|
|
||||||
render: (date: string) => dayjs(date).format('YYYY-MM-DD HH:mm:ss'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: intl.get('状态'),
|
|
||||||
dataIndex: 'executionStatus',
|
|
||||||
key: 'executionStatus',
|
|
||||||
width: 100,
|
|
||||||
render: (status: string) => {
|
|
||||||
const colors: any = {
|
|
||||||
success: 'success',
|
|
||||||
failure: 'error',
|
|
||||||
partial: 'warning',
|
|
||||||
};
|
|
||||||
return <Tag color={colors[status] || 'default'}>{status}</Tag>;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: intl.get('条件匹配'),
|
|
||||||
dataIndex: 'conditionsMatched',
|
|
||||||
key: 'conditionsMatched',
|
|
||||||
width: 100,
|
|
||||||
render: (matched: boolean) => (
|
|
||||||
<Tag color={matched ? 'success' : 'default'}>
|
|
||||||
{matched ? intl.get('是') : intl.get('否')}
|
|
||||||
</Tag>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: intl.get('执行时间'),
|
|
||||||
dataIndex: 'executionTime',
|
|
||||||
key: 'executionTime',
|
|
||||||
width: 100,
|
|
||||||
render: (time: number) => (time ? `${time}ms` : '-'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: intl.get('重试次数'),
|
|
||||||
dataIndex: 'retriesAttempted',
|
|
||||||
key: 'retriesAttempted',
|
|
||||||
width: 100,
|
|
||||||
render: (retries: number) => retries || 0,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: intl.get('错误信息'),
|
|
||||||
dataIndex: 'errorMessage',
|
|
||||||
key: 'errorMessage',
|
|
||||||
ellipsis: true,
|
|
||||||
render: (error: string) => (
|
|
||||||
<Text type={error ? 'danger' : undefined}>{error || '-'}</Text>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Modal
|
|
||||||
title={`${intl.get('场景日志')} - ${scenario?.name || ''}`}
|
|
||||||
open={visible}
|
|
||||||
onCancel={onCancel}
|
|
||||||
footer={null}
|
|
||||||
width={1000}
|
|
||||||
destroyOnClose
|
|
||||||
>
|
|
||||||
<Table
|
|
||||||
columns={columns}
|
|
||||||
dataSource={logs}
|
|
||||||
rowKey="id"
|
|
||||||
loading={loading}
|
|
||||||
pagination={{
|
|
||||||
pageSize: 20,
|
|
||||||
showSizeChanger: true,
|
|
||||||
}}
|
|
||||||
size="small"
|
|
||||||
/>
|
|
||||||
</Modal>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default ScenarioLogModal;
|
|
||||||
@@ -1,443 +0,0 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
|
||||||
import {
|
|
||||||
Modal,
|
|
||||||
Form,
|
|
||||||
Input,
|
|
||||||
Select,
|
|
||||||
InputNumber,
|
|
||||||
Switch,
|
|
||||||
Button,
|
|
||||||
Space,
|
|
||||||
Card,
|
|
||||||
message,
|
|
||||||
Divider,
|
|
||||||
} from 'antd';
|
|
||||||
import { PlusOutlined, DeleteOutlined } from '@ant-design/icons';
|
|
||||||
import { request } from '@/utils/http';
|
|
||||||
import intl from 'react-intl-universal';
|
|
||||||
|
|
||||||
const { TextArea } = Input;
|
|
||||||
const { Option } = Select;
|
|
||||||
|
|
||||||
interface ScenarioModalProps {
|
|
||||||
visible: boolean;
|
|
||||||
scenario: any;
|
|
||||||
onCancel: () => void;
|
|
||||||
onSuccess: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
const ScenarioModal: React.FC<ScenarioModalProps> = ({
|
|
||||||
visible,
|
|
||||||
scenario,
|
|
||||||
onCancel,
|
|
||||||
onSuccess,
|
|
||||||
}) => {
|
|
||||||
const [form] = Form.useForm();
|
|
||||||
const [loading, setLoading] = useState(false);
|
|
||||||
const [triggerType, setTriggerType] = useState('time');
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (visible) {
|
|
||||||
if (scenario) {
|
|
||||||
form.setFieldsValue({
|
|
||||||
...scenario,
|
|
||||||
conditions: scenario.conditions || [],
|
|
||||||
actions: scenario.actions || [],
|
|
||||||
});
|
|
||||||
setTriggerType(scenario.triggerType);
|
|
||||||
} else {
|
|
||||||
form.resetFields();
|
|
||||||
form.setFieldsValue({
|
|
||||||
isEnabled: 1,
|
|
||||||
conditionLogic: 'AND',
|
|
||||||
failureThreshold: 3,
|
|
||||||
delayExecution: 0,
|
|
||||||
conditions: [],
|
|
||||||
actions: [],
|
|
||||||
});
|
|
||||||
setTriggerType('time');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, [visible, scenario, form]);
|
|
||||||
|
|
||||||
const handleSubmit = async () => {
|
|
||||||
try {
|
|
||||||
const values = await form.validateFields();
|
|
||||||
setLoading(true);
|
|
||||||
|
|
||||||
const endpoint = scenario ? '/api/scenarios' : '/api/scenarios';
|
|
||||||
const method = scenario ? 'put' : 'post';
|
|
||||||
const payload = scenario ? { ...values, id: scenario.id } : values;
|
|
||||||
|
|
||||||
const { code } = await request[method](endpoint, payload);
|
|
||||||
if (code === 200) {
|
|
||||||
message.success(
|
|
||||||
scenario ? intl.get('更新成功') : intl.get('创建成功'),
|
|
||||||
);
|
|
||||||
onSuccess();
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Failed to save scenario:', error);
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const renderTriggerConfig = () => {
|
|
||||||
switch (triggerType) {
|
|
||||||
case 'variable':
|
|
||||||
return (
|
|
||||||
<Form.Item
|
|
||||||
name={['triggerConfig', 'watchPath']}
|
|
||||||
label={intl.get('监听路径')}
|
|
||||||
rules={[{ required: true }]}
|
|
||||||
>
|
|
||||||
<Input placeholder="/path/to/watch" />
|
|
||||||
</Form.Item>
|
|
||||||
);
|
|
||||||
case 'webhook':
|
|
||||||
return (
|
|
||||||
<Form.Item name={['triggerConfig', 'token']} label="Token">
|
|
||||||
<Input
|
|
||||||
placeholder={intl.get('留空自动生成')}
|
|
||||||
disabled={!!scenario}
|
|
||||||
/>
|
|
||||||
</Form.Item>
|
|
||||||
);
|
|
||||||
case 'time':
|
|
||||||
return (
|
|
||||||
<Form.Item
|
|
||||||
name={['triggerConfig', 'schedule']}
|
|
||||||
label={intl.get('Cron 表达式')}
|
|
||||||
rules={[{ required: true }]}
|
|
||||||
>
|
|
||||||
<Input placeholder="0 0 * * *" />
|
|
||||||
</Form.Item>
|
|
||||||
);
|
|
||||||
case 'system_event':
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<Form.Item
|
|
||||||
name={['triggerConfig', 'eventType']}
|
|
||||||
label={intl.get('事件类型')}
|
|
||||||
rules={[{ required: true }]}
|
|
||||||
>
|
|
||||||
<Select>
|
|
||||||
<Option value="disk_space">{intl.get('磁盘空间')}</Option>
|
|
||||||
<Option value="memory">{intl.get('内存使用')}</Option>
|
|
||||||
</Select>
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item
|
|
||||||
name={['triggerConfig', 'threshold']}
|
|
||||||
label={intl.get('阈值')}
|
|
||||||
rules={[{ required: true }]}
|
|
||||||
>
|
|
||||||
<InputNumber min={0} max={100} addonAfter="%" />
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item
|
|
||||||
name={['triggerConfig', 'checkInterval']}
|
|
||||||
label={intl.get('检查间隔')}
|
|
||||||
>
|
|
||||||
<InputNumber min={10000} addonAfter="ms" />
|
|
||||||
</Form.Item>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
case 'task_status':
|
|
||||||
return (
|
|
||||||
<Form.Item
|
|
||||||
name={['triggerConfig', 'cronId']}
|
|
||||||
label={intl.get('任务 ID')}
|
|
||||||
rules={[{ required: true }]}
|
|
||||||
>
|
|
||||||
<InputNumber min={1} />
|
|
||||||
</Form.Item>
|
|
||||||
);
|
|
||||||
default:
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Modal
|
|
||||||
title={scenario ? intl.get('编辑场景') : intl.get('新建场景')}
|
|
||||||
open={visible}
|
|
||||||
onCancel={onCancel}
|
|
||||||
onOk={handleSubmit}
|
|
||||||
confirmLoading={loading}
|
|
||||||
width={800}
|
|
||||||
destroyOnClose
|
|
||||||
>
|
|
||||||
<Form form={form} layout="vertical">
|
|
||||||
<Form.Item
|
|
||||||
name="name"
|
|
||||||
label={intl.get('名称')}
|
|
||||||
rules={[{ required: true }]}
|
|
||||||
>
|
|
||||||
<Input />
|
|
||||||
</Form.Item>
|
|
||||||
|
|
||||||
<Form.Item name="description" label={intl.get('描述')}>
|
|
||||||
<TextArea rows={2} />
|
|
||||||
</Form.Item>
|
|
||||||
|
|
||||||
<Form.Item
|
|
||||||
name="triggerType"
|
|
||||||
label={intl.get('触发类型')}
|
|
||||||
rules={[{ required: true }]}
|
|
||||||
>
|
|
||||||
<Select onChange={setTriggerType}>
|
|
||||||
<Option value="time">{intl.get('时间触发')}</Option>
|
|
||||||
<Option value="variable">{intl.get('变量监听')}</Option>
|
|
||||||
<Option value="webhook">Webhook</Option>
|
|
||||||
<Option value="task_status">{intl.get('任务状态')}</Option>
|
|
||||||
<Option value="system_event">{intl.get('系统事件')}</Option>
|
|
||||||
</Select>
|
|
||||||
</Form.Item>
|
|
||||||
|
|
||||||
{renderTriggerConfig()}
|
|
||||||
|
|
||||||
<Divider orientation="left">{intl.get('条件配置')}</Divider>
|
|
||||||
|
|
||||||
<Form.Item
|
|
||||||
name="conditionLogic"
|
|
||||||
label={intl.get('条件逻辑')}
|
|
||||||
tooltip={intl.get('多个条件之间的关系')}
|
|
||||||
>
|
|
||||||
<Select>
|
|
||||||
<Option value="AND">AND ({intl.get('全部满足')})</Option>
|
|
||||||
<Option value="OR">OR ({intl.get('任一满足')})</Option>
|
|
||||||
</Select>
|
|
||||||
</Form.Item>
|
|
||||||
|
|
||||||
<Form.List name="conditions">
|
|
||||||
{(fields, { add, remove }) => (
|
|
||||||
<>
|
|
||||||
{fields.map((field) => (
|
|
||||||
<Card
|
|
||||||
key={field.key}
|
|
||||||
size="small"
|
|
||||||
style={{ marginBottom: 8 }}
|
|
||||||
extra={
|
|
||||||
<DeleteOutlined
|
|
||||||
onClick={() => remove(field.name)}
|
|
||||||
style={{ color: 'red' }}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<Space>
|
|
||||||
<Form.Item
|
|
||||||
{...field}
|
|
||||||
name={[field.name, 'field']}
|
|
||||||
noStyle
|
|
||||||
rules={[{ required: true }]}
|
|
||||||
>
|
|
||||||
<Input
|
|
||||||
placeholder={intl.get('字段名')}
|
|
||||||
style={{ width: 150 }}
|
|
||||||
/>
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item
|
|
||||||
{...field}
|
|
||||||
name={[field.name, 'operator']}
|
|
||||||
noStyle
|
|
||||||
rules={[{ required: true }]}
|
|
||||||
>
|
|
||||||
<Select placeholder={intl.get('操作符')} style={{ width: 120 }}>
|
|
||||||
<Option value="equals">=</Option>
|
|
||||||
<Option value="not_equals">!=</Option>
|
|
||||||
<Option value="greater_than">></Option>
|
|
||||||
<Option value="less_than"><</Option>
|
|
||||||
<Option value="contains">{intl.get('包含')}</Option>
|
|
||||||
<Option value="not_contains">{intl.get('不包含')}</Option>
|
|
||||||
</Select>
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item
|
|
||||||
{...field}
|
|
||||||
name={[field.name, 'value']}
|
|
||||||
noStyle
|
|
||||||
rules={[{ required: true }]}
|
|
||||||
>
|
|
||||||
<Input
|
|
||||||
placeholder={intl.get('值')}
|
|
||||||
style={{ width: 150 }}
|
|
||||||
/>
|
|
||||||
</Form.Item>
|
|
||||||
</Space>
|
|
||||||
</Card>
|
|
||||||
))}
|
|
||||||
<Button
|
|
||||||
type="dashed"
|
|
||||||
onClick={() => add()}
|
|
||||||
block
|
|
||||||
icon={<PlusOutlined />}
|
|
||||||
>
|
|
||||||
{intl.get('添加条件')}
|
|
||||||
</Button>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</Form.List>
|
|
||||||
|
|
||||||
<Divider orientation="left">{intl.get('动作配置')}</Divider>
|
|
||||||
|
|
||||||
<Form.List name="actions">
|
|
||||||
{(fields, { add, remove }) => (
|
|
||||||
<>
|
|
||||||
{fields.map((field) => (
|
|
||||||
<Card
|
|
||||||
key={field.key}
|
|
||||||
size="small"
|
|
||||||
style={{ marginBottom: 8 }}
|
|
||||||
extra={
|
|
||||||
<DeleteOutlined
|
|
||||||
onClick={() => remove(field.name)}
|
|
||||||
style={{ color: 'red' }}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<Form.Item
|
|
||||||
{...field}
|
|
||||||
name={[field.name, 'type']}
|
|
||||||
label={intl.get('动作类型')}
|
|
||||||
rules={[{ required: true }]}
|
|
||||||
>
|
|
||||||
<Select>
|
|
||||||
<Option value="run_task">{intl.get('运行任务')}</Option>
|
|
||||||
<Option value="set_variable">{intl.get('设置变量')}</Option>
|
|
||||||
<Option value="execute_command">{intl.get('执行命令')}</Option>
|
|
||||||
<Option value="send_notification">{intl.get('发送通知')}</Option>
|
|
||||||
</Select>
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item
|
|
||||||
noStyle
|
|
||||||
shouldUpdate={(prevValues, currentValues) =>
|
|
||||||
prevValues.actions?.[field.name]?.type !==
|
|
||||||
currentValues.actions?.[field.name]?.type
|
|
||||||
}
|
|
||||||
>
|
|
||||||
{({ getFieldValue }) => {
|
|
||||||
const actionType = getFieldValue([
|
|
||||||
'actions',
|
|
||||||
field.name,
|
|
||||||
'type',
|
|
||||||
]);
|
|
||||||
if (actionType === 'run_task') {
|
|
||||||
return (
|
|
||||||
<Form.Item
|
|
||||||
{...field}
|
|
||||||
name={[field.name, 'cronId']}
|
|
||||||
label={intl.get('任务 ID')}
|
|
||||||
rules={[{ required: true }]}
|
|
||||||
>
|
|
||||||
<InputNumber min={1} style={{ width: '100%' }} />
|
|
||||||
</Form.Item>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (actionType === 'set_variable') {
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<Form.Item
|
|
||||||
{...field}
|
|
||||||
name={[field.name, 'name']}
|
|
||||||
label={intl.get('变量名')}
|
|
||||||
rules={[{ required: true }]}
|
|
||||||
>
|
|
||||||
<Input />
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item
|
|
||||||
{...field}
|
|
||||||
name={[field.name, 'value']}
|
|
||||||
label={intl.get('变量值')}
|
|
||||||
rules={[{ required: true }]}
|
|
||||||
>
|
|
||||||
<Input />
|
|
||||||
</Form.Item>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (actionType === 'execute_command') {
|
|
||||||
return (
|
|
||||||
<Form.Item
|
|
||||||
{...field}
|
|
||||||
name={[field.name, 'command']}
|
|
||||||
label={intl.get('命令')}
|
|
||||||
rules={[{ required: true }]}
|
|
||||||
>
|
|
||||||
<TextArea rows={2} />
|
|
||||||
</Form.Item>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (actionType === 'send_notification') {
|
|
||||||
return (
|
|
||||||
<Form.Item
|
|
||||||
{...field}
|
|
||||||
name={[field.name, 'message']}
|
|
||||||
label={intl.get('消息')}
|
|
||||||
rules={[{ required: true }]}
|
|
||||||
>
|
|
||||||
<TextArea rows={2} />
|
|
||||||
</Form.Item>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}}
|
|
||||||
</Form.Item>
|
|
||||||
</Card>
|
|
||||||
))}
|
|
||||||
<Button
|
|
||||||
type="dashed"
|
|
||||||
onClick={() => add()}
|
|
||||||
block
|
|
||||||
icon={<PlusOutlined />}
|
|
||||||
>
|
|
||||||
{intl.get('添加动作')}
|
|
||||||
</Button>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</Form.List>
|
|
||||||
|
|
||||||
<Divider orientation="left">{intl.get('高级设置')}</Divider>
|
|
||||||
|
|
||||||
<Form.Item name="delayExecution" label={intl.get('延迟执行')}>
|
|
||||||
<InputNumber min={0} addonAfter={intl.get('秒')} />
|
|
||||||
</Form.Item>
|
|
||||||
|
|
||||||
<Form.Item
|
|
||||||
name="failureThreshold"
|
|
||||||
label={intl.get('失败熔断阈值')}
|
|
||||||
tooltip={intl.get('连续失败多少次后自动禁用')}
|
|
||||||
>
|
|
||||||
<InputNumber min={1} />
|
|
||||||
</Form.Item>
|
|
||||||
|
|
||||||
<Form.Item name={['retryStrategy', 'maxRetries']} label={intl.get('最大重试次数')}>
|
|
||||||
<InputNumber min={0} max={10} />
|
|
||||||
</Form.Item>
|
|
||||||
|
|
||||||
<Form.Item
|
|
||||||
name={['retryStrategy', 'retryDelay']}
|
|
||||||
label={intl.get('重试延迟')}
|
|
||||||
>
|
|
||||||
<InputNumber min={1} addonAfter={intl.get('秒')} />
|
|
||||||
</Form.Item>
|
|
||||||
|
|
||||||
<Form.Item
|
|
||||||
name={['retryStrategy', 'backoffMultiplier']}
|
|
||||||
label={intl.get('退避倍数')}
|
|
||||||
tooltip={intl.get('每次重试延迟的乘数')}
|
|
||||||
>
|
|
||||||
<InputNumber min={1} step={0.5} />
|
|
||||||
</Form.Item>
|
|
||||||
|
|
||||||
<Form.Item
|
|
||||||
name="isEnabled"
|
|
||||||
label={intl.get('启用')}
|
|
||||||
valuePropName="checked"
|
|
||||||
>
|
|
||||||
<Switch />
|
|
||||||
</Form.Item>
|
|
||||||
</Form>
|
|
||||||
</Modal>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default ScenarioModal;
|
|
||||||
@@ -1,299 +0,0 @@
|
|||||||
// Custom Node Type Definitions for Flowgram Workflow Editor
|
|
||||||
import React from 'react';
|
|
||||||
import { Tag } from 'antd';
|
|
||||||
|
|
||||||
export interface NodeData {
|
|
||||||
label: string;
|
|
||||||
[key: string]: any;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface WorkflowNode {
|
|
||||||
id: string;
|
|
||||||
type: string;
|
|
||||||
position: { x: number; y: number };
|
|
||||||
data: NodeData;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface WorkflowEdge {
|
|
||||||
id: string;
|
|
||||||
source: string;
|
|
||||||
target: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface WorkflowGraph {
|
|
||||||
nodes: WorkflowNode[];
|
|
||||||
edges: WorkflowEdge[];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Trigger Node Types
|
|
||||||
export const TriggerNodeTypes = {
|
|
||||||
TIME: 'time',
|
|
||||||
WEBHOOK: 'webhook',
|
|
||||||
VARIABLE: 'variable',
|
|
||||||
TASK_STATUS: 'task_status',
|
|
||||||
SYSTEM_EVENT: 'system_event',
|
|
||||||
};
|
|
||||||
|
|
||||||
// Condition Node Types
|
|
||||||
export const ConditionNodeTypes = {
|
|
||||||
EQUALS: 'equals',
|
|
||||||
NOT_EQUALS: 'not_equals',
|
|
||||||
GREATER_THAN: 'greater_than',
|
|
||||||
LESS_THAN: 'less_than',
|
|
||||||
CONTAINS: 'contains',
|
|
||||||
NOT_CONTAINS: 'not_contains',
|
|
||||||
};
|
|
||||||
|
|
||||||
// Action Node Types
|
|
||||||
export const ActionNodeTypes = {
|
|
||||||
RUN_TASK: 'run_task',
|
|
||||||
SET_VARIABLE: 'set_variable',
|
|
||||||
EXECUTE_COMMAND: 'execute_command',
|
|
||||||
SEND_NOTIFICATION: 'send_notification',
|
|
||||||
};
|
|
||||||
|
|
||||||
// Control Flow Node Types
|
|
||||||
export const ControlFlowNodeTypes = {
|
|
||||||
DELAY: 'delay',
|
|
||||||
RETRY: 'retry',
|
|
||||||
CIRCUIT_BREAKER: 'circuit_breaker',
|
|
||||||
AND_GATE: 'and_gate',
|
|
||||||
OR_GATE: 'or_gate',
|
|
||||||
};
|
|
||||||
|
|
||||||
// Node Renderer Components
|
|
||||||
export const NodeRenderers = {
|
|
||||||
trigger: (node: WorkflowNode) => (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
padding: '12px 16px',
|
|
||||||
background: '#1890ff',
|
|
||||||
color: 'white',
|
|
||||||
borderRadius: 6,
|
|
||||||
minWidth: 160,
|
|
||||||
boxShadow: '0 2px 8px rgba(24, 144, 255, 0.3)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div style={{ fontWeight: 600, marginBottom: 4 }}>{node.data.label}</div>
|
|
||||||
<Tag
|
|
||||||
style={{
|
|
||||||
background: 'rgba(255, 255, 255, 0.2)',
|
|
||||||
border: 'none',
|
|
||||||
color: 'white',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{node.data.triggerType || 'trigger'}
|
|
||||||
</Tag>
|
|
||||||
</div>
|
|
||||||
),
|
|
||||||
|
|
||||||
condition: (node: WorkflowNode) => (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
padding: '12px 16px',
|
|
||||||
background: '#52c41a',
|
|
||||||
color: 'white',
|
|
||||||
borderRadius: 6,
|
|
||||||
minWidth: 160,
|
|
||||||
boxShadow: '0 2px 8px rgba(82, 196, 26, 0.3)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div style={{ fontWeight: 600, marginBottom: 4 }}>{node.data.label}</div>
|
|
||||||
<div style={{ fontSize: 12, opacity: 0.9 }}>
|
|
||||||
{node.data.field} {node.data.operator} {node.data.value}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
),
|
|
||||||
|
|
||||||
action: (node: WorkflowNode) => (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
padding: '12px 16px',
|
|
||||||
background: '#fa8c16',
|
|
||||||
color: 'white',
|
|
||||||
borderRadius: 6,
|
|
||||||
minWidth: 160,
|
|
||||||
boxShadow: '0 2px 8px rgba(250, 140, 22, 0.3)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div style={{ fontWeight: 600, marginBottom: 4 }}>{node.data.label}</div>
|
|
||||||
<Tag
|
|
||||||
style={{
|
|
||||||
background: 'rgba(255, 255, 255, 0.2)',
|
|
||||||
border: 'none',
|
|
||||||
color: 'white',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{node.data.actionType || 'action'}
|
|
||||||
</Tag>
|
|
||||||
</div>
|
|
||||||
),
|
|
||||||
|
|
||||||
control: (node: WorkflowNode) => (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
padding: '12px 16px',
|
|
||||||
background: '#722ed1',
|
|
||||||
color: 'white',
|
|
||||||
borderRadius: 6,
|
|
||||||
minWidth: 160,
|
|
||||||
boxShadow: '0 2px 8px rgba(114, 46, 209, 0.3)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div style={{ fontWeight: 600, marginBottom: 4 }}>{node.data.label}</div>
|
|
||||||
<div style={{ fontSize: 12, opacity: 0.9 }}>
|
|
||||||
{node.data.controlType || 'control'}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
),
|
|
||||||
|
|
||||||
logic_gate: (node: WorkflowNode) => (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
padding: '12px 16px',
|
|
||||||
background: '#13c2c2',
|
|
||||||
color: 'white',
|
|
||||||
borderRadius: 6,
|
|
||||||
minWidth: 120,
|
|
||||||
textAlign: 'center',
|
|
||||||
boxShadow: '0 2px 8px rgba(19, 194, 194, 0.3)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div style={{ fontWeight: 600, fontSize: 16 }}>
|
|
||||||
{node.data.gateType || 'AND'}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
),
|
|
||||||
};
|
|
||||||
|
|
||||||
// Helper function to create a new node
|
|
||||||
export const createNode = (
|
|
||||||
type: string,
|
|
||||||
position: { x: number; y: number },
|
|
||||||
data: Partial<NodeData>,
|
|
||||||
): WorkflowNode => {
|
|
||||||
return {
|
|
||||||
id: `${type}-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
|
|
||||||
type,
|
|
||||||
position,
|
|
||||||
data: {
|
|
||||||
label: data.label || type,
|
|
||||||
...data,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
// Helper function to create a new edge
|
|
||||||
export const createEdge = (
|
|
||||||
source: string,
|
|
||||||
target: string,
|
|
||||||
): WorkflowEdge => {
|
|
||||||
return {
|
|
||||||
id: `edge-${source}-${target}`,
|
|
||||||
source,
|
|
||||||
target,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
// Node templates for quick creation
|
|
||||||
export const NodeTemplates = {
|
|
||||||
triggers: {
|
|
||||||
time: {
|
|
||||||
label: '时间触发',
|
|
||||||
triggerType: 'time',
|
|
||||||
config: { schedule: '0 0 * * *' },
|
|
||||||
},
|
|
||||||
webhook: {
|
|
||||||
label: 'Webhook触发',
|
|
||||||
triggerType: 'webhook',
|
|
||||||
config: {},
|
|
||||||
},
|
|
||||||
variable: {
|
|
||||||
label: '变量监听',
|
|
||||||
triggerType: 'variable',
|
|
||||||
config: { watchPath: '' },
|
|
||||||
},
|
|
||||||
task_status: {
|
|
||||||
label: '任务状态',
|
|
||||||
triggerType: 'task_status',
|
|
||||||
config: { cronId: null },
|
|
||||||
},
|
|
||||||
system_event: {
|
|
||||||
label: '系统事件',
|
|
||||||
triggerType: 'system_event',
|
|
||||||
config: { eventType: 'disk_space', threshold: 80 },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
conditions: {
|
|
||||||
equals: {
|
|
||||||
label: '等于判断',
|
|
||||||
operator: 'equals',
|
|
||||||
field: '',
|
|
||||||
value: '',
|
|
||||||
},
|
|
||||||
greater_than: {
|
|
||||||
label: '大于判断',
|
|
||||||
operator: 'greater_than',
|
|
||||||
field: '',
|
|
||||||
value: 0,
|
|
||||||
},
|
|
||||||
contains: {
|
|
||||||
label: '包含判断',
|
|
||||||
operator: 'contains',
|
|
||||||
field: '',
|
|
||||||
value: '',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
actions: {
|
|
||||||
run_task: {
|
|
||||||
label: '运行任务',
|
|
||||||
actionType: 'run_task',
|
|
||||||
cronId: null,
|
|
||||||
},
|
|
||||||
set_variable: {
|
|
||||||
label: '设置变量',
|
|
||||||
actionType: 'set_variable',
|
|
||||||
name: '',
|
|
||||||
value: '',
|
|
||||||
},
|
|
||||||
execute_command: {
|
|
||||||
label: '执行命令',
|
|
||||||
actionType: 'execute_command',
|
|
||||||
command: '',
|
|
||||||
},
|
|
||||||
send_notification: {
|
|
||||||
label: '发送通知',
|
|
||||||
actionType: 'send_notification',
|
|
||||||
message: '',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
controls: {
|
|
||||||
delay: {
|
|
||||||
label: '延迟执行',
|
|
||||||
controlType: 'delay',
|
|
||||||
delaySeconds: 60,
|
|
||||||
},
|
|
||||||
retry: {
|
|
||||||
label: '重试策略',
|
|
||||||
controlType: 'retry',
|
|
||||||
maxRetries: 3,
|
|
||||||
retryDelay: 5,
|
|
||||||
backoffMultiplier: 2,
|
|
||||||
},
|
|
||||||
circuit_breaker: {
|
|
||||||
label: '熔断器',
|
|
||||||
controlType: 'circuit_breaker',
|
|
||||||
failureThreshold: 3,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
logic_gates: {
|
|
||||||
and: {
|
|
||||||
label: 'AND',
|
|
||||||
gateType: 'AND',
|
|
||||||
},
|
|
||||||
or: {
|
|
||||||
label: 'OR',
|
|
||||||
gateType: 'OR',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@@ -16,7 +16,7 @@ const SaveModal = ({
|
|||||||
|
|
||||||
const handleOk = async (values: any) => {
|
const handleOk = async (values: any) => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const payload = { ...file, ...values, originFilename: file.title };
|
const payload = { ...values, originFilename: file.title, content: file.content };
|
||||||
request
|
request
|
||||||
.post(`${config.apiPrefix}scripts`, payload)
|
.post(`${config.apiPrefix}scripts`, payload)
|
||||||
.then(({ code, data }) => {
|
.then(({ code, data }) => {
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ const dataMap = {
|
|||||||
'log-remove-frequency': 'logRemoveFrequency',
|
'log-remove-frequency': 'logRemoveFrequency',
|
||||||
'cron-concurrency': 'cronConcurrency',
|
'cron-concurrency': 'cronConcurrency',
|
||||||
timezone: 'timezone',
|
timezone: 'timezone',
|
||||||
|
'global-ssh-key': 'globalSshKey',
|
||||||
};
|
};
|
||||||
|
|
||||||
const exportModules = [
|
const exportModules = [
|
||||||
@@ -54,6 +55,7 @@ const Other = ({
|
|||||||
logRemoveFrequency?: number | null;
|
logRemoveFrequency?: number | null;
|
||||||
cronConcurrency?: number | null;
|
cronConcurrency?: number | null;
|
||||||
timezone?: string | null;
|
timezone?: string | null;
|
||||||
|
globalSshKey?: string | null;
|
||||||
}>();
|
}>();
|
||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
const [exportLoading, setExportLoading] = useState(false);
|
const [exportLoading, setExportLoading] = useState(false);
|
||||||
@@ -240,6 +242,7 @@ const Other = ({
|
|||||||
addonBefore={intl.get('每')}
|
addonBefore={intl.get('每')}
|
||||||
addonAfter={intl.get('天')}
|
addonAfter={intl.get('天')}
|
||||||
style={{ width: 180 }}
|
style={{ width: 180 }}
|
||||||
|
placeholder={intl.get('未启用')}
|
||||||
min={0}
|
min={0}
|
||||||
value={systemConfig?.logRemoveFrequency}
|
value={systemConfig?.logRemoveFrequency}
|
||||||
onChange={(value) => {
|
onChange={(value) => {
|
||||||
@@ -261,8 +264,9 @@ const Other = ({
|
|||||||
<Input.Group compact>
|
<Input.Group compact>
|
||||||
<InputNumber
|
<InputNumber
|
||||||
style={{ width: 180 }}
|
style={{ width: 180 }}
|
||||||
min={1}
|
min={4}
|
||||||
value={systemConfig?.cronConcurrency}
|
value={systemConfig?.cronConcurrency}
|
||||||
|
placeholder={intl.get('默认为 CPU 个数')}
|
||||||
onChange={(value) => {
|
onChange={(value) => {
|
||||||
setSystemConfig({ ...systemConfig, cronConcurrency: value });
|
setSystemConfig({ ...systemConfig, cronConcurrency: value });
|
||||||
}}
|
}}
|
||||||
@@ -306,6 +310,32 @@ const Other = ({
|
|||||||
</Button>
|
</Button>
|
||||||
</Input.Group>
|
</Input.Group>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
label={intl.get('全局SSH私钥')}
|
||||||
|
name="globalSshKey"
|
||||||
|
tooltip={intl.get('用于访问所有私有仓库的全局SSH私钥')}
|
||||||
|
>
|
||||||
|
<Input.Group compact>
|
||||||
|
<Input.TextArea
|
||||||
|
value={systemConfig?.globalSshKey || ''}
|
||||||
|
style={{ width: 264 }}
|
||||||
|
autoSize={{ minRows: 3, maxRows: 8 }}
|
||||||
|
placeholder={intl.get('请输入完整的SSH私钥内容')}
|
||||||
|
onChange={(e) => {
|
||||||
|
setSystemConfig({ ...systemConfig, globalSshKey: e.target.value });
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Input.Group>
|
||||||
|
<Button
|
||||||
|
type="primary"
|
||||||
|
onClick={() => {
|
||||||
|
updateSystemConfig('global-ssh-key');
|
||||||
|
}}
|
||||||
|
style={{ width: 264, marginTop: 8 }}
|
||||||
|
>
|
||||||
|
{intl.get('确认')}
|
||||||
|
</Button>
|
||||||
|
</Form.Item>
|
||||||
<Form.Item label={intl.get('语言')} name="lang">
|
<Form.Item label={intl.get('语言')} name="lang">
|
||||||
<Select
|
<Select
|
||||||
defaultValue={localStorage.getItem('lang') || ''}
|
defaultValue={localStorage.getItem('lang') || ''}
|
||||||
|
|||||||
@@ -395,6 +395,12 @@ export default {
|
|||||||
),
|
),
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: 'larkSecret',
|
||||||
|
tip: intl.get(
|
||||||
|
'飞书群组机器人加签密钥,安全设置中开启签名校验后获得',
|
||||||
|
),
|
||||||
|
},
|
||||||
],
|
],
|
||||||
email: [
|
email: [
|
||||||
{
|
{
|
||||||
|
|||||||
+46
-9
@@ -1,10 +1,47 @@
|
|||||||
version: 2.19.2
|
version: 2.20.0
|
||||||
changeLogLink: https://t.me/jiao_long/431
|
changeLogLink: https://t.me/jiao_long/432
|
||||||
publishTime: 2025-06-27 23:59
|
publishTime: 2025-12-10 01:05
|
||||||
changeLog: |
|
changeLog: |
|
||||||
1. 备份数据支持选择模块,支持清除依赖缓存
|
1. 定时任务(cron / task)相关的大量修复 & 增强
|
||||||
2. QLAPI 和 openapi 的 systemNotify 支持自定义通知类型和参数
|
|
||||||
3. ntfy 增加可选的认证与用户动作,感谢 https://github.com/liheji
|
修复 cron 解析错误(修复 parse cron / 升级 cron-parser)
|
||||||
4. 修复取消安装依赖
|
修复集群模式下定时任务可能不执行(race condition)
|
||||||
5. 修复环境变量过大解析报错
|
定时任务支持订阅筛选
|
||||||
6. 修改服务启动方式
|
定时任务支持排序调整
|
||||||
|
定时任务支持自定义日志文件或无日志
|
||||||
|
修复任务实例默认值
|
||||||
|
任务支持单实例 / 多实例模式
|
||||||
|
修复 task 命令软链可能失败问题
|
||||||
|
|
||||||
|
2. 日志系统相关的大更新
|
||||||
|
|
||||||
|
修复日志目录逻辑
|
||||||
|
修复 pm2 日志目录
|
||||||
|
优化日志写入(stream pooling)
|
||||||
|
|
||||||
|
3. 环境变量(env)系统的改进与修复
|
||||||
|
|
||||||
|
修复环境变量复制到剪贴板时可能失败
|
||||||
|
添加环境变量“置顶”功能
|
||||||
|
修复 QlPort 与 QlGrpcPort 环境变量在 host network 模式下被忽略
|
||||||
|
增加全局 SSH 私钥配置
|
||||||
|
|
||||||
|
4. Docker / 非 root 用户 / Alpine 兼容性增强
|
||||||
|
|
||||||
|
新增非 root Docker 用户支持,自动初始化命令
|
||||||
|
修复 Alpine 容器 DNS 解析失败(设置 ndots:0)
|
||||||
|
修复 PM2 在 ARM 路由器(Node.js 不兼容)上的启动失败
|
||||||
|
移除 nginx(可能是考虑更轻量的镜像运行)
|
||||||
|
|
||||||
|
5. API 安全与校验增强
|
||||||
|
|
||||||
|
Dependencies GET endpoint 增加校验
|
||||||
|
Script API routes 增加输入校验
|
||||||
|
修复 JWT 认证问题
|
||||||
|
Feishu 机器人通知增加签名校验
|
||||||
|
QLAPI 增加 cron task 管理功能
|
||||||
|
修复 URIError(错误 cookie 导致白屏)
|
||||||
|
|
||||||
|
6. 系统设置
|
||||||
|
|
||||||
|
新增多终端/多平台的并发登录会话支持
|
||||||
Reference in New Issue
Block a user