mirror of
https://github.com/certd/certd.git
synced 2026-07-16 18:57:32 +08:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 83495b3213 | |||
| 5108416904 | |||
| 5589da1822 | |||
| 21e5aed3f3 | |||
| 4a88f795e1 | |||
| 604fa5be63 | |||
| 7ed1be994f | |||
| 6cc74a1c0a | |||
| 167b303fae | |||
| b91c9e4ea6 |
@@ -0,0 +1,412 @@
|
|||||||
|
# 插件依赖按需加载方案
|
||||||
|
|
||||||
|
## 背景与目标
|
||||||
|
|
||||||
|
### 当前问题
|
||||||
|
- `packages/ui/certd-server/node_modules` 包含 50+ 个插件的所有依赖,体积庞大
|
||||||
|
- 大量云厂商 SDK(AWS、阿里云、腾讯云、华为云等)只在特定插件中使用
|
||||||
|
- 用户通常只使用少数几个插件,但必须安装所有依赖
|
||||||
|
|
||||||
|
### 目标
|
||||||
|
实现依赖的按需下载和加载:
|
||||||
|
1. 插件依赖独立管理,不占用主 `node_modules` 空间
|
||||||
|
2. 只有当用户首次使用某插件时,才动态下载该插件需要的依赖
|
||||||
|
3. 依赖安装完成后,通过 `await import()` 从独立路径加载
|
||||||
|
4. 保持现有插件代码的最小改动
|
||||||
|
|
||||||
|
## 当前架构分析
|
||||||
|
|
||||||
|
### 插件加载机制
|
||||||
|
- 插件位于 `packages/ui/certd-server/src/plugins/` 下(50+ 个插件目录)
|
||||||
|
- `AutoLoadPlugins` 类在启动时扫描 `dist/plugins` 目录并动态导入
|
||||||
|
- 插件注册到不同的 registry:`accessRegistry`, `pluginRegistry`, `dnsProviderRegistry` 等
|
||||||
|
- 插件代码已经使用 `await import()` 进行懒加载(如 `await import("@aws-sdk/client-acm")`)
|
||||||
|
|
||||||
|
### 重型依赖分布
|
||||||
|
从 `packages/ui/certd-server/package.json` 分析,以下依赖体积大且仅特定插件使用:
|
||||||
|
|
||||||
|
**云厂商 SDK(按插件分组):**
|
||||||
|
- **AWS 插件**:`@aws-sdk/client-acm`, `@aws-sdk/client-cloudfront`, `@aws-sdk/client-iam`, `@aws-sdk/client-route-53`, `@aws-sdk/client-s3`, `@aws-sdk/client-sts`
|
||||||
|
- **阿里云插件**:`@alicloud/openapi-client`, `@alicloud/pop-core`, `@alicloud/tea-typescript`, `@alicloud/fc20230330` 等
|
||||||
|
- **腾讯云插件**:`tencentcloud-sdk-nodejs`, `cos-nodejs-sdk-v5`
|
||||||
|
- **华为云插件**:`@huaweicloud/huaweicloud-sdk-cdn`, `@huaweicloud/huaweicloud-sdk-core` 等
|
||||||
|
- **Azure 插件**:`@azure/arm-dns`, `@azure/identity`
|
||||||
|
- **Google Cloud 插件**:`@google-cloud/dns`, `@google-cloud/publicca`
|
||||||
|
- **火山引擎插件**:`@volcengine/openapi`, `@volcengine/tos-sdk`
|
||||||
|
|
||||||
|
**网络/工具库:**
|
||||||
|
- `ssh2`, `socks`, `socks-proxy-agent`(SSH 相关插件)
|
||||||
|
- `ali-oss`, `qiniu`, `basic-ftp`(存储/传输插件)
|
||||||
|
- `nodemailer`(邮件通知插件)
|
||||||
|
|
||||||
|
**通用依赖(保留在主 package.json):**
|
||||||
|
- `@midwayjs/*` 系列(框架核心)
|
||||||
|
- `@certd/*` 系列(项目内部包)
|
||||||
|
- `axios`, `lodash-es`, `dayjs`, `js-yaml` 等基础工具
|
||||||
|
|
||||||
|
## 设计方案
|
||||||
|
|
||||||
|
### 架构概览
|
||||||
|
|
||||||
|
```
|
||||||
|
packages/ui/certd-server/
|
||||||
|
├── package.json # 主依赖(框架、通用工具)
|
||||||
|
├── node_modules/ # 主依赖安装目录
|
||||||
|
├── optional-deps/ # 新增:可选依赖管理目录
|
||||||
|
│ ├── package.json # 可选依赖总配置(用于 pnpm install)
|
||||||
|
│ ├── pnpm-lock.yaml # 可选依赖锁文件
|
||||||
|
│ └── node_modules/ # 可选依赖安装目录
|
||||||
|
├── src/
|
||||||
|
│ └── modules/
|
||||||
|
│ └── dependency/ # 新增:依赖管理模块
|
||||||
|
│ ├── dependency-manager.ts # 核心:依赖管理器
|
||||||
|
│ ├── dependency-registry.ts # 依赖注册表(插件 -> 依赖映射)
|
||||||
|
│ └── types.ts # 类型定义
|
||||||
|
```
|
||||||
|
|
||||||
|
### 核心组件
|
||||||
|
|
||||||
|
#### 1. 依赖管理器(DependencyManager)
|
||||||
|
|
||||||
|
**职责:**
|
||||||
|
- 检查依赖是否已安装
|
||||||
|
- 动态执行 `pnpm install` 安装缺失依赖
|
||||||
|
- 提供从 `optional-deps/node_modules` 加载依赖的方法
|
||||||
|
- 并发控制:避免多个插件同时触发安装
|
||||||
|
|
||||||
|
**关键方法:**
|
||||||
|
```typescript
|
||||||
|
class DependencyManager {
|
||||||
|
// 确保依赖已安装,返回依赖模块
|
||||||
|
async ensureAndImport<T>(packageName: string): Promise<T>
|
||||||
|
|
||||||
|
// 检查依赖是否已安装
|
||||||
|
async isInstalled(packageName: string): Promise<boolean>
|
||||||
|
|
||||||
|
// 安装依赖(带锁,避免并发)
|
||||||
|
async installDependencies(packages: string[]): Promise<void>
|
||||||
|
|
||||||
|
// 从 optional-deps/node_modules 加载依赖
|
||||||
|
async loadModule<T>(packageName: string): Promise<T>
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**实现要点:**
|
||||||
|
- 使用文件锁(如 `proper-lockfile`)防止并发安装
|
||||||
|
- 安装前检查 `optional-deps/node_modules/{packageName}` 是否存在
|
||||||
|
- 安装命令:`pnpm install --dir optional-deps --ignore-workspace`
|
||||||
|
- 加载时使用绝对路径:`import('file:///absolute/path/to/optional-deps/node_modules/package')`
|
||||||
|
|
||||||
|
#### 2. 依赖注册表(DependencyRegistry)
|
||||||
|
|
||||||
|
**职责:**
|
||||||
|
- 维护插件名称到依赖列表的映射
|
||||||
|
- 提供依赖查询接口
|
||||||
|
|
||||||
|
**数据结构:**
|
||||||
|
```typescript
|
||||||
|
interface PluginDependencyConfig {
|
||||||
|
pluginName: string;
|
||||||
|
dependencies: {
|
||||||
|
packageName: string;
|
||||||
|
version: string;
|
||||||
|
optional?: boolean; // 是否可选(安装失败不阻塞)
|
||||||
|
}[];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 示例注册
|
||||||
|
dependencyRegistry.register('plugin-aws', [
|
||||||
|
{ packageName: '@aws-sdk/client-acm', version: '^3.964.0' },
|
||||||
|
{ packageName: '@aws-sdk/client-cloudfront', version: '^3.964.0' },
|
||||||
|
{ packageName: '@aws-sdk/client-route-53', version: '^3.964.0' },
|
||||||
|
]);
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 3. 插件集成
|
||||||
|
|
||||||
|
**改造现有插件代码:**
|
||||||
|
|
||||||
|
改造前(`plugin-aws/libs/aws-client.ts`):
|
||||||
|
```typescript
|
||||||
|
const { ACMClient, ImportCertificateCommand } = await import("@aws-sdk/client-acm");
|
||||||
|
```
|
||||||
|
|
||||||
|
改造后:
|
||||||
|
```typescript
|
||||||
|
import { DependencyManager } from "../../../modules/dependency/dependency-manager.js";
|
||||||
|
|
||||||
|
const depManager = new DependencyManager();
|
||||||
|
const { ACMClient, ImportCertificateCommand } = await depManager.ensureAndImport("@aws-sdk/client-acm");
|
||||||
|
```
|
||||||
|
|
||||||
|
**简化方案(推荐):**
|
||||||
|
|
||||||
|
创建辅助函数,减少改动量:
|
||||||
|
```typescript
|
||||||
|
// src/modules/dependency/import-helper.ts
|
||||||
|
export async function importOptionalDep<T>(packageName: string): Promise<T> {
|
||||||
|
const depManager = new DependencyManager();
|
||||||
|
return await depManager.ensureAndImport<T>(packageName);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 插件中使用
|
||||||
|
import { importOptionalDep } from "../../../modules/dependency/import-helper.js";
|
||||||
|
const { ACMClient } = await importOptionalDep("@aws-sdk/client-acm");
|
||||||
|
```
|
||||||
|
|
||||||
|
### 实施步骤
|
||||||
|
|
||||||
|
#### 阶段一:基础设施搭建
|
||||||
|
1. 创建 `optional-deps/` 目录结构
|
||||||
|
2. 生成 `optional-deps/package.json`(包含所有可选依赖)
|
||||||
|
3. 实现 `DependencyManager` 核心逻辑
|
||||||
|
4. 实现依赖安装锁机制
|
||||||
|
5. 编写单元测试
|
||||||
|
|
||||||
|
#### 阶段二:依赖迁移
|
||||||
|
6. 从主 `package.json` 移除可选依赖
|
||||||
|
7. 将依赖添加到 `optional-deps/package.json`
|
||||||
|
8. 创建依赖注册表,映射插件到依赖
|
||||||
|
|
||||||
|
#### 阶段三:插件改造
|
||||||
|
9. 创建 `import-helper.ts` 辅助函数
|
||||||
|
10. 逐步改造插件代码,使用 `importOptionalDep` 加载依赖
|
||||||
|
11. 优先改造重型依赖(AWS、阿里云、腾讯云等)
|
||||||
|
|
||||||
|
#### 阶段四:测试与优化
|
||||||
|
12. 端到端测试:验证依赖按需安装和加载
|
||||||
|
13. 性能优化:缓存已加载的模块
|
||||||
|
14. 错误处理:安装失败时的降级策略
|
||||||
|
15. 文档:编写使用说明和迁移指南
|
||||||
|
|
||||||
|
## 关键技术决策
|
||||||
|
|
||||||
|
### 1. 依赖分组策略
|
||||||
|
**选择:按插件分组**
|
||||||
|
- 每个插件声明自己需要的依赖
|
||||||
|
- 优点:职责清晰,易于维护
|
||||||
|
- 缺点:可能有重复依赖(但 pnpm 会去重)
|
||||||
|
|
||||||
|
**备选:按功能分组**
|
||||||
|
- 将依赖按功能分组(如 "aws-deps", "aliyun-deps")
|
||||||
|
- 优点:更细粒度控制
|
||||||
|
- 缺点:增加复杂度
|
||||||
|
|
||||||
|
### 2. 安装触发时机
|
||||||
|
**选择:首次使用时触发**
|
||||||
|
- 在插件的 `execute()` 或 `getClient()` 方法中触发安装
|
||||||
|
- 优点:真正的按需加载
|
||||||
|
- 缺点:首次使用有延迟
|
||||||
|
|
||||||
|
**备选:启动时预检查**
|
||||||
|
- 启动时扫描启用的插件,预安装依赖
|
||||||
|
- 优点:避免运行时延迟
|
||||||
|
- 缺点:可能安装不需要的依赖
|
||||||
|
|
||||||
|
### 3. 依赖路径解析
|
||||||
|
**选择:使用绝对路径 + `file://` 协议**
|
||||||
|
```typescript
|
||||||
|
const modulePath = path.resolve(__dirname, '../../optional-deps/node_modules', packageName);
|
||||||
|
return await import(`file://${modulePath}/index.js`);
|
||||||
|
```
|
||||||
|
|
||||||
|
**原因:**
|
||||||
|
- Node.js ESM 要求明确的 URL 格式
|
||||||
|
- 避免模块解析冲突
|
||||||
|
|
||||||
|
### 4. 并发控制
|
||||||
|
**选择:文件锁 + 内存锁双重保护**
|
||||||
|
- 使用 `proper-lockfile` 锁定 `optional-deps/` 目录
|
||||||
|
- 内存中使用 `Map` 记录正在安装的依赖
|
||||||
|
- 避免多个插件同时触发安装
|
||||||
|
|
||||||
|
### 5. 错误处理
|
||||||
|
**策略:**
|
||||||
|
- 安装失败时记录日志,抛出明确的错误信息
|
||||||
|
- 提供手动安装命令提示:`请运行: cd optional-deps && pnpm install`
|
||||||
|
- 支持降级:某些非核心依赖安装失败时,插件可以部分功能可用
|
||||||
|
|
||||||
|
## 验证方案
|
||||||
|
|
||||||
|
### 单元测试
|
||||||
|
1. 测试 `DependencyManager.isInstalled()` 正确检测依赖状态
|
||||||
|
2. 测试 `DependencyManager.installDependencies()` 成功安装依赖
|
||||||
|
3. 测试并发安装时的锁机制
|
||||||
|
4. 测试从 `optional-deps/node_modules` 加载模块
|
||||||
|
|
||||||
|
### 集成测试
|
||||||
|
1. 清空 `optional-deps/node_modules`
|
||||||
|
2. 启动服务,验证不触发安装
|
||||||
|
3. 调用 AWS 插件,验证触发安装并成功加载
|
||||||
|
4. 再次调用,验证不重复安装
|
||||||
|
5. 验证主 `node_modules` 体积减少
|
||||||
|
|
||||||
|
### 性能测试
|
||||||
|
1. 测量首次安装依赖的耗时
|
||||||
|
2. 测量后续加载的耗时(应该与正常 import 相近)
|
||||||
|
3. 对比改造前后的 `node_modules` 大小
|
||||||
|
|
||||||
|
## 风险与挑战
|
||||||
|
|
||||||
|
### 1. 首次使用延迟
|
||||||
|
**风险:** 用户首次使用插件时需要等待依赖安装(可能几十秒)
|
||||||
|
**缓解:**
|
||||||
|
- 在 UI 上显示安装进度
|
||||||
|
- 提供预安装命令:`pnpm run install-optional-deps`
|
||||||
|
- 文档说明首次使用会有延迟
|
||||||
|
|
||||||
|
### 2. 离线环境
|
||||||
|
**风险:** 离线环境无法下载依赖
|
||||||
|
**缓解:**
|
||||||
|
- 提供完整安装包(包含所有可选依赖)
|
||||||
|
- 支持手动复制 `node_modules`
|
||||||
|
|
||||||
|
### 3. 版本冲突
|
||||||
|
**风险:** 可选依赖与主依赖版本冲突
|
||||||
|
**缓解:**
|
||||||
|
- 使用 `--ignore-workspace` 隔离安装
|
||||||
|
- 定期同步主依赖版本
|
||||||
|
|
||||||
|
### 4. TypeScript 类型
|
||||||
|
**风险:** 动态导入的类型推断
|
||||||
|
**缓解:**
|
||||||
|
- 保留 `@types/*` 在主 `devDependencies`
|
||||||
|
- 使用泛型和类型断言
|
||||||
|
|
||||||
|
## 预期收益
|
||||||
|
|
||||||
|
1. **空间节省:** 主 `node_modules` 体积减少 60-70%(估算)
|
||||||
|
2. **安装速度:** 初始 `pnpm install` 速度提升 3-5 倍
|
||||||
|
3. **用户体验:** 不使用的插件不占用空间,按需加载
|
||||||
|
4. **维护性:** 依赖分组清晰,易于管理
|
||||||
|
|
||||||
|
## 后续优化
|
||||||
|
|
||||||
|
1. **依赖预热:** 在后台预安装常用插件依赖
|
||||||
|
2. **依赖缓存:** 支持从 CDN 或本地缓存安装
|
||||||
|
3. **依赖更新:** 提供命令批量更新可选依赖
|
||||||
|
4. **插件市场:** 支持从远程下载插件及其依赖配置
|
||||||
|
|
||||||
|
## 附录:依赖分类清单
|
||||||
|
|
||||||
|
### 可选依赖(迁移到 optional-deps/package.json)
|
||||||
|
|
||||||
|
**AWS 相关(plugin-aws, plugin-aws-cn):**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"@aws-sdk/client-acm": "^3.964.0",
|
||||||
|
"@aws-sdk/client-cloudfront": "^3.964.0",
|
||||||
|
"@aws-sdk/client-iam": "^3.964.0",
|
||||||
|
"@aws-sdk/client-route-53": "^3.964.0",
|
||||||
|
"@aws-sdk/client-s3": "^3.964.0",
|
||||||
|
"@aws-sdk/client-sts": "^3.990.0"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**阿里云相关(plugin-aliyun, plugin-lib/aliyun):**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"@alicloud/fc20230330": "^4.1.7",
|
||||||
|
"@alicloud/openapi-client": "^0.4.12",
|
||||||
|
"@alicloud/openapi-util": "^0.3.2",
|
||||||
|
"@alicloud/pop-core": "^1.7.10",
|
||||||
|
"@alicloud/sts-sdk": "^1.0.2",
|
||||||
|
"@alicloud/tea-typescript": "^1.8.0",
|
||||||
|
"@alicloud/tea-util": "^1.4.10",
|
||||||
|
"ali-oss": "^6.21.0"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**腾讯云相关(plugin-tencent, plugin-lib/tencent):**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"tencentcloud-sdk-nodejs": "^4.1.112",
|
||||||
|
"cos-nodejs-sdk-v5": "^2.14.6"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**华为云相关(plugin-huawei):**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"@huaweicloud/huaweicloud-sdk-cdn": "3.1.185",
|
||||||
|
"@huaweicloud/huaweicloud-sdk-core": "3.1.185",
|
||||||
|
"@huaweicloud/huaweicloud-sdk-elb": "3.1.185",
|
||||||
|
"@huaweicloud/huaweicloud-sdk-iam": "3.1.185",
|
||||||
|
"esdk-obs-nodejs": "^3.25.6"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Azure 相关(plugin-azure):**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"@azure/arm-dns": "^5.1.0",
|
||||||
|
"@azure/identity": "^4.13.1"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Google Cloud 相关(plugin-google, plugin-cert/google):**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"@google-cloud/dns": "^5.3.1",
|
||||||
|
"@google-cloud/publicca": "^1.3.0"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**火山引擎相关(plugin-volcengine):**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"@volcengine/openapi": "^1.28.1",
|
||||||
|
"@volcengine/tos-sdk": "^2.9.1"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**SSH/网络相关(plugin-host, plugin-lib/ssh):**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"ssh2": "^1.17.0",
|
||||||
|
"socks": "^2.8.3",
|
||||||
|
"socks-proxy-agent": "^8.0.4",
|
||||||
|
"basic-ftp": "^5.0.5"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**其他存储/传输(plugin-qiniu, plugin-lib/qiniu):**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"qiniu": "^7.12.0"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**邮件通知(plugin-notification/email):**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"nodemailer": "^6.9.16"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 主依赖(保留在主 package.json)
|
||||||
|
|
||||||
|
**框架核心:**
|
||||||
|
- `@midwayjs/*` 系列
|
||||||
|
- `@koa/cors`
|
||||||
|
- `typeorm`, `better-sqlite3`, `mysql2`, `pg`
|
||||||
|
|
||||||
|
**项目内部包:**
|
||||||
|
- `@certd/*` 系列
|
||||||
|
|
||||||
|
**通用工具:**
|
||||||
|
- `axios`, `lodash-es`, `dayjs`, `js-yaml`
|
||||||
|
- `crypto-js`, `jsonwebtoken`, `bcryptjs`
|
||||||
|
- `reflect-metadata`, `uuid`, `nanoid`
|
||||||
|
- 等等
|
||||||
|
|
||||||
|
## 总结
|
||||||
|
|
||||||
|
本方案通过引入独立的可选依赖管理机制,实现了插件依赖的按需下载和加载。核心思路是:
|
||||||
|
|
||||||
|
1. **隔离管理:** 在 `optional-deps/` 目录下维护独立的 `package.json` 和 `node_modules`
|
||||||
|
2. **动态安装:** 通过 `DependencyManager` 在首次使用时触发 `pnpm install`
|
||||||
|
3. **路径加载:** 使用绝对路径从独立目录加载依赖模块
|
||||||
|
4. **最小改动:** 通过辅助函数 `importOptionalDep` 简化插件代码改造
|
||||||
|
|
||||||
|
该方案可以显著减少主 `node_modules` 体积,提升初始安装速度,同时保持现有架构的兼容性和可维护性。
|
||||||
@@ -212,29 +212,6 @@ Certd 是可私有化部署的 SSL/TLS 证书自动化管理平台,提供 Web
|
|||||||
|
|
||||||
## 注意事项
|
## 注意事项
|
||||||
|
|
||||||
|
|
||||||
### 换行符(LF / CRLF)
|
|
||||||
|
|
||||||
- 本项目源码使用 **LF** 换行符。Windows 上通过 Python 写文件时,open(path, "w", encoding="utf-8") 默认使用 **CRLF**,会破坏文件格式。
|
|
||||||
- **修复方案**:写文件时用 open(path, "w", encoding="utf-8", newline="\n") 明确指定 LF。
|
|
||||||
- 如果已经写入 CRLF,用以下 PowerShell 修复:
|
|
||||||
`powershell
|
|
||||||
git add --renormalize . && git commit -m "fix line endings"
|
|
||||||
`
|
|
||||||
### 旧版数据兼容
|
### 旧版数据兼容
|
||||||
|
|
||||||
- 新增插件参数时,必须要考虑旧版数据兼容,比如新增一个deployType参数,有两种值:`default`和`custom`,需要在使用时判空,走旧版逻辑。
|
- 新增插件参数时,必须要考虑旧版数据兼容,比如新增一个deployType参数,有两种值:`default`和`custom`,需要在使用时判空,走旧版逻辑。
|
||||||
|
|
||||||
## 前端路由与国际化
|
|
||||||
|
|
||||||
- 路由 `meta.title` 是 **i18n 国际化 key**,必须在 `src/locales/langs/zh-CN/` 和 `src/locales/langs/en-US/` 对应的模块文件中添加翻译。
|
|
||||||
- 示例:路由 `title: "certd.auditLog"` 需要在中英 locales 文件中有对应 key(`"certd.auditLog": "操作日志"` / `"certd.auditLog": "Audit Log"`)。
|
|
||||||
- 菜单通过路由自动生成,需设置 `meta.isMenu: true` 才会出现在左侧菜单。
|
|
||||||
- Plus 版功能菜单需设置 `meta.show: () => { const settingStore = useSettingStore(); return settingStore.isPlus; }`。
|
|
||||||
|
|
||||||
## 审计日志
|
|
||||||
|
|
||||||
- 审计日志是 Plus 版功能,非 Plus 版不会写入。
|
|
||||||
- Controller 继承 `BaseController`,通过 `this.auditLog({ content: "xxx" })` 记录日志。
|
|
||||||
- `getAuditType()` 返回类型常量,中间件自动从 ctx.path 判定 scope(`/api/sys/` → system,其他 → user)。
|
|
||||||
- 操作日志有系统级(scope=system)和用户级(scope=user)区分。
|
|
||||||
@@ -3,6 +3,18 @@
|
|||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||||
|
|
||||||
|
## [1.42.5](https://github.com/certd/certd/compare/v1.42.4...v1.42.5) (2026-07-15)
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* 修复上传到cos报runtimeDepsService未初始化的问题 ([167b303](https://github.com/certd/certd/commit/167b303faeca02cc11cf97e4be2a3df914852167))
|
||||||
|
* 修复dingtalk通知格式没有换行的bug ([7ed1be9](https://github.com/certd/certd/commit/7ed1be994f8b4b74cdeb38743060c912c027248b))
|
||||||
|
|
||||||
|
### Performance Improvements
|
||||||
|
|
||||||
|
* 给SQLITE_IOERR_WRITE增加友好报错提示,将certd:latest镜像改为certd:slim ([b91c9e4](https://github.com/certd/certd/commit/b91c9e4ea671cb359ef164e27864de1d66cba9d3))
|
||||||
|
* 优化vke keubconfig获取方式,改成先查询,如果没有再创建临时config ([604fa5b](https://github.com/certd/certd/commit/604fa5be634d099d797bfee5c2b0f26ce0ac8461))
|
||||||
|
|
||||||
## [1.42.4](https://github.com/certd/certd/compare/v1.42.3...v1.42.4) (2026-07-11)
|
## [1.42.4](https://github.com/certd/certd/compare/v1.42.3...v1.42.4) (2026-07-11)
|
||||||
|
|
||||||
### Bug Fixes
|
### Bug Fixes
|
||||||
|
|||||||
+1
-1
@@ -9,5 +9,5 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"npmClient": "pnpm",
|
"npmClient": "pnpm",
|
||||||
"version": "1.42.4"
|
"version": "1.42.5"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,7 @@
|
|||||||
"test:unit": "cross-env NODE_ENV=unittest pnpm -r --workspace-concurrency=1 run test:unit",
|
"test:unit": "cross-env NODE_ENV=unittest pnpm -r --workspace-concurrency=1 run test:unit",
|
||||||
"pub": "echo 1",
|
"pub": "echo 1",
|
||||||
"dev": "pnpm run -r --parallel compile ",
|
"dev": "pnpm run -r --parallel compile ",
|
||||||
|
"lint_all": "pnpm run -r --parallel lint ",
|
||||||
"pub_all": "node ./scripts/pub-all.js",
|
"pub_all": "node ./scripts/pub-all.js",
|
||||||
"release": "time /t >trigger/release.trigger && git add trigger/release.trigger && git commit -m \"build: release\" && git push",
|
"release": "time /t >trigger/release.trigger && git add trigger/release.trigger && git commit -m \"build: release\" && git push",
|
||||||
"publish_to_atomgit": "node --experimental-json-modules ./scripts/publish-atomgit.js",
|
"publish_to_atomgit": "node --experimental-json-modules ./scripts/publish-atomgit.js",
|
||||||
|
|||||||
@@ -3,6 +3,10 @@
|
|||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||||
|
|
||||||
|
## [1.42.5](https://github.com/publishlab/node-acme-client/compare/v1.42.4...v1.42.5) (2026-07-15)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @certd/acme-client
|
||||||
|
|
||||||
## [1.42.4](https://github.com/publishlab/node-acme-client/compare/v1.42.3...v1.42.4) (2026-07-11)
|
## [1.42.4](https://github.com/publishlab/node-acme-client/compare/v1.42.3...v1.42.4) (2026-07-11)
|
||||||
|
|
||||||
**Note:** Version bump only for package @certd/acme-client
|
**Note:** Version bump only for package @certd/acme-client
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
"description": "Simple and unopinionated ACME client",
|
"description": "Simple and unopinionated ACME client",
|
||||||
"private": false,
|
"private": false,
|
||||||
"author": "nmorsman",
|
"author": "nmorsman",
|
||||||
"version": "1.42.4",
|
"version": "1.42.5",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"module": "./dist/index.js",
|
"module": "./dist/index.js",
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
"types"
|
"types"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@certd/basic": "^1.42.4",
|
"@certd/basic": "^1.42.5",
|
||||||
"@peculiar/x509": "^1.11.0",
|
"@peculiar/x509": "^1.11.0",
|
||||||
"asn1js": "^3.0.5",
|
"asn1js": "^3.0.5",
|
||||||
"axios": "^1.9.0",
|
"axios": "^1.9.0",
|
||||||
|
|||||||
@@ -3,6 +3,10 @@
|
|||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||||
|
|
||||||
|
## [1.42.5](https://github.com/certd/certd/compare/v1.42.4...v1.42.5) (2026-07-15)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @certd/basic
|
||||||
|
|
||||||
## [1.42.4](https://github.com/certd/certd/compare/v1.42.3...v1.42.4) (2026-07-11)
|
## [1.42.4](https://github.com/certd/certd/compare/v1.42.3...v1.42.4) (2026-07-11)
|
||||||
|
|
||||||
**Note:** Version bump only for package @certd/basic
|
**Note:** Version bump only for package @certd/basic
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
02:45
|
23:31
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@certd/basic",
|
"name": "@certd/basic",
|
||||||
"private": false,
|
"private": false,
|
||||||
"version": "1.42.4",
|
"version": "1.42.5",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
"module": "./dist/index.js",
|
"module": "./dist/index.js",
|
||||||
|
|||||||
@@ -3,6 +3,16 @@
|
|||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||||
|
|
||||||
|
## [1.42.5](https://github.com/certd/certd/compare/v1.42.4...v1.42.5) (2026-07-15)
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* 修复上传到cos报runtimeDepsService未初始化的问题 ([167b303](https://github.com/certd/certd/commit/167b303faeca02cc11cf97e4be2a3df914852167))
|
||||||
|
|
||||||
|
### Performance Improvements
|
||||||
|
|
||||||
|
* 优化vke keubconfig获取方式,改成先查询,如果没有再创建临时config ([604fa5b](https://github.com/certd/certd/commit/604fa5be634d099d797bfee5c2b0f26ce0ac8461))
|
||||||
|
|
||||||
## [1.42.4](https://github.com/certd/certd/compare/v1.42.3...v1.42.4) (2026-07-11)
|
## [1.42.4](https://github.com/certd/certd/compare/v1.42.3...v1.42.4) (2026-07-11)
|
||||||
|
|
||||||
### Bug Fixes
|
### Bug Fixes
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@certd/pipeline",
|
"name": "@certd/pipeline",
|
||||||
"private": false,
|
"private": false,
|
||||||
"version": "1.42.4",
|
"version": "1.42.5",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
"module": "./dist/index.js",
|
"module": "./dist/index.js",
|
||||||
@@ -21,8 +21,8 @@
|
|||||||
"lint": "eslint --fix"
|
"lint": "eslint --fix"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@certd/basic": "^1.42.4",
|
"@certd/basic": "^1.42.5",
|
||||||
"@certd/plus-core": "^1.42.4",
|
"@certd/plus-core": "^1.42.5",
|
||||||
"dayjs": "^1.11.7",
|
"dayjs": "^1.11.7",
|
||||||
"lodash-es": "^4.17.21",
|
"lodash-es": "^4.17.21",
|
||||||
"reflect-metadata": "^0.2.2"
|
"reflect-metadata": "^0.2.2"
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { FormItemProps } from "../dt/index.js";
|
|||||||
import { HttpClient, ILogger, utils } from "@certd/basic";
|
import { HttpClient, ILogger, utils } from "@certd/basic";
|
||||||
import * as _ from "lodash-es";
|
import * as _ from "lodash-es";
|
||||||
import { PluginRequestHandleReq } from "../plugin/index.js";
|
import { PluginRequestHandleReq } from "../plugin/index.js";
|
||||||
import { IRuntimeDepsService, IServiceGetter } from "../service/index.js";
|
import { IServiceGetter, getRuntimeDepsService } from "../service/index.js";
|
||||||
|
|
||||||
// export type AccessRequestHandleReqInput<T = any> = {
|
// export type AccessRequestHandleReqInput<T = any> = {
|
||||||
// id?: number;
|
// id?: number;
|
||||||
@@ -48,20 +48,13 @@ export type AccessContext = {
|
|||||||
|
|
||||||
export abstract class BaseAccess implements IAccess {
|
export abstract class BaseAccess implements IAccess {
|
||||||
ctx!: AccessContext;
|
ctx!: AccessContext;
|
||||||
runtimeDepsService?: IRuntimeDepsService;
|
|
||||||
|
|
||||||
async importRuntime(specifier: string) {
|
async importRuntime(specifier: string) {
|
||||||
if (!this.runtimeDepsService) {
|
return await getRuntimeDepsService().importRuntime(specifier, this.ctx.logger);
|
||||||
throw new Error("runtimeDepsService 未初始化");
|
|
||||||
}
|
|
||||||
return await this.runtimeDepsService.importRuntime(specifier, this.ctx.logger);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async setCtx(ctx: AccessContext) {
|
async setCtx(ctx: AccessContext) {
|
||||||
this.ctx = ctx;
|
this.ctx = ctx;
|
||||||
if (!this.runtimeDepsService && this.ctx.serviceGetter) {
|
|
||||||
this.runtimeDepsService = await this.ctx.serviceGetter.get("runtimeDepsService");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async onRequest(req: AccessRequestHandleReq) {
|
async onRequest(req: AccessRequestHandleReq) {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { Registrable } from "../registry/index.js";
|
|||||||
import { FormItemProps, HistoryResult, Pipeline } from "../dt/index.js";
|
import { FormItemProps, HistoryResult, Pipeline } from "../dt/index.js";
|
||||||
import { HttpClient, ILogger, utils } from "@certd/basic";
|
import { HttpClient, ILogger, utils } from "@certd/basic";
|
||||||
import * as _ from "lodash-es";
|
import * as _ from "lodash-es";
|
||||||
import { IEmailService, IRuntimeDepsService, IServiceGetter } from "../service/index.js";
|
import { IEmailService, IServiceGetter, getRuntimeDepsService } from "../service/index.js";
|
||||||
|
|
||||||
export type NotificationBody = {
|
export type NotificationBody = {
|
||||||
userId?: number;
|
userId?: number;
|
||||||
@@ -89,16 +89,16 @@ export abstract class BaseNotification implements INotification {
|
|||||||
ctx!: NotificationContext;
|
ctx!: NotificationContext;
|
||||||
http!: HttpClient;
|
http!: HttpClient;
|
||||||
logger!: ILogger;
|
logger!: ILogger;
|
||||||
runtimeDepsService?: IRuntimeDepsService;
|
|
||||||
|
|
||||||
async importRuntime(specifier: string) {
|
async importRuntime(specifier: string) {
|
||||||
if (!this.runtimeDepsService) {
|
return await getRuntimeDepsService().importRuntime(specifier, this.logger);
|
||||||
return await import(specifier);
|
|
||||||
}
|
|
||||||
return await this.runtimeDepsService.importRuntime(specifier, this.logger);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async doSend(body: NotificationBody) {
|
async doSend(body: NotificationBody) {
|
||||||
|
if (body.content) {
|
||||||
|
const content = body.content?.replace(/\n/g, " \n");
|
||||||
|
body.content = content;
|
||||||
|
}
|
||||||
return await this.send(body);
|
return await this.send(body);
|
||||||
}
|
}
|
||||||
abstract send(body: NotificationBody): Promise<void>;
|
abstract send(body: NotificationBody): Promise<void>;
|
||||||
@@ -109,9 +109,6 @@ export abstract class BaseNotification implements INotification {
|
|||||||
this.ctx = ctx;
|
this.ctx = ctx;
|
||||||
this.http = ctx.http;
|
this.http = ctx.http;
|
||||||
this.logger = ctx.logger;
|
this.logger = ctx.logger;
|
||||||
if (!this.runtimeDepsService && this.ctx.serviceGetter) {
|
|
||||||
this.runtimeDepsService = await this.ctx.serviceGetter.get("runtimeDepsService");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
setDefine = (define: NotificationDefine) => {
|
setDefine = (define: NotificationDefine) => {
|
||||||
this.define = define;
|
this.define = define;
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import { INotificationService } from "../notification/index.js";
|
|||||||
import { Registrable } from "../registry/index.js";
|
import { Registrable } from "../registry/index.js";
|
||||||
import { IPluginConfigService } from "../service/config.js";
|
import { IPluginConfigService } from "../service/config.js";
|
||||||
import { TaskEmitter } from "../service/emit.js";
|
import { TaskEmitter } from "../service/emit.js";
|
||||||
import { ICnameProxyService, IEmailService, IRuntimeDepsService, IServiceGetter, IUrlService } from "../service/index.js";
|
import { ICnameProxyService, IEmailService, IServiceGetter, IUrlService, getRuntimeDepsService } from "../service/index.js";
|
||||||
|
|
||||||
export type PluginRequestHandleReq<T = any> = {
|
export type PluginRequestHandleReq<T = any> = {
|
||||||
typeName: string;
|
typeName: string;
|
||||||
@@ -76,7 +76,7 @@ export type ITaskPlugin = {
|
|||||||
execute(): Promise<void | string>;
|
execute(): Promise<void | string>;
|
||||||
onRequest(req: PluginRequestHandleReq<any>): Promise<any>;
|
onRequest(req: PluginRequestHandleReq<any>): Promise<any>;
|
||||||
setCtx(ctx: TaskInstanceContext): Promise<void>;
|
setCtx(ctx: TaskInstanceContext): Promise<void>;
|
||||||
importRuntime?(specifier: string): Promise<any>;
|
importRuntime(specifier: string): Promise<any>;
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -150,13 +150,9 @@ export abstract class AbstractTaskPlugin implements ITaskPlugin {
|
|||||||
logger!: ILogger;
|
logger!: ILogger;
|
||||||
http!: HttpClient;
|
http!: HttpClient;
|
||||||
accessService!: IAccessService;
|
accessService!: IAccessService;
|
||||||
runtimeDepsService!: IRuntimeDepsService;
|
|
||||||
|
|
||||||
async importRuntime(specifier: string) {
|
async importRuntime(specifier: string) {
|
||||||
if (!this.runtimeDepsService) {
|
return await getRuntimeDepsService().importRuntime(specifier, this.logger);
|
||||||
throw new Error("runtimeDepsService 未初始化");
|
|
||||||
}
|
|
||||||
return await this.runtimeDepsService.importRuntime(specifier, this.logger);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
clearLastStatus() {
|
clearLastStatus() {
|
||||||
@@ -178,9 +174,6 @@ export abstract class AbstractTaskPlugin implements ITaskPlugin {
|
|||||||
this.logger = ctx.logger;
|
this.logger = ctx.logger;
|
||||||
this.accessService = ctx.accessService;
|
this.accessService = ctx.accessService;
|
||||||
this.http = ctx.http;
|
this.http = ctx.http;
|
||||||
if (!this.runtimeDepsService && this.ctx.serviceGetter) {
|
|
||||||
this.runtimeDepsService = await this.ctx.serviceGetter.get("runtimeDepsService");
|
|
||||||
}
|
|
||||||
// 将证书加入secret
|
// 将证书加入secret
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
if (this.cert && this.cert.crt && this.cert.key) {
|
if (this.cert && this.cert.crt && this.cert.key) {
|
||||||
|
|||||||
+57
-222
@@ -1,38 +1,35 @@
|
|||||||
import assert from "assert";
|
import assert from "assert";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import os from "os";
|
import os from "os";
|
||||||
import { RuntimeDepsService, type RuntimeDependencyPluginDefine } from "./runtime-deps-service.js";
|
import { RuntimeDepsService, NpmRegistryResolver, type RuntimeDependencyPluginDefine } from "./runtime.js";
|
||||||
import { accessRegistry, pluginRegistry } from "@certd/pipeline";
|
import { accessRegistry } from "../access/registry.js";
|
||||||
import { addonRegistry } from "@certd/lib-server";
|
import { pluginRegistry } from "../plugin/registry.js";
|
||||||
|
|
||||||
describe("RuntimeDepsService", () => {
|
describe("RuntimeDepsService", () => {
|
||||||
it("detects conflicting dependency ranges across plugins", () => {
|
it("detects conflicting dependency ranges across plugins", () => {
|
||||||
const service = new RuntimeDepsService();
|
const service = new RuntimeDepsService({}, null);
|
||||||
const merged = service.collectDependencies([
|
const merged = service.collectDependencies([
|
||||||
{ name: "a", dependPackages: { foo: "^1.0.0" } },
|
{ name: "a", dependPackages: { foo: "^1.0.0" } },
|
||||||
{ name: "b", dependPackages: { foo: "^1.2.0" } },
|
{ name: "b", dependPackages: { foo: "^1.2.0" } },
|
||||||
]);
|
]);
|
||||||
|
|
||||||
assert.deepEqual(merged.dependencies, { foo: "^1.0.0" });
|
assert.deepEqual(merged.dependencies, { foo: "^1.0.0" });
|
||||||
assert.equal(merged.conflicts.length, 0);
|
assert.equal(merged.conflicts.length, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("reports incompatible dependency ranges", () => {
|
it("reports incompatible dependency ranges", () => {
|
||||||
const service = new RuntimeDepsService();
|
const service = new RuntimeDepsService({}, null);
|
||||||
const merged = service.collectDependencies([
|
const merged = service.collectDependencies([
|
||||||
{ name: "a", dependPackages: { foo: "^1.0.0" } },
|
{ name: "a", dependPackages: { foo: "^1.0.0" } },
|
||||||
{ name: "b", dependPackages: { foo: "^2.0.0" } },
|
{ name: "b", dependPackages: { foo: "^2.0.0" } },
|
||||||
]);
|
]);
|
||||||
|
|
||||||
assert.equal(merged.conflicts.length, 1);
|
assert.equal(merged.conflicts.length, 1);
|
||||||
assert.equal(merged.conflicts[0].packageName, "foo");
|
assert.equal(merged.conflicts[0].packageName, "foo");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("builds a runtime package manifest in the target directory", async () => {
|
it("builds a runtime package manifest in the target directory", async () => {
|
||||||
const rootDir = fs.mkdtempSync(path.join(os.tmpdir(), "certd-runtime-deps-"));
|
const rootDir = fs.mkdtempSync(path.join(os.tmpdir(), "certd-runtime-deps-"));
|
||||||
const service = new RuntimeDepsService();
|
const service = new RuntimeDepsService({ rootDir }, null);
|
||||||
service.runtimeDepsRootDir = rootDir;
|
|
||||||
service.registryResolver = {
|
service.registryResolver = {
|
||||||
async resolve() {
|
async resolve() {
|
||||||
return "https://registry.npmmirror.com";
|
return "https://registry.npmmirror.com";
|
||||||
@@ -50,18 +47,15 @@ describe("RuntimeDepsService", () => {
|
|||||||
return { stdout: "", stderr: "", code: 0 };
|
return { stdout: "", stderr: "", code: 0 };
|
||||||
},
|
},
|
||||||
} as any;
|
} as any;
|
||||||
|
|
||||||
const plugins: RuntimeDependencyPluginDefine[] = [{ name: "a", dependPackages: { foo: "^1.0.0" } }];
|
const plugins: RuntimeDependencyPluginDefine[] = [{ name: "a", dependPackages: { foo: "^1.0.0" } }];
|
||||||
const result = await service.ensureInstalled({ plugins });
|
const result = await service.ensureInstalled({ plugins });
|
||||||
|
|
||||||
assert.equal(result.registryUrl, "https://registry.npmmirror.com");
|
assert.equal(result.registryUrl, "https://registry.npmmirror.com");
|
||||||
assert.ok(fs.existsSync(path.join(rootDir, "package.json")));
|
assert.ok(fs.existsSync(path.join(rootDir, "package.json")));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("installs direct dependency maps without plugin metadata", async () => {
|
it("installs direct dependency maps without plugin metadata", async () => {
|
||||||
const rootDir = fs.mkdtempSync(path.join(os.tmpdir(), "certd-runtime-deps-direct-"));
|
const rootDir = fs.mkdtempSync(path.join(os.tmpdir(), "certd-runtime-deps-direct-"));
|
||||||
const service = new RuntimeDepsService();
|
const service = new RuntimeDepsService({ rootDir }, null);
|
||||||
service.runtimeDepsRootDir = rootDir;
|
|
||||||
service.registryResolver = {
|
service.registryResolver = {
|
||||||
async resolve() {
|
async resolve() {
|
||||||
return "";
|
return "";
|
||||||
@@ -77,9 +71,7 @@ describe("RuntimeDepsService", () => {
|
|||||||
return { stdout: "", stderr: "", code: 0 };
|
return { stdout: "", stderr: "", code: 0 };
|
||||||
},
|
},
|
||||||
} as any;
|
} as any;
|
||||||
|
|
||||||
await service.ensureDependencies({ dependencies: { directPkg: "^1.0.0" } });
|
await service.ensureDependencies({ dependencies: { directPkg: "^1.0.0" } });
|
||||||
|
|
||||||
const manifest = JSON.parse(fs.readFileSync(path.join(rootDir, "package.json"), "utf8"));
|
const manifest = JSON.parse(fs.readFileSync(path.join(rootDir, "package.json"), "utf8"));
|
||||||
assert.deepEqual(manifest.dependencies, { directPkg: "^1.0.0" });
|
assert.deepEqual(manifest.dependencies, { directPkg: "^1.0.0" });
|
||||||
});
|
});
|
||||||
@@ -91,27 +83,19 @@ describe("RuntimeDepsService", () => {
|
|||||||
fs.writeFileSync(path.join(rootDir, "package.json"), JSON.stringify({ name: "runtime-root", type: "module" }), "utf8");
|
fs.writeFileSync(path.join(rootDir, "package.json"), JSON.stringify({ name: "runtime-root", type: "module" }), "utf8");
|
||||||
fs.writeFileSync(path.join(packageDir, "package.json"), JSON.stringify({ name: "runtime-only", type: "module", main: "index.js" }), "utf8");
|
fs.writeFileSync(path.join(packageDir, "package.json"), JSON.stringify({ name: "runtime-only", type: "module", main: "index.js" }), "utf8");
|
||||||
fs.writeFileSync(path.join(packageDir, "index.js"), "export const value = 42;\n", "utf8");
|
fs.writeFileSync(path.join(packageDir, "index.js"), "export const value = 42;\n", "utf8");
|
||||||
|
const service = new RuntimeDepsService({ rootDir }, null);
|
||||||
const service = new RuntimeDepsService();
|
|
||||||
service.runtimeDepsRootDir = rootDir;
|
|
||||||
service.commandRunner = {
|
service.commandRunner = {
|
||||||
async run() {
|
async run() {
|
||||||
throw new Error("install should not run");
|
throw new Error("install should not run");
|
||||||
},
|
},
|
||||||
} as any;
|
} as any;
|
||||||
|
|
||||||
const mod = await service.importRuntime("runtime-only");
|
const mod = await service.importRuntime("runtime-only");
|
||||||
|
|
||||||
assert.equal(mod.value, 42);
|
assert.equal(mod.value, 42);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("installs configured lazy dependency when import target is missing", async () => {
|
it("installs configured lazy dependency when import target is missing", async () => {
|
||||||
const rootDir = fs.mkdtempSync(path.join(os.tmpdir(), "certd-runtime-deps-lazy-"));
|
const rootDir = fs.mkdtempSync(path.join(os.tmpdir(), "certd-runtime-deps-lazy-"));
|
||||||
const service = new RuntimeDepsService();
|
const service = new RuntimeDepsService({ rootDir, lazyDependencies: { "lazy-pkg": "^1.2.3" } }, null);
|
||||||
service.runtimeDepsRootDir = rootDir;
|
|
||||||
service.lazyDependencies = {
|
|
||||||
"lazy-pkg": "^1.2.3",
|
|
||||||
};
|
|
||||||
service.registryResolver = {
|
service.registryResolver = {
|
||||||
async resolve() {
|
async resolve() {
|
||||||
return "";
|
return "";
|
||||||
@@ -130,9 +114,7 @@ describe("RuntimeDepsService", () => {
|
|||||||
return { stdout: "", stderr: "", code: 0 };
|
return { stdout: "", stderr: "", code: 0 };
|
||||||
},
|
},
|
||||||
} as any;
|
} as any;
|
||||||
|
|
||||||
const mod = await service.importRuntime("lazy-pkg/sub/entry.js");
|
const mod = await service.importRuntime("lazy-pkg/sub/entry.js");
|
||||||
|
|
||||||
const manifest = JSON.parse(fs.readFileSync(path.join(rootDir, "package.json"), "utf8"));
|
const manifest = JSON.parse(fs.readFileSync(path.join(rootDir, "package.json"), "utf8"));
|
||||||
assert.deepEqual(manifest.dependencies, { "lazy-pkg": "^1.2.3" });
|
assert.deepEqual(manifest.dependencies, { "lazy-pkg": "^1.2.3" });
|
||||||
assert.equal(mod.value, 7);
|
assert.equal(mod.value, 7);
|
||||||
@@ -140,11 +122,7 @@ describe("RuntimeDepsService", () => {
|
|||||||
|
|
||||||
it("resolves scoped package names for lazy imports", async () => {
|
it("resolves scoped package names for lazy imports", async () => {
|
||||||
const rootDir = fs.mkdtempSync(path.join(os.tmpdir(), "certd-runtime-deps-scoped-"));
|
const rootDir = fs.mkdtempSync(path.join(os.tmpdir(), "certd-runtime-deps-scoped-"));
|
||||||
const service = new RuntimeDepsService();
|
const service = new RuntimeDepsService({ rootDir, lazyDependencies: { "@scope/lazy": "^2.0.0" } }, null);
|
||||||
service.runtimeDepsRootDir = rootDir;
|
|
||||||
service.lazyDependencies = {
|
|
||||||
"@scope/lazy": "^2.0.0",
|
|
||||||
};
|
|
||||||
service.registryResolver = {
|
service.registryResolver = {
|
||||||
async resolve() {
|
async resolve() {
|
||||||
return "";
|
return "";
|
||||||
@@ -163,9 +141,7 @@ describe("RuntimeDepsService", () => {
|
|||||||
return { stdout: "", stderr: "", code: 0 };
|
return { stdout: "", stderr: "", code: 0 };
|
||||||
},
|
},
|
||||||
} as any;
|
} as any;
|
||||||
|
|
||||||
const mod = await service.importRuntime("@scope/lazy/dist/index.js");
|
const mod = await service.importRuntime("@scope/lazy/dist/index.js");
|
||||||
|
|
||||||
const manifest = JSON.parse(fs.readFileSync(path.join(rootDir, "package.json"), "utf8"));
|
const manifest = JSON.parse(fs.readFileSync(path.join(rootDir, "package.json"), "utf8"));
|
||||||
assert.deepEqual(manifest.dependencies, { "@scope/lazy": "^2.0.0" });
|
assert.deepEqual(manifest.dependencies, { "@scope/lazy": "^2.0.0" });
|
||||||
assert.equal(mod.scoped, true);
|
assert.equal(mod.scoped, true);
|
||||||
@@ -173,55 +149,20 @@ describe("RuntimeDepsService", () => {
|
|||||||
|
|
||||||
it("reports missing lazy dependency configuration", async () => {
|
it("reports missing lazy dependency configuration", async () => {
|
||||||
const rootDir = fs.mkdtempSync(path.join(os.tmpdir(), "certd-runtime-deps-lazy-missing-"));
|
const rootDir = fs.mkdtempSync(path.join(os.tmpdir(), "certd-runtime-deps-lazy-missing-"));
|
||||||
const service = new RuntimeDepsService();
|
const service = new RuntimeDepsService({ rootDir, lazyDependencies: {} }, null);
|
||||||
service.runtimeDepsRootDir = rootDir;
|
|
||||||
service.lazyDependencies = {};
|
|
||||||
|
|
||||||
await assert.rejects(() => service.importRuntime("missing-pkg/sub.js"), /未配置懒加载版本: missing-pkg/);
|
await assert.rejects(() => service.importRuntime("missing-pkg/sub.js"), /未配置懒加载版本: missing-pkg/);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("falls back to project node_modules when lazy dependency is not configured", async () => {
|
it("falls back to project node_modules when lazy dependency is not configured", async () => {
|
||||||
const rootDir = fs.mkdtempSync(path.join(os.tmpdir(), "certd-runtime-deps-project-fallback-"));
|
const rootDir = fs.mkdtempSync(path.join(os.tmpdir(), "certd-runtime-deps-project-fallback-"));
|
||||||
const service = new RuntimeDepsService();
|
const service = new RuntimeDepsService({ rootDir, lazyDependencies: {} }, null);
|
||||||
service.runtimeDepsRootDir = rootDir;
|
|
||||||
service.lazyDependencies = {};
|
|
||||||
|
|
||||||
const mod = await service.importRuntime("dayjs");
|
const mod = await service.importRuntime("dayjs");
|
||||||
|
|
||||||
assert.equal(typeof mod.default, "function");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("falls back to project node_modules when lazy install fails", async () => {
|
|
||||||
const rootDir = fs.mkdtempSync(path.join(os.tmpdir(), "certd-runtime-deps-project-fallback-install-"));
|
|
||||||
const service = new RuntimeDepsService();
|
|
||||||
service.runtimeDepsRootDir = rootDir;
|
|
||||||
service.lazyDependencies = {
|
|
||||||
dayjs: "^1.11.7",
|
|
||||||
};
|
|
||||||
service.registryResolver = {
|
|
||||||
async resolve() {
|
|
||||||
return "";
|
|
||||||
},
|
|
||||||
} as any;
|
|
||||||
service.commandRunner = {
|
|
||||||
async run(command: string, args: string[]) {
|
|
||||||
assert.equal(command, "pnpm");
|
|
||||||
if (args.includes("--version")) {
|
|
||||||
return { stdout: "9.1.0\n", stderr: "", code: 0 };
|
|
||||||
}
|
|
||||||
return { stdout: "", stderr: "install failed in test", code: 1 };
|
|
||||||
},
|
|
||||||
} as any;
|
|
||||||
|
|
||||||
const mod = await service.importRuntime("dayjs");
|
|
||||||
|
|
||||||
assert.equal(typeof mod.default, "function");
|
assert.equal(typeof mod.default, "function");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("keeps previously installed dependencies when installing a later plugin", async () => {
|
it("keeps previously installed dependencies when installing a later plugin", async () => {
|
||||||
const rootDir = fs.mkdtempSync(path.join(os.tmpdir(), "certd-runtime-deps-merge-"));
|
const rootDir = fs.mkdtempSync(path.join(os.tmpdir(), "certd-runtime-deps-merge-"));
|
||||||
const service = new RuntimeDepsService();
|
const service = new RuntimeDepsService({ rootDir }, null);
|
||||||
service.runtimeDepsRootDir = rootDir;
|
|
||||||
service.registryResolver = {
|
service.registryResolver = {
|
||||||
async resolve() {
|
async resolve() {
|
||||||
return "";
|
return "";
|
||||||
@@ -237,22 +178,17 @@ describe("RuntimeDepsService", () => {
|
|||||||
return { stdout: "", stderr: "", code: 0 };
|
return { stdout: "", stderr: "", code: 0 };
|
||||||
},
|
},
|
||||||
} as any;
|
} as any;
|
||||||
|
|
||||||
await service.ensureInstalled({ plugins: [{ name: "a", pluginType: "deploy", dependPackages: { foo: "^1.0.0" } }] });
|
await service.ensureInstalled({ plugins: [{ name: "a", pluginType: "deploy", dependPackages: { foo: "^1.0.0" } }] });
|
||||||
await service.ensureInstalled({ plugins: [{ name: "b", pluginType: "deploy", dependPackages: { bar: "^2.0.0" } }] });
|
await service.ensureInstalled({ plugins: [{ name: "b", pluginType: "deploy", dependPackages: { bar: "^2.0.0" } }] });
|
||||||
|
|
||||||
const manifest = JSON.parse(fs.readFileSync(path.join(rootDir, "package.json"), "utf8"));
|
const manifest = JSON.parse(fs.readFileSync(path.join(rootDir, "package.json"), "utf8"));
|
||||||
assert.deepEqual(manifest.dependencies, {
|
assert.deepEqual(manifest.dependencies, { foo: "^1.0.0", bar: "^2.0.0" });
|
||||||
foo: "^1.0.0",
|
|
||||||
bar: "^2.0.0",
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("includes npm dependencies from dependent plugins", () => {
|
it("includes npm dependencies from dependent plugins", async () => {
|
||||||
const service = new RuntimeDepsService();
|
const service = new RuntimeDepsService({}, { accessRegistry, pluginRegistry });
|
||||||
accessRegistry.register("runtimeDepsAccess", {
|
accessRegistry.register("runtimeDepsAccess", {
|
||||||
define: { name: "runtimeDepsAccess", title: "access", dependPackages: { accessOnly: "^1.0.0" } } as any,
|
define: { name: "runtimeDepsAccess", title: "access", dependPackages: { accessOnly: "^1.0.0" } } as any,
|
||||||
target: async () => ({} as any),
|
target: async () => ({}) as any,
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
const resolved = service.resolvePluginDependencies({
|
const resolved = service.resolvePluginDependencies({
|
||||||
@@ -262,11 +198,7 @@ describe("RuntimeDepsService", () => {
|
|||||||
dependPackages: { deployOnly: "^1.0.0" },
|
dependPackages: { deployOnly: "^1.0.0" },
|
||||||
});
|
});
|
||||||
const merged = service.collectDependencies(resolved);
|
const merged = service.collectDependencies(resolved);
|
||||||
|
assert.deepEqual(merged.dependencies, { deployOnly: "^1.0.0", accessOnly: "^1.0.0" });
|
||||||
assert.deepEqual(merged.dependencies, {
|
|
||||||
deployOnly: "^1.0.0",
|
|
||||||
accessOnly: "^1.0.0",
|
|
||||||
});
|
|
||||||
} finally {
|
} finally {
|
||||||
accessRegistry.unRegister("runtimeDepsAccess");
|
accessRegistry.unRegister("runtimeDepsAccess");
|
||||||
}
|
}
|
||||||
@@ -274,8 +206,7 @@ describe("RuntimeDepsService", () => {
|
|||||||
|
|
||||||
it("installs dependencies by registered plugin key", async () => {
|
it("installs dependencies by registered plugin key", async () => {
|
||||||
const rootDir = fs.mkdtempSync(path.join(os.tmpdir(), "certd-runtime-deps-key-"));
|
const rootDir = fs.mkdtempSync(path.join(os.tmpdir(), "certd-runtime-deps-key-"));
|
||||||
const service = new RuntimeDepsService();
|
const service = new RuntimeDepsService({ rootDir }, { pluginRegistry, accessRegistry });
|
||||||
service.runtimeDepsRootDir = rootDir;
|
|
||||||
service.registryResolver = {
|
service.registryResolver = {
|
||||||
async resolve() {
|
async resolve() {
|
||||||
return "";
|
return "";
|
||||||
@@ -293,11 +224,11 @@ describe("RuntimeDepsService", () => {
|
|||||||
} as any;
|
} as any;
|
||||||
pluginRegistry.register("runtimeDepsKey", {
|
pluginRegistry.register("runtimeDepsKey", {
|
||||||
define: { name: "runtimeDepsKey", title: "key", dependPackages: { keyed: "^1.0.0" } } as any,
|
define: { name: "runtimeDepsKey", title: "key", dependPackages: { keyed: "^1.0.0" } } as any,
|
||||||
target: async () => ({} as any),
|
target: async () => ({}) as any,
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
|
service.setRegistries({ pluginRegistry, accessRegistry });
|
||||||
await service.ensureRuntimeDependencies({ pluginKeys: "plugin:runtimeDepsKey" });
|
await service.ensureRuntimeDependencies({ pluginKeys: "plugin:runtimeDepsKey" });
|
||||||
|
|
||||||
const manifest = JSON.parse(fs.readFileSync(path.join(rootDir, "package.json"), "utf8"));
|
const manifest = JSON.parse(fs.readFileSync(path.join(rootDir, "package.json"), "utf8"));
|
||||||
assert.deepEqual(manifest.dependencies, { keyed: "^1.0.0" });
|
assert.deepEqual(manifest.dependencies, { keyed: "^1.0.0" });
|
||||||
} finally {
|
} finally {
|
||||||
@@ -305,58 +236,16 @@ describe("RuntimeDepsService", () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it("installs dependencies from multiple plugin keys including addon subtype keys", async () => {
|
|
||||||
const rootDir = fs.mkdtempSync(path.join(os.tmpdir(), "certd-runtime-deps-keys-"));
|
|
||||||
const service = new RuntimeDepsService();
|
|
||||||
service.runtimeDepsRootDir = rootDir;
|
|
||||||
service.registryResolver = {
|
|
||||||
async resolve() {
|
|
||||||
return "";
|
|
||||||
},
|
|
||||||
} as any;
|
|
||||||
service.commandRunner = {
|
|
||||||
async run(command: string, args: string[]) {
|
|
||||||
assert.equal(command, "pnpm");
|
|
||||||
if (args.includes("--version")) {
|
|
||||||
return { stdout: "9.1.0\n", stderr: "", code: 0 };
|
|
||||||
}
|
|
||||||
fs.mkdirSync(path.join(rootDir, "node_modules"), { recursive: true });
|
|
||||||
return { stdout: "", stderr: "", code: 0 };
|
|
||||||
},
|
|
||||||
} as any;
|
|
||||||
accessRegistry.register("runtimeDepsArrayAccess", {
|
|
||||||
define: { name: "runtimeDepsArrayAccess", title: "access", dependPackages: { accessPkg: "^1.0.0" } } as any,
|
|
||||||
target: async () => ({} as any),
|
|
||||||
});
|
|
||||||
addonRegistry.register("captcha:runtimeDepsArrayAddon", {
|
|
||||||
define: { addonType: "captcha", name: "runtimeDepsArrayAddon", title: "addon", dependPackages: { addonPkg: "^2.0.0" } } as any,
|
|
||||||
target: async () => ({} as any),
|
|
||||||
});
|
|
||||||
try {
|
|
||||||
await service.ensureRuntimeDependencies({ pluginKeys: ["access:runtimeDepsArrayAccess", "addon:captcha:runtimeDepsArrayAddon"] });
|
|
||||||
|
|
||||||
const manifest = JSON.parse(fs.readFileSync(path.join(rootDir, "package.json"), "utf8"));
|
|
||||||
assert.deepEqual(manifest.dependencies, {
|
|
||||||
accessPkg: "^1.0.0",
|
|
||||||
addonPkg: "^2.0.0",
|
|
||||||
});
|
|
||||||
} finally {
|
|
||||||
accessRegistry.unRegister("runtimeDepsArrayAccess");
|
|
||||||
addonRegistry.unRegister("captcha:runtimeDepsArrayAddon");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it("reports missing dependent plugins", () => {
|
it("reports missing dependent plugins", () => {
|
||||||
const service = new RuntimeDepsService();
|
const service = new RuntimeDepsService({}, { accessRegistry, pluginRegistry });
|
||||||
|
|
||||||
assert.throws(() => service.resolvePluginDependencies({ name: "deploy", pluginType: "deploy", dependPlugins: { "access:access": "*" } }), /插件依赖缺失/);
|
assert.throws(() => service.resolvePluginDependencies({ name: "deploy", pluginType: "deploy", dependPlugins: { "access:access": "*" } }), /插件依赖缺失/);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("reports incompatible dependent plugin versions", () => {
|
it("reports incompatible dependent plugin versions", () => {
|
||||||
const service = new RuntimeDepsService();
|
const service = new RuntimeDepsService({}, { accessRegistry, pluginRegistry });
|
||||||
accessRegistry.register("runtimeDepsVersionedAccess", {
|
accessRegistry.register("runtimeDepsVersionedAccess", {
|
||||||
define: { name: "runtimeDepsVersionedAccess", title: "access", version: "1.4.0", dependPackages: { accessOnly: "^1.0.0" } } as any,
|
define: { name: "runtimeDepsVersionedAccess", title: "access", version: "1.4.0", dependPackages: { accessOnly: "^1.0.0" } } as any,
|
||||||
target: async () => ({} as any),
|
target: async () => ({}) as any,
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
assert.throws(
|
assert.throws(
|
||||||
@@ -374,73 +263,10 @@ describe("RuntimeDepsService", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("reports bare dependent plugin names as invalid format", () => {
|
it("reports bare dependent plugin names as invalid format", () => {
|
||||||
const service = new RuntimeDepsService();
|
const service = new RuntimeDepsService({}, null);
|
||||||
|
|
||||||
assert.throws(() => service.resolvePluginDependencies({ name: "deploy", pluginType: "deploy", dependPlugins: { runtimeDepsBareName: "*" } }), /插件依赖格式错误/);
|
assert.throws(() => service.resolvePluginDependencies({ name: "deploy", pluginType: "deploy", dependPlugins: { runtimeDepsBareName: "*" } }), /插件依赖格式错误/);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("records runtime install environment state", async () => {
|
|
||||||
const rootDir = fs.mkdtempSync(path.join(os.tmpdir(), "certd-runtime-deps-state-"));
|
|
||||||
const service = new RuntimeDepsService();
|
|
||||||
service.runtimeDepsRootDir = rootDir;
|
|
||||||
service.registryResolver = {
|
|
||||||
async resolve() {
|
|
||||||
return "";
|
|
||||||
},
|
|
||||||
} as any;
|
|
||||||
service.commandRunner = {
|
|
||||||
async run(command: string, args: string[]) {
|
|
||||||
assert.equal(command, "pnpm");
|
|
||||||
if (args.includes("--version")) {
|
|
||||||
return { stdout: "9.1.0\n", stderr: "", code: 0 };
|
|
||||||
}
|
|
||||||
assert.equal(args[0], "install");
|
|
||||||
return { stdout: "", stderr: "", code: 0 };
|
|
||||||
},
|
|
||||||
} as any;
|
|
||||||
|
|
||||||
await service.ensureInstalled({ plugins: [{ name: "a", dependPackages: { foo: "^1.0.0" } }] });
|
|
||||||
|
|
||||||
const state = JSON.parse(fs.readFileSync(path.join(rootDir, "install-state.json"), "utf8"));
|
|
||||||
assert.equal(state.nodeVersion, process.version);
|
|
||||||
assert.equal(state.pnpmVersion, "9.1.0");
|
|
||||||
assert.equal(state.lastError, undefined);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("serializes installs with a file lock", async () => {
|
|
||||||
const rootDir = fs.mkdtempSync(path.join(os.tmpdir(), "certd-runtime-deps-lock-"));
|
|
||||||
const serviceA = new RuntimeDepsService();
|
|
||||||
const serviceB = new RuntimeDepsService();
|
|
||||||
for (const service of [serviceA, serviceB]) {
|
|
||||||
service.runtimeDepsRootDir = rootDir;
|
|
||||||
service.registryResolver = {
|
|
||||||
async resolve() {
|
|
||||||
return "";
|
|
||||||
},
|
|
||||||
} as any;
|
|
||||||
}
|
|
||||||
let installCount = 0;
|
|
||||||
const commandRunner = {
|
|
||||||
async run(command: string, args: string[]) {
|
|
||||||
assert.equal(command, "pnpm");
|
|
||||||
if (args.includes("--version")) {
|
|
||||||
return { stdout: "9.1.0\n", stderr: "", code: 0 };
|
|
||||||
}
|
|
||||||
assert.equal(args[0], "install");
|
|
||||||
installCount++;
|
|
||||||
await new Promise(resolve => setTimeout(resolve, 50));
|
|
||||||
fs.mkdirSync(path.join(rootDir, "node_modules"), { recursive: true });
|
|
||||||
return { stdout: "", stderr: "", code: 0 };
|
|
||||||
},
|
|
||||||
};
|
|
||||||
serviceA.commandRunner = commandRunner as any;
|
|
||||||
serviceB.commandRunner = commandRunner as any;
|
|
||||||
|
|
||||||
await Promise.all([serviceA.ensureInstalled({ plugins: [{ name: "a", dependPackages: { foo: "^1.0.0" } }] }), serviceB.ensureInstalled({ plugins: [{ name: "a", dependPackages: { foo: "^1.0.0" } }] })]);
|
|
||||||
|
|
||||||
assert.equal(installCount, 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("does not pass node debugger options to pnpm child process", async () => {
|
it("does not pass node debugger options to pnpm child process", async () => {
|
||||||
const rootDir = fs.mkdtempSync(path.join(os.tmpdir(), "certd-runtime-deps-env-"));
|
const rootDir = fs.mkdtempSync(path.join(os.tmpdir(), "certd-runtime-deps-env-"));
|
||||||
const oldNodeOptions = process.env.NODE_OPTIONS;
|
const oldNodeOptions = process.env.NODE_OPTIONS;
|
||||||
@@ -448,8 +274,7 @@ describe("RuntimeDepsService", () => {
|
|||||||
process.env.NODE_OPTIONS = "--inspect=127.0.0.1:9229 --max-old-space-size=4096";
|
process.env.NODE_OPTIONS = "--inspect=127.0.0.1:9229 --max-old-space-size=4096";
|
||||||
process.env.VSCODE_INSPECTOR_OPTIONS = '{"inspectorIpc":"test"}';
|
process.env.VSCODE_INSPECTOR_OPTIONS = '{"inspectorIpc":"test"}';
|
||||||
try {
|
try {
|
||||||
const service = new RuntimeDepsService();
|
const service = new RuntimeDepsService({ rootDir }, null);
|
||||||
service.runtimeDepsRootDir = rootDir;
|
|
||||||
service.registryResolver = {
|
service.registryResolver = {
|
||||||
async resolve() {
|
async resolve() {
|
||||||
return "";
|
return "";
|
||||||
@@ -467,7 +292,6 @@ describe("RuntimeDepsService", () => {
|
|||||||
return { stdout: "", stderr: "", code: 0 };
|
return { stdout: "", stderr: "", code: 0 };
|
||||||
},
|
},
|
||||||
} as any;
|
} as any;
|
||||||
|
|
||||||
await service.ensureInstalled({ plugins: [{ name: "a", dependPackages: { foo: "^1.0.0" } }] });
|
await service.ensureInstalled({ plugins: [{ name: "a", dependPackages: { foo: "^1.0.0" } }] });
|
||||||
} finally {
|
} finally {
|
||||||
if (oldNodeOptions == null) {
|
if (oldNodeOptions == null) {
|
||||||
@@ -483,27 +307,38 @@ describe("RuntimeDepsService", () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it.skip("clears runtime dependency directory", async () => {
|
|
||||||
const rootDir = fs.mkdtempSync(path.join(os.tmpdir(), "certd-runtime-clear-"));
|
|
||||||
const runtimeRootDir = path.join(rootDir, ".runtime-deps");
|
|
||||||
fs.mkdirSync(path.join(runtimeRootDir, "node_modules", "foo"), { recursive: true });
|
|
||||||
fs.writeFileSync(path.join(runtimeRootDir, "package.json"), "{}", "utf8");
|
|
||||||
const service = new RuntimeDepsService();
|
|
||||||
service.runtimeDepsRootDir = runtimeRootDir;
|
|
||||||
service.installTimeoutMs = 1000;
|
|
||||||
|
|
||||||
await service.clearRuntimeDeps();
|
|
||||||
|
|
||||||
assert.equal(fs.existsSync(runtimeRootDir), true);
|
|
||||||
const remainingEntries = fs.readdirSync(runtimeRootDir).filter(e => e !== ".install.lock");
|
|
||||||
assert.equal(remainingEntries.length, 0);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("rejects clearing unexpected runtime dependency path", async () => {
|
it("rejects clearing unexpected runtime dependency path", async () => {
|
||||||
const rootDir = fs.mkdtempSync(path.join(os.tmpdir(), "certd-runtime-clear-invalid-"));
|
const rootDir = fs.mkdtempSync(path.join(os.tmpdir(), "certd-runtime-clear-invalid-"));
|
||||||
const service = new RuntimeDepsService();
|
const service = new RuntimeDepsService({ rootDir }, null);
|
||||||
service.runtimeDepsRootDir = rootDir;
|
|
||||||
|
|
||||||
await assert.rejects(() => service.clearRuntimeDeps(), /动态依赖目录配置异常/);
|
await assert.rejects(() => service.clearRuntimeDeps(), /动态依赖目录配置异常/);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("NpmRegistryResolver", () => {
|
||||||
|
it("chooses the fastest successful registry in auto mode", async () => {
|
||||||
|
const resolver = new NpmRegistryResolver({
|
||||||
|
mode: "auto",
|
||||||
|
candidates: ["https://slow.example.com", "https://fast.example.com"],
|
||||||
|
probeTimeoutMs: 100,
|
||||||
|
cacheTtlMs: 1000,
|
||||||
|
});
|
||||||
|
resolver.probe = async (registryUrl: string) => ({
|
||||||
|
registryUrl,
|
||||||
|
ok: true,
|
||||||
|
elapsedMs: registryUrl.includes("fast") ? 10 : 50,
|
||||||
|
});
|
||||||
|
const result = await resolver.resolve();
|
||||||
|
assert.equal(result, "https://fast.example.com");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("uses fixed registry without probing", async () => {
|
||||||
|
const resolver = new NpmRegistryResolver({
|
||||||
|
mode: "fixed",
|
||||||
|
fixedUrl: "https://registry.example.com",
|
||||||
|
probeTimeoutMs: 100,
|
||||||
|
cacheTtlMs: 1000,
|
||||||
|
});
|
||||||
|
const result = await resolver.resolve();
|
||||||
|
assert.equal(result, "https://registry.example.com");
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,27 +1,773 @@
|
|||||||
/**
|
import fs from "fs";
|
||||||
* 运行时动态导入函数类型
|
import path from "path";
|
||||||
*/
|
import { spawn } from "child_process";
|
||||||
export type ImportRuntime = (specifier: string, logger?: ILogger) => Promise<any>;
|
import crypto from "crypto";
|
||||||
|
import { createRequire } from "module";
|
||||||
/**
|
import { pathToFileURL } from "url";
|
||||||
* 日志接口
|
import { logger as defaultLogger } from "@certd/basic";
|
||||||
*/
|
import type { Registry } from "../registry/registry.js";
|
||||||
export type ILogger = {
|
export type ILogger = {
|
||||||
info: (message: string) => void;
|
info: (message: string) => void;
|
||||||
|
warn?: (message: string) => void;
|
||||||
|
error?: (message: string, ...args: any[]) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
export type ImportRuntime = (specifier: string, logger?: ILogger) => Promise<any>;
|
||||||
* 运行时依赖服务参数
|
|
||||||
*/
|
|
||||||
export type EnsureRuntimeDepsOptions = {
|
export type EnsureRuntimeDepsOptions = {
|
||||||
pluginKeys: string | string[];
|
pluginKeys: string | string[];
|
||||||
logger?: ILogger;
|
logger?: ILogger;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* 运行时依赖服务接口
|
|
||||||
*/
|
|
||||||
export interface IRuntimeDepsService {
|
export interface IRuntimeDepsService {
|
||||||
ensureRuntimeDependencies(options: EnsureRuntimeDepsOptions): Promise<any>;
|
ensureRuntimeDependencies(options: EnsureRuntimeDepsOptions): Promise<any>;
|
||||||
importRuntime: ImportRuntime;
|
importRuntime: ImportRuntime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type RuntimeDependencyPluginDefine = {
|
||||||
|
name: string;
|
||||||
|
key?: string;
|
||||||
|
title?: string;
|
||||||
|
version?: string;
|
||||||
|
pluginType?: string;
|
||||||
|
addonType?: string;
|
||||||
|
dependPlugins?: Record<string, string>;
|
||||||
|
dependPackages?: Record<string, string>;
|
||||||
|
};
|
||||||
|
|
||||||
|
type RegisteredDefineLike = RuntimeDependencyPluginDefine & {
|
||||||
|
key?: string;
|
||||||
|
pluginType?: string;
|
||||||
|
addonType?: string;
|
||||||
|
dependPlugins?: Record<string, string>;
|
||||||
|
dependPackages?: Record<string, string>;
|
||||||
|
};
|
||||||
|
|
||||||
|
type DependencyConflict = {
|
||||||
|
packageName: string;
|
||||||
|
ranges: Array<{ pluginName: string; range: string }>;
|
||||||
|
};
|
||||||
|
|
||||||
|
type CollectDependenciesResult = {
|
||||||
|
dependencies: Record<string, string>;
|
||||||
|
conflicts: DependencyConflict[];
|
||||||
|
};
|
||||||
|
|
||||||
|
type InstallResult = {
|
||||||
|
registryUrl: string;
|
||||||
|
packageJsonPath: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
type RuntimeImportResolveResult = {
|
||||||
|
resolved: string;
|
||||||
|
packageName: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
type CommandRunnerResult = {
|
||||||
|
stdout: string;
|
||||||
|
stderr: string;
|
||||||
|
code: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
type CommandRunner = {
|
||||||
|
run(command: string, args: string[], options: { cwd: string; timeoutMs: number; env?: NodeJS.ProcessEnv }): Promise<CommandRunnerResult>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type NpmRegistryResolverConfig = {
|
||||||
|
mode?: "auto" | "fixed" | "system";
|
||||||
|
fixedUrl?: string;
|
||||||
|
candidates?: string[];
|
||||||
|
probeTimeoutMs?: number;
|
||||||
|
cacheTtlMs?: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type RegistryProbeResult = {
|
||||||
|
registryUrl: string;
|
||||||
|
ok: boolean;
|
||||||
|
elapsedMs: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export class NpmRegistryResolver {
|
||||||
|
config: NpmRegistryResolverConfig;
|
||||||
|
private cache?: { registryUrl: string; expiresAt: number };
|
||||||
|
|
||||||
|
constructor(config?: NpmRegistryResolverConfig) {
|
||||||
|
this.config = config || {};
|
||||||
|
}
|
||||||
|
|
||||||
|
async resolve(): Promise<string> {
|
||||||
|
const config = this.config;
|
||||||
|
if (config?.mode === "fixed" && config.fixedUrl) {
|
||||||
|
return config.fixedUrl;
|
||||||
|
}
|
||||||
|
if (config?.mode === "system") {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
const cached = this.cache;
|
||||||
|
if (cached && cached.expiresAt > Date.now()) {
|
||||||
|
return cached.registryUrl;
|
||||||
|
}
|
||||||
|
const candidates = (config?.candidates || []).filter(Boolean);
|
||||||
|
if (candidates.length === 0) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
const probes = await Promise.allSettled(candidates.map(registryUrl => this.probe(registryUrl)));
|
||||||
|
const okList = probes.map(item => (item.status === "fulfilled" ? item.value : null)).filter((item): item is RegistryProbeResult => !!item && item.ok);
|
||||||
|
if (okList.length > 0) {
|
||||||
|
okList.sort((a, b) => a.elapsedMs - b.elapsedMs);
|
||||||
|
const best = okList[0].registryUrl;
|
||||||
|
this.cache = { registryUrl: best, expiresAt: Date.now() + (config?.cacheTtlMs || 6 * 60 * 60 * 1000) };
|
||||||
|
return best;
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
async probe(registryUrl: string): Promise<RegistryProbeResult> {
|
||||||
|
const timeoutMs = this.config?.probeTimeoutMs || 3000;
|
||||||
|
const started = Date.now();
|
||||||
|
try {
|
||||||
|
const controller = new AbortController();
|
||||||
|
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
||||||
|
try {
|
||||||
|
const res = await fetch(`${registryUrl.replace(/\/$/, "")}/-/ping`, { signal: controller.signal });
|
||||||
|
return { registryUrl, ok: res.ok, elapsedMs: Date.now() - started };
|
||||||
|
} finally {
|
||||||
|
clearTimeout(timer);
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
return { registryUrl, ok: false, elapsedMs: Date.now() - started };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export type RuntimeDepsConfig = {
|
||||||
|
rootDir?: string;
|
||||||
|
autoInstall?: boolean;
|
||||||
|
enabled?: boolean;
|
||||||
|
installTimeoutMs?: number;
|
||||||
|
pnpmCommand?: string;
|
||||||
|
lazyDependencies?: Record<string, string>;
|
||||||
|
registry?: NpmRegistryResolverConfig;
|
||||||
|
};
|
||||||
|
|
||||||
|
function normalizeRange(range: string) {
|
||||||
|
return range.trim().replace(/^\^/, "").replace(/^~?/, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
function areRangesCompatible(a: string, b: string) {
|
||||||
|
if (!a || !b) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (a === "*" || b === "*") {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
const left = normalizeRange(a).split(".");
|
||||||
|
const right = normalizeRange(b).split(".");
|
||||||
|
return left[0] === right[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
const PROCESS_LOCKS = new Map<string, Promise<unknown>>();
|
||||||
|
|
||||||
|
class DefaultCommandRunner implements CommandRunner {
|
||||||
|
async run(command: string, args: string[], options: { cwd: string; timeoutMs: number; env?: NodeJS.ProcessEnv }): Promise<CommandRunnerResult> {
|
||||||
|
return await new Promise<CommandRunnerResult>(resolve => {
|
||||||
|
let stdout = "";
|
||||||
|
let stderr = "";
|
||||||
|
let settled = false;
|
||||||
|
const child = spawn(command, args, { cwd: options.cwd, env: options.env, windowsHide: true, shell: process.platform === "win32" });
|
||||||
|
const timer = setTimeout(() => {
|
||||||
|
if (settled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
settled = true;
|
||||||
|
child.kill("SIGTERM");
|
||||||
|
resolve({ stdout, stderr: stderr || `command timeout after ${options.timeoutMs}ms`, code: 1 });
|
||||||
|
}, options.timeoutMs);
|
||||||
|
child.stdout?.on("data", chunk => {
|
||||||
|
stdout += chunk.toString();
|
||||||
|
});
|
||||||
|
child.stderr?.on("data", chunk => {
|
||||||
|
stderr += chunk.toString();
|
||||||
|
});
|
||||||
|
child.on("error", error => {
|
||||||
|
if (settled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
settled = true;
|
||||||
|
clearTimeout(timer);
|
||||||
|
resolve({ stdout, stderr: error.message, code: 1 });
|
||||||
|
});
|
||||||
|
child.on("close", code => {
|
||||||
|
if (settled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
settled = true;
|
||||||
|
clearTimeout(timer);
|
||||||
|
resolve({ stdout, stderr, code: code || 0 });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class RuntimeDepsService {
|
||||||
|
runtimeDepsRootDir: string;
|
||||||
|
autoInstall: boolean;
|
||||||
|
enabled: boolean;
|
||||||
|
installTimeoutMs: number;
|
||||||
|
pnpmCommand: string;
|
||||||
|
lazyDependencies: Record<string, string>;
|
||||||
|
registryResolver!: NpmRegistryResolver;
|
||||||
|
commandRunner: CommandRunner = new DefaultCommandRunner();
|
||||||
|
pluginLazyDependencies: Record<string, string> = {};
|
||||||
|
private installPromises = new Map<string, Promise<InstallResult>>();
|
||||||
|
private registriesMap: Record<string, { registry: Registry<any>; pluginType: string; addonType?: string }> | null = null;
|
||||||
|
|
||||||
|
constructor(config: RuntimeDepsConfig, registries: any) {
|
||||||
|
this.runtimeDepsRootDir = config?.rootDir ?? "./data/.runtime-deps";
|
||||||
|
this.autoInstall = config?.autoInstall ?? true;
|
||||||
|
this.enabled = config?.enabled ?? true;
|
||||||
|
this.installTimeoutMs = config?.installTimeoutMs ?? 120000;
|
||||||
|
this.pnpmCommand = config?.pnpmCommand ?? "";
|
||||||
|
this.lazyDependencies = config?.lazyDependencies ?? {};
|
||||||
|
this.registryResolver = new NpmRegistryResolver(config?.registry);
|
||||||
|
if (registries) {
|
||||||
|
this.setRegistries(registries);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setRegistries(registries: { pluginRegistry?: Registry<any>; accessRegistry?: Registry<any>; notificationRegistry?: Registry<any>; dnsProviderRegistry?: Registry<any>; addonRegistry?: Registry<any> }) {
|
||||||
|
const map: Record<string, { registry: Registry<any>; pluginType: string; addonType?: string }> = {};
|
||||||
|
if (registries.pluginRegistry) {
|
||||||
|
map["plugin"] = { registry: registries.pluginRegistry, pluginType: "plugin" };
|
||||||
|
}
|
||||||
|
if (registries.accessRegistry) {
|
||||||
|
map["access"] = { registry: registries.accessRegistry, pluginType: "access" };
|
||||||
|
}
|
||||||
|
if (registries.notificationRegistry) {
|
||||||
|
map["notification"] = { registry: registries.notificationRegistry, pluginType: "notification" };
|
||||||
|
}
|
||||||
|
if (registries.dnsProviderRegistry) {
|
||||||
|
map["dnsProvider"] = { registry: registries.dnsProviderRegistry, pluginType: "dnsProvider" };
|
||||||
|
}
|
||||||
|
if (registries.addonRegistry) {
|
||||||
|
map["addon"] = { registry: registries.addonRegistry, pluginType: "addon", addonType: "" };
|
||||||
|
}
|
||||||
|
this.registriesMap = map;
|
||||||
|
}
|
||||||
|
|
||||||
|
collectDependencies(plugins: RuntimeDependencyPluginDefine[]): CollectDependenciesResult {
|
||||||
|
const merged: Record<string, string> = {};
|
||||||
|
const seen: Record<string, Array<{ pluginName: string; range: string }>> = {};
|
||||||
|
for (const plugin of plugins) {
|
||||||
|
const deps = plugin.dependPackages || {};
|
||||||
|
for (const [packageName, range] of Object.entries(deps)) {
|
||||||
|
seen[packageName] ||= [];
|
||||||
|
seen[packageName].push({ pluginName: plugin.name, range });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const conflicts: DependencyConflict[] = [];
|
||||||
|
for (const [packageName, ranges] of Object.entries(seen)) {
|
||||||
|
const first = ranges[0]?.range;
|
||||||
|
if (!first) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const conflict = ranges.some(item => !areRangesCompatible(first, item.range));
|
||||||
|
if (conflict) {
|
||||||
|
conflicts.push({ packageName, ranges });
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
merged[packageName] = first;
|
||||||
|
}
|
||||||
|
return { dependencies: merged, conflicts };
|
||||||
|
}
|
||||||
|
|
||||||
|
async ensureInstalled(options: { plugins: RuntimeDependencyPluginDefine[]; logger?: ILogger }): Promise<InstallResult> {
|
||||||
|
const { plugins, logger: log } = options;
|
||||||
|
const { dependencies, conflicts } = this.resolveDependenciesFromPlugins(plugins);
|
||||||
|
if (conflicts.length > 0) {
|
||||||
|
const conflict = conflicts[0];
|
||||||
|
throw new Error(`动态依赖版本冲突: ${conflict.packageName} => ${conflict.ranges.map(item => `${item.pluginName}:${item.range}`).join(", ")}`);
|
||||||
|
}
|
||||||
|
return await this.ensureDependencies({ dependencies, logger: log });
|
||||||
|
}
|
||||||
|
|
||||||
|
async ensureDependencies(options: { dependencies: Record<string, string>; logger?: ILogger }): Promise<InstallResult> {
|
||||||
|
const { dependencies, logger: log } = options;
|
||||||
|
if (!this.enabled) {
|
||||||
|
return { registryUrl: "", packageJsonPath: path.join(this.getRuntimeDepsRootDir(), "package.json") };
|
||||||
|
}
|
||||||
|
if (!this.autoInstall) {
|
||||||
|
return { registryUrl: "", packageJsonPath: path.join(this.getRuntimeDepsRootDir(), "package.json") };
|
||||||
|
}
|
||||||
|
const dependenciesHash = this.createDependenciesHash(dependencies);
|
||||||
|
let installPromise = this.installPromises.get(dependenciesHash);
|
||||||
|
if (installPromise) {
|
||||||
|
const nodeModulesPath = path.join(this.getRuntimeDepsRootDir(), "node_modules");
|
||||||
|
if (!fs.existsSync(nodeModulesPath)) {
|
||||||
|
this.installPromises.delete(dependenciesHash);
|
||||||
|
installPromise = undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!installPromise) {
|
||||||
|
installPromise = this.doEnsureInstalled({ dependencies, logger: log }).catch(error => {
|
||||||
|
this.installPromises.delete(dependenciesHash);
|
||||||
|
throw error;
|
||||||
|
});
|
||||||
|
this.installPromises.set(dependenciesHash, installPromise);
|
||||||
|
}
|
||||||
|
return await installPromise;
|
||||||
|
}
|
||||||
|
|
||||||
|
resolveDependenciesFromPlugins(plugins: RuntimeDependencyPluginDefine[]): CollectDependenciesResult {
|
||||||
|
const expandedPlugins = plugins.flatMap(plugin => this.resolvePluginDependencies(plugin));
|
||||||
|
return this.collectDependencies(expandedPlugins);
|
||||||
|
}
|
||||||
|
|
||||||
|
async ensureRuntimeDependencies(options: { pluginKeys: string | string[]; logger?: ILogger }): Promise<InstallResult> {
|
||||||
|
const { pluginKeys, logger: log } = options;
|
||||||
|
const keys = Array.isArray(pluginKeys) ? pluginKeys : [pluginKeys];
|
||||||
|
const pluginDefines = keys.map(pluginKey => this.getDefineByPluginKey(pluginKey));
|
||||||
|
if (pluginDefines.every(pluginDefine => !pluginDefine.dependPackages && !pluginDefine.dependPlugins)) {
|
||||||
|
return { registryUrl: "", packageJsonPath: path.join(this.getRuntimeDepsRootDir(), "package.json") };
|
||||||
|
}
|
||||||
|
const expandedPluginDefines = pluginDefines.flatMap(pluginDefine => this.resolvePluginDependencies(pluginDefine));
|
||||||
|
return await this.ensureInstalled({ plugins: expandedPluginDefines, logger: log });
|
||||||
|
}
|
||||||
|
|
||||||
|
async importRuntime(specifier: string, logger: ILogger = defaultLogger) {
|
||||||
|
if (this.isNativeImportSpecifier(specifier)) {
|
||||||
|
return await import(specifier);
|
||||||
|
}
|
||||||
|
const resolved = await this.resolveImportSpecifier(specifier, logger);
|
||||||
|
return await import(pathToFileURL(resolved).href);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async resolveImportSpecifier(specifier: string, logger: ILogger = defaultLogger) {
|
||||||
|
try {
|
||||||
|
return this.resolveRuntimeSpecifier(specifier).resolved;
|
||||||
|
} catch (runtimeError: any) {
|
||||||
|
if (!this.isModuleNotFoundError(runtimeError)) {
|
||||||
|
throw runtimeError;
|
||||||
|
}
|
||||||
|
return await this.resolveMissingRuntimeSpecifier(specifier, runtimeError, logger);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async resolveMissingRuntimeSpecifier(specifier: string, runtimeError: any, logger?: ILogger) {
|
||||||
|
const packageName = this.parsePackageName(specifier);
|
||||||
|
const mergedDeps = this.getMergedLazyDependencies();
|
||||||
|
const lazyRange = mergedDeps[packageName];
|
||||||
|
if (!lazyRange) {
|
||||||
|
try {
|
||||||
|
return this.resolveProjectSpecifier(specifier, runtimeError).resolved;
|
||||||
|
} catch {
|
||||||
|
throw new Error(`动态依赖未安装且未配置懒加载版本: ${packageName}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await this.ensureLazyDependency(packageName, logger);
|
||||||
|
return this.resolveRuntimeSpecifier(specifier).resolved;
|
||||||
|
} catch (lazyError: any) {
|
||||||
|
return this.resolveProjectSpecifier(specifier, lazyError).resolved;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private isNativeImportSpecifier(specifier: string) {
|
||||||
|
return specifier.startsWith(".") || specifier.startsWith("/") || specifier.startsWith("file:") || specifier.startsWith("node:");
|
||||||
|
}
|
||||||
|
|
||||||
|
private resolveRuntimeSpecifier(specifier: string): RuntimeImportResolveResult {
|
||||||
|
const packageName = this.parsePackageName(specifier);
|
||||||
|
const packageJsonPath = path.join(this.getRuntimeDepsRootDir(), "package.json");
|
||||||
|
const require = createRequire(packageJsonPath);
|
||||||
|
const resolved = require.resolve(specifier);
|
||||||
|
return { packageName, resolved };
|
||||||
|
}
|
||||||
|
|
||||||
|
private resolveProjectSpecifier(specifier: string, cause?: any): RuntimeImportResolveResult {
|
||||||
|
try {
|
||||||
|
const packageName = this.parsePackageName(specifier);
|
||||||
|
const packageJsonPath = path.resolve("package.json");
|
||||||
|
const require = createRequire(packageJsonPath);
|
||||||
|
const resolved = require.resolve(specifier);
|
||||||
|
return { packageName, resolved };
|
||||||
|
} catch (projectError: any) {
|
||||||
|
if (cause) {
|
||||||
|
projectError.cause = cause;
|
||||||
|
}
|
||||||
|
throw projectError;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private parsePackageName(specifier: string) {
|
||||||
|
if (!specifier || specifier.trim() !== specifier) {
|
||||||
|
throw new Error(`动态依赖导入路径无效: ${specifier}`);
|
||||||
|
}
|
||||||
|
const parts = specifier.split("/");
|
||||||
|
if (specifier.startsWith("@")) {
|
||||||
|
if (parts.length < 2 || !parts[0] || !parts[1]) {
|
||||||
|
throw new Error(`动态依赖导入路径无效: ${specifier}`);
|
||||||
|
}
|
||||||
|
return `${parts[0]}/${parts[1]}`;
|
||||||
|
}
|
||||||
|
if (!parts[0]) {
|
||||||
|
throw new Error(`动态依赖导入路径无效: ${specifier}`);
|
||||||
|
}
|
||||||
|
return parts[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
private async ensureLazyDependency(packageName: string, logger?: ILogger) {
|
||||||
|
const range = this.lazyDependencies?.[packageName];
|
||||||
|
if (!range) {
|
||||||
|
throw new Error(`动态依赖未安装且未配置懒加载版本: ${packageName}`);
|
||||||
|
}
|
||||||
|
await this.ensureDependencies({ dependencies: { [packageName]: range }, logger });
|
||||||
|
}
|
||||||
|
|
||||||
|
private isModuleNotFoundError(error: any) {
|
||||||
|
return error?.code === "MODULE_NOT_FOUND" || error?.code === "ERR_MODULE_NOT_FOUND";
|
||||||
|
}
|
||||||
|
|
||||||
|
resolvePluginDependencies(current: RuntimeDependencyPluginDefine): RuntimeDependencyPluginDefine[] {
|
||||||
|
const resolved: RuntimeDependencyPluginDefine[] = [];
|
||||||
|
const visited = new Set<string>();
|
||||||
|
const visit = (item: RuntimeDependencyPluginDefine) => {
|
||||||
|
const key = this.buildPluginDependencyKey(item);
|
||||||
|
if (visited.has(key)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
visited.add(key);
|
||||||
|
resolved.push(item);
|
||||||
|
for (const [dependencyName, expectedRange] of Object.entries(item.dependPlugins || {})) {
|
||||||
|
const dependency = this.getDefineByPluginKey(dependencyName, item);
|
||||||
|
if (!isPluginVersionCompatible(dependency, expectedRange)) {
|
||||||
|
throw new Error(`插件依赖版本冲突: ${item.name} 依赖 ${dependencyName}@${expectedRange},当前版本为 ${dependency.version || "未声明"}`);
|
||||||
|
}
|
||||||
|
visit(dependency);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
visit(current);
|
||||||
|
return resolved;
|
||||||
|
}
|
||||||
|
|
||||||
|
private buildPluginDependencyKey(plugin: RuntimeDependencyPluginDefine) {
|
||||||
|
if (plugin.pluginType === "addon" && plugin.addonType) {
|
||||||
|
return `addon:${plugin.addonType}:${plugin.name}`;
|
||||||
|
}
|
||||||
|
const pluginType = plugin.pluginType === "deploy" ? "plugin" : plugin.pluginType || "unknown";
|
||||||
|
return `${pluginType}:${plugin.name}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
private getDefineByPluginKey(pluginKey: string, owner?: RuntimeDependencyPluginDefine): RuntimeDependencyPluginDefine {
|
||||||
|
const parts = pluginKey.split(":");
|
||||||
|
let pluginType: string, name: string, subtype: string | undefined;
|
||||||
|
if (parts.length === 2) {
|
||||||
|
[pluginType, name] = parts;
|
||||||
|
} else if (parts.length === 3) {
|
||||||
|
[pluginType, subtype, name] = parts;
|
||||||
|
} else {
|
||||||
|
const ownerName = owner?.name || pluginKey;
|
||||||
|
throw new Error(`插件依赖格式错误: ${ownerName} 依赖 ${pluginKey}`);
|
||||||
|
}
|
||||||
|
if (!this.registriesMap) {
|
||||||
|
throw new Error("注册表未设置,请先调用 setRegistries");
|
||||||
|
}
|
||||||
|
const target = this.registriesMap[pluginType];
|
||||||
|
if (!target) {
|
||||||
|
const ownerName = owner?.name || pluginKey;
|
||||||
|
throw new Error(`插件依赖格式错误: ${ownerName} 依赖 ${pluginKey},未知插件类型 ${pluginType}`);
|
||||||
|
}
|
||||||
|
// addon 类型的 key 需要包含 subtype
|
||||||
|
const registryKey = pluginType === "addon" && subtype ? `${subtype}:${name}` : name;
|
||||||
|
const define = target.registry.getDefine(registryKey) as RegisteredDefineLike;
|
||||||
|
if (!define) {
|
||||||
|
throw new Error(`插件依赖缺失: ${owner?.name || pluginKey} 依赖 ${pluginKey},但该插件未注册或已禁用`);
|
||||||
|
}
|
||||||
|
return { ...define, key: pluginKey, pluginType: target.pluginType, addonType: target.addonType };
|
||||||
|
}
|
||||||
|
|
||||||
|
private async doEnsureInstalled(options: { dependencies: Record<string, string>; logger?: ILogger }): Promise<InstallResult> {
|
||||||
|
let { dependencies } = options;
|
||||||
|
const log = options.logger || defaultLogger;
|
||||||
|
return await this.withInstallLock(async () => {
|
||||||
|
const rootDir = this.getRuntimeDepsRootDir();
|
||||||
|
const packageJsonPath = path.join(rootDir, "package.json");
|
||||||
|
const lockPath = path.join(rootDir, "pnpm-lock.yaml");
|
||||||
|
log.info(`第三方依赖安装: ${JSON.stringify(dependencies)}`);
|
||||||
|
dependencies = this.mergeInstalledDependencies(this.readManifestDependencies(packageJsonPath), dependencies);
|
||||||
|
const dependenciesHash = this.createDependenciesHash(dependencies);
|
||||||
|
const statePath = path.join(rootDir, "install-state.json");
|
||||||
|
const currentState = this.readInstallState(statePath);
|
||||||
|
if (currentState?.dependenciesHash === dependenciesHash && fs.existsSync(path.join(rootDir, "node_modules"))) {
|
||||||
|
log.info("第三方依赖已安装");
|
||||||
|
return { registryUrl: currentState.registryUrl || "", packageJsonPath };
|
||||||
|
}
|
||||||
|
const manifest = { name: "certd-runtime-deps", private: true, type: "module", dependencies };
|
||||||
|
fs.writeFileSync(packageJsonPath, JSON.stringify(manifest, null, 2), "utf8");
|
||||||
|
const registryUrl = await this.registryResolver.resolve();
|
||||||
|
const env = this.buildChildEnv(registryUrl);
|
||||||
|
const command = this.getPnpmCommand();
|
||||||
|
const pnpmVersion = await this.getPnpmVersion(command, env);
|
||||||
|
const args = ["install", "--prod", "--ignore-scripts", "--ignore-workspace", "--no-frozen-lockfile", "--reporter=append-only"];
|
||||||
|
if (registryUrl) {
|
||||||
|
args.push(`--registry=${registryUrl}`);
|
||||||
|
}
|
||||||
|
log.info(`开始安装第三方依赖: ${Object.keys(dependencies).join(", ")}`);
|
||||||
|
const result = await this.commandRunner.run(command, args, { cwd: rootDir, timeoutMs: this.installTimeoutMs, env });
|
||||||
|
if (result.code !== 0) {
|
||||||
|
const message = result.stderr || result.stdout || "unknown error";
|
||||||
|
this.writeInstallState(statePath, {
|
||||||
|
...currentState,
|
||||||
|
installedAt: currentState?.installedAt,
|
||||||
|
failedAt: new Date().toISOString(),
|
||||||
|
registryUrl,
|
||||||
|
dependenciesHash,
|
||||||
|
nodeVersion: process.version,
|
||||||
|
pnpmVersion,
|
||||||
|
lockFileExists: fs.existsSync(lockPath),
|
||||||
|
lastError: message,
|
||||||
|
});
|
||||||
|
throw new Error(`动态依赖安装失败: ${message}`);
|
||||||
|
}
|
||||||
|
this.writeInstallState(statePath, { installedAt: new Date().toISOString(), registryUrl, dependenciesHash, nodeVersion: process.version, pnpmVersion, lockFileExists: fs.existsSync(lockPath) });
|
||||||
|
log.info("第三方依赖安装完成");
|
||||||
|
return { registryUrl, packageJsonPath };
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private async withInstallLock<T>(run: () => Promise<T>): Promise<T> {
|
||||||
|
const rootDir = this.getRuntimeDepsRootDir();
|
||||||
|
fs.mkdirSync(rootDir, { recursive: true });
|
||||||
|
const lockFile = path.join(rootDir, ".install.lock");
|
||||||
|
const previous = PROCESS_LOCKS.get(lockFile);
|
||||||
|
if (previous) {
|
||||||
|
await previous.catch(() => undefined);
|
||||||
|
}
|
||||||
|
let releaseProcessLock!: () => void;
|
||||||
|
const current = new Promise<void>(resolve => {
|
||||||
|
releaseProcessLock = resolve;
|
||||||
|
});
|
||||||
|
PROCESS_LOCKS.set(lockFile, current);
|
||||||
|
let fd: number | undefined;
|
||||||
|
try {
|
||||||
|
fd = await this.acquireFileLock(lockFile);
|
||||||
|
return await run();
|
||||||
|
} finally {
|
||||||
|
if (fd != null) {
|
||||||
|
fs.closeSync(fd);
|
||||||
|
try {
|
||||||
|
fs.rmSync(lockFile, { force: true });
|
||||||
|
} catch {
|
||||||
|
try {
|
||||||
|
fs.rmSync(lockFile, { force: true });
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
releaseProcessLock();
|
||||||
|
if (PROCESS_LOCKS.get(lockFile) === current) {
|
||||||
|
PROCESS_LOCKS.delete(lockFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async acquireFileLock(lockFile: string) {
|
||||||
|
const deadline = Date.now() + this.installTimeoutMs;
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
const fd = fs.openSync(lockFile, "wx");
|
||||||
|
fs.writeFileSync(fd, JSON.stringify({ pid: process.pid, createdAt: new Date().toISOString() }), "utf8");
|
||||||
|
return fd;
|
||||||
|
} catch (error: any) {
|
||||||
|
if (error?.code !== "EEXIST") {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
if (Date.now() > deadline) {
|
||||||
|
throw new Error(`动态依赖安装锁等待超时: ${lockFile}`);
|
||||||
|
}
|
||||||
|
await this.waitForExternalLock(lockFile, deadline);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async waitForExternalLock(lockFile: string, deadline: number) {
|
||||||
|
while (fs.existsSync(lockFile)) {
|
||||||
|
if (Date.now() > deadline) {
|
||||||
|
throw new Error(`动态依赖安装锁等待超时: ${lockFile}`);
|
||||||
|
}
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 300));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async clearRuntimeDeps() {
|
||||||
|
const rootDir = this.getRuntimeDepsRootDir();
|
||||||
|
const normalizedRootDir = path.normalize(rootDir);
|
||||||
|
if (!normalizedRootDir.endsWith(path.normalize(".runtime-deps"))) {
|
||||||
|
throw new Error(`动态依赖目录配置异常,拒绝清理: ${rootDir}`);
|
||||||
|
}
|
||||||
|
await this.withInstallLock(async () => {
|
||||||
|
if (fs.existsSync(rootDir)) {
|
||||||
|
const entries = fs.readdirSync(rootDir);
|
||||||
|
for (const entry of entries) {
|
||||||
|
if (entry === ".install.lock") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
fs.rmSync(path.join(rootDir, entry), { recursive: true, force: true });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.installPromises.clear();
|
||||||
|
return undefined;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
getMergedLazyDependencies(): Record<string, string> {
|
||||||
|
return { ...this.lazyDependencies, ...this.pluginLazyDependencies };
|
||||||
|
}
|
||||||
|
|
||||||
|
collectPluginDeps(logger?: ILogger) {
|
||||||
|
if (!this.registriesMap) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const deps: Record<string, string> = {};
|
||||||
|
for (const { registry } of Object.values(this.registriesMap)) {
|
||||||
|
const defineList = registry.getDefineList();
|
||||||
|
for (const define of defineList) {
|
||||||
|
const dependPackages = (define as any).dependPackages as Record<string, string> | undefined;
|
||||||
|
if (!dependPackages) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (const [pkgName, range] of Object.entries(dependPackages)) {
|
||||||
|
const existing = deps[pkgName];
|
||||||
|
if (existing && !areRangesCompatible(existing, range)) {
|
||||||
|
(logger || defaultLogger).warn?.(`懒加载依赖版本冲突: ${pkgName} => ${existing} vs ${range},保留已有版本`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
deps[pkgName] = range;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.pluginLazyDependencies = deps;
|
||||||
|
(logger || defaultLogger).info(`从插件注册表收集到 ${Object.keys(deps).length} 个懒加载依赖`);
|
||||||
|
}
|
||||||
|
|
||||||
|
refreshPluginDeps(logger?: ILogger) {
|
||||||
|
this.collectPluginDeps(logger);
|
||||||
|
}
|
||||||
|
|
||||||
|
private readInstallState(statePath: string): any {
|
||||||
|
if (!fs.existsSync(statePath)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return JSON.parse(fs.readFileSync(statePath, "utf8"));
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private writeInstallState(statePath: string, state: any) {
|
||||||
|
fs.writeFileSync(statePath, JSON.stringify(state, null, 2), "utf8");
|
||||||
|
}
|
||||||
|
|
||||||
|
private readManifestDependencies(packageJsonPath: string): Record<string, string> {
|
||||||
|
if (!fs.existsSync(packageJsonPath)) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const manifest = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
|
||||||
|
return manifest.dependencies || {};
|
||||||
|
} catch {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private mergeInstalledDependencies(installed: Record<string, string>, requested: Record<string, string>) {
|
||||||
|
const dependencies = { ...installed };
|
||||||
|
for (const [packageName, range] of Object.entries(requested)) {
|
||||||
|
const installedRange = dependencies[packageName];
|
||||||
|
if (installedRange && !areRangesCompatible(installedRange, range)) {
|
||||||
|
throw new Error(`动态依赖版本冲突: ${packageName} => installed:${installedRange}, requested:${range}`);
|
||||||
|
}
|
||||||
|
dependencies[packageName] = installedRange || range;
|
||||||
|
}
|
||||||
|
return dependencies;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async getPnpmVersion(command: string, env: NodeJS.ProcessEnv) {
|
||||||
|
const result = await this.commandRunner.run(command, ["--version"], { cwd: this.getRuntimeDepsRootDir(), timeoutMs: Math.min(this.installTimeoutMs, 10000), env });
|
||||||
|
if (result.code !== 0) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return (result.stdout || result.stderr || "").trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
private getPnpmCommand() {
|
||||||
|
return this.pnpmCommand || "pnpm";
|
||||||
|
}
|
||||||
|
|
||||||
|
private buildChildEnv(registryUrl: string) {
|
||||||
|
const env = { ...process.env };
|
||||||
|
for (const key of ["NODE_OPTIONS", "VSCODE_INSPECTOR_OPTIONS", "NODE_INSPECTOR_PORT", "NODE_DEBUG"]) {
|
||||||
|
if (!env[key]) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (key === "NODE_OPTIONS") {
|
||||||
|
env[key] = this.stripDebugNodeOptions(env[key] as string);
|
||||||
|
} else {
|
||||||
|
delete env[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (registryUrl) {
|
||||||
|
env.npm_config_registry = registryUrl;
|
||||||
|
env.pnpm_config_registry = registryUrl;
|
||||||
|
}
|
||||||
|
env.CI = env.CI || "true";
|
||||||
|
env.npm_config_confirm_modules_purge = "false";
|
||||||
|
env.pnpm_config_confirm_modules_purge = "false";
|
||||||
|
return env;
|
||||||
|
}
|
||||||
|
|
||||||
|
private stripDebugNodeOptions(value: string) {
|
||||||
|
return value
|
||||||
|
.split(/\s+/)
|
||||||
|
.filter(Boolean)
|
||||||
|
.filter(item => !/^--inspect(-brk|-port)?(=|$)/.test(item))
|
||||||
|
.filter(item => !/^--debug(=|$)/.test(item))
|
||||||
|
.join(" ");
|
||||||
|
}
|
||||||
|
|
||||||
|
getRuntimeDepsRootDir() {
|
||||||
|
return path.resolve(this.runtimeDepsRootDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
private createDependenciesHash(dependencies: Record<string, string>) {
|
||||||
|
return crypto.createHash("sha256").update(JSON.stringify(dependencies)).digest("hex");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function isPluginVersionCompatible(plugin: RuntimeDependencyPluginDefine, expectedRange: string) {
|
||||||
|
if (!expectedRange || expectedRange === "*") {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!plugin.version) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return areRangesCompatible(expectedRange, plugin.version);
|
||||||
|
}
|
||||||
|
|
||||||
|
let runtimeDepsServiceInstance: RuntimeDepsService | null = null;
|
||||||
|
|
||||||
|
export function initRuntimeDepsService(config: RuntimeDepsConfig, registries: any): RuntimeDepsService {
|
||||||
|
runtimeDepsServiceInstance = new RuntimeDepsService(config, registries);
|
||||||
|
return runtimeDepsServiceInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getRuntimeDepsService(): RuntimeDepsService {
|
||||||
|
if (!runtimeDepsServiceInstance) {
|
||||||
|
throw new Error("RuntimeDepsService 未初始化");
|
||||||
|
}
|
||||||
|
return runtimeDepsServiceInstance!;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function importRuntime(specifier: string, logger: ILogger = defaultLogger): Promise<any> {
|
||||||
|
return getRuntimeDepsService().importRuntime(specifier, logger);
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,6 +3,10 @@
|
|||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||||
|
|
||||||
|
## [1.42.5](https://github.com/certd/certd/compare/v1.42.4...v1.42.5) (2026-07-15)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @certd/lib-huawei
|
||||||
|
|
||||||
## [1.42.4](https://github.com/certd/certd/compare/v1.42.3...v1.42.4) (2026-07-11)
|
## [1.42.4](https://github.com/certd/certd/compare/v1.42.3...v1.42.4) (2026-07-11)
|
||||||
|
|
||||||
**Note:** Version bump only for package @certd/lib-huawei
|
**Note:** Version bump only for package @certd/lib-huawei
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@certd/lib-huawei",
|
"name": "@certd/lib-huawei",
|
||||||
"private": false,
|
"private": false,
|
||||||
"version": "1.42.4",
|
"version": "1.42.5",
|
||||||
"main": "./dist/bundle.js",
|
"main": "./dist/bundle.js",
|
||||||
"module": "./dist/bundle.js",
|
"module": "./dist/bundle.js",
|
||||||
"types": "./dist/d/index.d.ts",
|
"types": "./dist/d/index.d.ts",
|
||||||
@@ -26,6 +26,7 @@
|
|||||||
"@typescript-eslint/eslint-plugin": "^8.26.1",
|
"@typescript-eslint/eslint-plugin": "^8.26.1",
|
||||||
"@typescript-eslint/parser": "^8.26.1",
|
"@typescript-eslint/parser": "^8.26.1",
|
||||||
"cross-env": "^7.0.3",
|
"cross-env": "^7.0.3",
|
||||||
|
"eslint": "^8.57.0",
|
||||||
"esmock": "^2.7.5",
|
"esmock": "^2.7.5",
|
||||||
"prettier": "3.3.3",
|
"prettier": "3.3.3",
|
||||||
"tslib": "^2.8.1"
|
"tslib": "^2.8.1"
|
||||||
|
|||||||
@@ -3,6 +3,10 @@
|
|||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||||
|
|
||||||
|
## [1.42.5](https://github.com/certd/certd/compare/v1.42.4...v1.42.5) (2026-07-15)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @certd/lib-iframe
|
||||||
|
|
||||||
## [1.42.4](https://github.com/certd/certd/compare/v1.42.3...v1.42.4) (2026-07-11)
|
## [1.42.4](https://github.com/certd/certd/compare/v1.42.3...v1.42.4) (2026-07-11)
|
||||||
|
|
||||||
**Note:** Version bump only for package @certd/lib-iframe
|
**Note:** Version bump only for package @certd/lib-iframe
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@certd/lib-iframe",
|
"name": "@certd/lib-iframe",
|
||||||
"private": false,
|
"private": false,
|
||||||
"version": "1.42.4",
|
"version": "1.42.5",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
"module": "./dist/index.js",
|
"module": "./dist/index.js",
|
||||||
|
|||||||
@@ -3,6 +3,10 @@
|
|||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||||
|
|
||||||
|
## [1.42.5](https://github.com/certd/certd/compare/v1.42.4...v1.42.5) (2026-07-15)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @certd/jdcloud
|
||||||
|
|
||||||
## [1.42.4](https://github.com/certd/certd/compare/v1.42.3...v1.42.4) (2026-07-11)
|
## [1.42.4](https://github.com/certd/certd/compare/v1.42.3...v1.42.4) (2026-07-11)
|
||||||
|
|
||||||
**Note:** Version bump only for package @certd/jdcloud
|
**Note:** Version bump only for package @certd/jdcloud
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@certd/jdcloud",
|
"name": "@certd/jdcloud",
|
||||||
"version": "1.42.4",
|
"version": "1.42.5",
|
||||||
"description": "jdcloud openApi sdk",
|
"description": "jdcloud openApi sdk",
|
||||||
"main": "./dist/bundle.js",
|
"main": "./dist/bundle.js",
|
||||||
"module": "./dist/bundle.js",
|
"module": "./dist/bundle.js",
|
||||||
@@ -35,6 +35,7 @@
|
|||||||
"chai": "^5.1.0",
|
"chai": "^5.1.0",
|
||||||
"config": "^1.30.0",
|
"config": "^1.30.0",
|
||||||
"cross-env": "^7.0.3",
|
"cross-env": "^7.0.3",
|
||||||
|
"eslint": "^8.57.0",
|
||||||
"esmock": "^2.7.5",
|
"esmock": "^2.7.5",
|
||||||
"js-yaml": "^3.11.0",
|
"js-yaml": "^3.11.0",
|
||||||
"mocha": "^10.6.0",
|
"mocha": "^10.6.0",
|
||||||
|
|||||||
@@ -3,6 +3,10 @@
|
|||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||||
|
|
||||||
|
## [1.42.5](https://github.com/certd/certd/compare/v1.42.4...v1.42.5) (2026-07-15)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @certd/lib-k8s
|
||||||
|
|
||||||
## [1.42.4](https://github.com/certd/certd/compare/v1.42.3...v1.42.4) (2026-07-11)
|
## [1.42.4](https://github.com/certd/certd/compare/v1.42.3...v1.42.4) (2026-07-11)
|
||||||
|
|
||||||
**Note:** Version bump only for package @certd/lib-k8s
|
**Note:** Version bump only for package @certd/lib-k8s
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@certd/lib-k8s",
|
"name": "@certd/lib-k8s",
|
||||||
"private": false,
|
"private": false,
|
||||||
"version": "1.42.4",
|
"version": "1.42.5",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
"module": "./dist/index.js",
|
"module": "./dist/index.js",
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
"lint": "eslint --fix"
|
"lint": "eslint --fix"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@certd/basic": "^1.42.4",
|
"@certd/basic": "^1.42.5",
|
||||||
"@kubernetes/client-node": "0.21.0"
|
"@kubernetes/client-node": "0.21.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@@ -3,6 +3,12 @@
|
|||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||||
|
|
||||||
|
## [1.42.5](https://github.com/certd/certd/compare/v1.42.4...v1.42.5) (2026-07-15)
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* 修复上传到cos报runtimeDepsService未初始化的问题 ([167b303](https://github.com/certd/certd/commit/167b303faeca02cc11cf97e4be2a3df914852167))
|
||||||
|
|
||||||
## [1.42.4](https://github.com/certd/certd/compare/v1.42.3...v1.42.4) (2026-07-11)
|
## [1.42.4](https://github.com/certd/certd/compare/v1.42.3...v1.42.4) (2026-07-11)
|
||||||
|
|
||||||
### Bug Fixes
|
### Bug Fixes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@certd/lib-server",
|
"name": "@certd/lib-server",
|
||||||
"version": "1.42.4",
|
"version": "1.42.5",
|
||||||
"description": "midway with flyway, sql upgrade way ",
|
"description": "midway with flyway, sql upgrade way ",
|
||||||
"private": false,
|
"private": false,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
@@ -29,11 +29,11 @@
|
|||||||
],
|
],
|
||||||
"license": "AGPL",
|
"license": "AGPL",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@certd/acme-client": "^1.42.4",
|
"@certd/acme-client": "^1.42.5",
|
||||||
"@certd/basic": "^1.42.4",
|
"@certd/basic": "^1.42.5",
|
||||||
"@certd/pipeline": "^1.42.4",
|
"@certd/pipeline": "^1.42.5",
|
||||||
"@certd/plugin-lib": "^1.42.4",
|
"@certd/plugin-lib": "^1.42.5",
|
||||||
"@certd/plus-core": "^1.42.4",
|
"@certd/plus-core": "^1.42.5",
|
||||||
"@midwayjs/cache": "3.14.0",
|
"@midwayjs/cache": "3.14.0",
|
||||||
"@midwayjs/core": "3.20.11",
|
"@midwayjs/core": "3.20.11",
|
||||||
"@midwayjs/i18n": "3.20.13",
|
"@midwayjs/i18n": "3.20.13",
|
||||||
|
|||||||
@@ -1,34 +0,0 @@
|
|||||||
/// <reference types="mocha" />
|
|
||||||
|
|
||||||
import assert from "node:assert/strict";
|
|
||||||
import { AuditLogContext } from "./audit.js";
|
|
||||||
|
|
||||||
// AuditLog decorator and getAuditLogOptions are removed since auditLog()
|
|
||||||
// now signals audit intent directly via ctx.auditLog.enabled
|
|
||||||
|
|
||||||
describe("AuditLogContext type", () => {
|
|
||||||
it("supports enabled flag", () => {
|
|
||||||
const ctx: AuditLogContext = {
|
|
||||||
type: "pipeline",
|
|
||||||
action: "删除流水线",
|
|
||||||
append: ["ID:5"],
|
|
||||||
content: "删除了流水线(ID:5)",
|
|
||||||
projectId: 3,
|
|
||||||
enabled: true,
|
|
||||||
};
|
|
||||||
|
|
||||||
assert.equal(ctx.enabled, true);
|
|
||||||
assert.equal(ctx.type, "pipeline");
|
|
||||||
assert.equal(ctx.content, "删除了流水线(ID:5)");
|
|
||||||
assert.equal(ctx.projectId, 3);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("works with minimal fields", () => {
|
|
||||||
const ctx: AuditLogContext = {
|
|
||||||
enabled: true,
|
|
||||||
append: ["提交2条"],
|
|
||||||
};
|
|
||||||
|
|
||||||
assert.equal(ctx.enabled, true);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
export type AuditLogOptions = {
|
|
||||||
type?: string;
|
|
||||||
action?: string;
|
|
||||||
content?: string;
|
|
||||||
template?: string;
|
|
||||||
disabled?: boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type AuditLogContext = {
|
|
||||||
type?: string;
|
|
||||||
action?: string;
|
|
||||||
append?: string | string[];
|
|
||||||
content?: string;
|
|
||||||
projectId?: number;
|
|
||||||
enabled?: boolean;
|
|
||||||
scope?: string;
|
|
||||||
userId?: number;
|
|
||||||
username?: string;
|
|
||||||
success?: boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
/** 审计日志方法的参数类型 */
|
|
||||||
export type AuditLogParam = {
|
|
||||||
type?: string;
|
|
||||||
action?: string;
|
|
||||||
content?: string;
|
|
||||||
append?: string | string[];
|
|
||||||
projectId?: number;
|
|
||||||
userId?: number;
|
|
||||||
username?: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
/** AuditService.log() 参数类型 */
|
|
||||||
export type AuditLogWriteParam = {
|
|
||||||
userId: number;
|
|
||||||
type: string;
|
|
||||||
action: string;
|
|
||||||
content: string;
|
|
||||||
username?: string;
|
|
||||||
projectId?: number;
|
|
||||||
ipAddress?: string;
|
|
||||||
scope?: string;
|
|
||||||
success?: boolean;
|
|
||||||
};
|
|
||||||
@@ -3,7 +3,6 @@ import type { IMidwayContainer } from "@midwayjs/core";
|
|||||||
import * as koa from "@midwayjs/koa";
|
import * as koa from "@midwayjs/koa";
|
||||||
import { Constants } from "./constants.js";
|
import { Constants } from "./constants.js";
|
||||||
import { isEnterprise } from "./mode.js";
|
import { isEnterprise } from "./mode.js";
|
||||||
import type { AuditLogContext, AuditLogParam } from "./audit.js";
|
|
||||||
|
|
||||||
export abstract class BaseController {
|
export abstract class BaseController {
|
||||||
@Inject()
|
@Inject()
|
||||||
@@ -128,43 +127,4 @@ export abstract class BaseController {
|
|||||||
}
|
}
|
||||||
return { projectId, userId };
|
return { projectId, userId };
|
||||||
}
|
}
|
||||||
|
|
||||||
getAuditType(): string {
|
|
||||||
return "unknown";
|
|
||||||
}
|
|
||||||
|
|
||||||
auditLog(bean: AuditLogParam = {}) {
|
|
||||||
const auditLog = this.ensureAuditLogContext();
|
|
||||||
auditLog.enabled = true;
|
|
||||||
if (bean.userId != null) {
|
|
||||||
auditLog.userId = bean.userId;
|
|
||||||
}
|
|
||||||
if (bean.username != null) {
|
|
||||||
auditLog.username = bean.username;
|
|
||||||
}
|
|
||||||
if (bean.type != null) {
|
|
||||||
auditLog.type = bean.type;
|
|
||||||
}
|
|
||||||
if (bean.action != null) {
|
|
||||||
auditLog.action = bean.action;
|
|
||||||
}
|
|
||||||
if (bean.projectId != null) {
|
|
||||||
auditLog.projectId = bean.projectId;
|
|
||||||
}
|
|
||||||
if (bean.content) {
|
|
||||||
auditLog.content = bean.content;
|
|
||||||
}
|
|
||||||
if (bean.append) {
|
|
||||||
const items = Array.isArray(bean.append) ? bean.append : [bean.append];
|
|
||||||
const old = Array.isArray(auditLog.append) ? auditLog.append : auditLog.append ? [auditLog.append] : [];
|
|
||||||
auditLog.append = [...old, ...items].filter(item => item && String(item).trim());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private ensureAuditLogContext(): AuditLogContext {
|
|
||||||
if (!this.ctx.auditLog) {
|
|
||||||
this.ctx.auditLog = {};
|
|
||||||
}
|
|
||||||
return this.ctx.auditLog;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,21 @@
|
|||||||
export const Constants = {
|
export const Constants = {
|
||||||
dataDir: "./data",
|
dataDir: './data',
|
||||||
role: {
|
role: {
|
||||||
defaultUser: 3,
|
defaultUser: 3,
|
||||||
},
|
},
|
||||||
per: {
|
per: {
|
||||||
//无需登录
|
//无需登录
|
||||||
guest: "_guest_",
|
guest: '_guest_',
|
||||||
//无需登录
|
//无需登录
|
||||||
anonymous: "_guest_",
|
anonymous: '_guest_',
|
||||||
//无需登录,有 token 时解析当前用户
|
//无需登录,有 token 时解析当前用户
|
||||||
guestOptionalAuth: "_guestOptionalAuth_",
|
guestOptionalAuth: '_guestOptionalAuth_',
|
||||||
//仅需要登录
|
//仅需要登录
|
||||||
authOnly: "_authOnly_",
|
authOnly: '_authOnly_',
|
||||||
//仅需要登录
|
//仅需要登录
|
||||||
loginOnly: "_authOnly_",
|
loginOnly: '_authOnly_',
|
||||||
|
|
||||||
open: "_open_",
|
open: '_open_',
|
||||||
},
|
},
|
||||||
res: {
|
res: {
|
||||||
serverError(message: string) {
|
serverError(message: string) {
|
||||||
@@ -26,102 +26,102 @@ export const Constants = {
|
|||||||
},
|
},
|
||||||
error: {
|
error: {
|
||||||
code: 1,
|
code: 1,
|
||||||
message: "Internal server error",
|
message: 'Internal server error',
|
||||||
},
|
},
|
||||||
success: {
|
success: {
|
||||||
code: 0,
|
code: 0,
|
||||||
message: "success",
|
message: 'success',
|
||||||
},
|
},
|
||||||
validation: {
|
validation: {
|
||||||
code: 10,
|
code: 10,
|
||||||
message: "参数错误",
|
message: '参数错误',
|
||||||
},
|
},
|
||||||
needvip: {
|
needvip: {
|
||||||
code: 88,
|
code: 88,
|
||||||
message: "需要VIP",
|
message: '需要VIP',
|
||||||
},
|
},
|
||||||
needsuite: {
|
needsuite: {
|
||||||
code: 89,
|
code: 89,
|
||||||
message: "需要购买或升级套餐",
|
message: '需要购买或升级套餐',
|
||||||
},
|
},
|
||||||
loginError: {
|
loginError: {
|
||||||
code: 2,
|
code: 2,
|
||||||
message: "登录失败",
|
message: '登录失败',
|
||||||
},
|
},
|
||||||
codeError: {
|
codeError: {
|
||||||
code: 3,
|
code: 3,
|
||||||
message: "验证码错误",
|
message: '验证码错误',
|
||||||
},
|
},
|
||||||
auth: {
|
auth: {
|
||||||
code: 401,
|
code: 401,
|
||||||
message: "您还未登录或token已过期",
|
message: '您还未登录或token已过期',
|
||||||
},
|
},
|
||||||
permission: {
|
permission: {
|
||||||
code: 402,
|
code: 402,
|
||||||
message: "您没有权限",
|
message: '您没有权限',
|
||||||
},
|
},
|
||||||
param: {
|
param: {
|
||||||
code: 400,
|
code: 400,
|
||||||
message: "参数错误",
|
message: '参数错误',
|
||||||
},
|
},
|
||||||
notFound: {
|
notFound: {
|
||||||
code: 404,
|
code: 404,
|
||||||
message: "页面/文件/资源不存在",
|
message: '页面/文件/资源不存在',
|
||||||
},
|
},
|
||||||
|
|
||||||
preview: {
|
preview: {
|
||||||
code: 10001,
|
code: 10001,
|
||||||
message: "对不起,预览环境不允许修改此数据",
|
message: '对不起,预览环境不允许修改此数据',
|
||||||
},
|
},
|
||||||
siteOff: {
|
siteOff:{
|
||||||
code: 10010,
|
code: 10010,
|
||||||
message: "站点已关闭",
|
message: '站点已关闭',
|
||||||
},
|
},
|
||||||
need2fa: {
|
need2fa:{
|
||||||
code: 10020,
|
code: 10020,
|
||||||
message: "需要2FA认证",
|
message: '需要2FA认证',
|
||||||
},
|
},
|
||||||
openKeyError: {
|
openKeyError: {
|
||||||
code: 20000,
|
code: 20000,
|
||||||
message: "ApiToken错误",
|
message: 'ApiToken错误',
|
||||||
},
|
},
|
||||||
openKeySignError: {
|
openKeySignError: {
|
||||||
code: 20001,
|
code: 20001,
|
||||||
message: "ApiToken签名错误",
|
message: 'ApiToken签名错误',
|
||||||
},
|
},
|
||||||
openKeyExpiresError: {
|
openKeyExpiresError: {
|
||||||
code: 20002,
|
code: 20002,
|
||||||
message: "ApiToken时间戳错误",
|
message: 'ApiToken时间戳错误',
|
||||||
},
|
},
|
||||||
openKeySignTypeError: {
|
openKeySignTypeError: {
|
||||||
code: 20003,
|
code: 20003,
|
||||||
message: "ApiToken签名类型不支持",
|
message: 'ApiToken签名类型不支持',
|
||||||
},
|
},
|
||||||
openParamError: {
|
openParamError: {
|
||||||
code: 20010,
|
code: 20010,
|
||||||
message: "请求参数错误",
|
message: '请求参数错误',
|
||||||
},
|
},
|
||||||
openCertNotFound: {
|
openCertNotFound: {
|
||||||
code: 20011,
|
code: 20011,
|
||||||
message: "证书不存在",
|
message: '证书不存在',
|
||||||
},
|
},
|
||||||
openCertNotReady: {
|
openCertNotReady: {
|
||||||
code: 20012,
|
code: 20012,
|
||||||
message: "证书还未生成",
|
message: '证书还未生成',
|
||||||
},
|
},
|
||||||
openCertApplying: {
|
openCertApplying: {
|
||||||
code: 20013,
|
code: 20013,
|
||||||
message: "证书正在申请中,请稍后重新获取",
|
message: '证书正在申请中,请稍后重新获取',
|
||||||
},
|
},
|
||||||
openDomainNoVerifier: {
|
openDomainNoVerifier:{
|
||||||
code: 20014,
|
code: 20014,
|
||||||
message: "域名校验方式未配置",
|
message: '域名校验方式未配置',
|
||||||
},
|
},
|
||||||
openEmailNotFound: {
|
openEmailNotFound: {
|
||||||
code: 20021,
|
code: 20021,
|
||||||
message: "用户邮箱还未配置",
|
message: '用户邮箱还未配置',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
systemUserId: 0, // 系统级别userid固定为0
|
systemUserId: 0, // 系统级别userid固定为0
|
||||||
enterpriseUserId: -1, // 企业模式用户id固定为-1
|
enterpriseUserId: -1 // 企业模式用户id固定为-1
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
import { createRequestParamDecorator } from "@midwayjs/core";
|
|
||||||
|
|
||||||
export const AuditLog = (opts: { type?: string; action?: string; content?: string; enabled?: boolean } = {}) => {
|
|
||||||
return createRequestParamDecorator(ctx => {
|
|
||||||
if (!ctx.auditLog) {
|
|
||||||
ctx.auditLog = {};
|
|
||||||
}
|
|
||||||
ctx.auditLog.enabled = opts.enabled !== false;
|
|
||||||
if (opts.type != null) {
|
|
||||||
ctx.auditLog.type = opts.type;
|
|
||||||
}
|
|
||||||
if (opts.action != null) {
|
|
||||||
ctx.auditLog.action = opts.action;
|
|
||||||
}
|
|
||||||
if (opts.content != null) {
|
|
||||||
ctx.auditLog.content = opts.content;
|
|
||||||
}
|
|
||||||
return ctx.auditLog;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
export * from "./decoractor.js";
|
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
import { ALL, Body, Post, Query } from "@midwayjs/core";
|
import { ALL, Body, Post, Query } from '@midwayjs/core';
|
||||||
import { BaseController } from "./base-controller.js";
|
import { BaseController } from './base-controller.js';
|
||||||
|
|
||||||
export abstract class CrudController<T> extends BaseController {
|
export abstract class CrudController<T> extends BaseController {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
abstract getService<T>();
|
abstract getService<T>();
|
||||||
|
|
||||||
@Post("/page")
|
@Post('/page')
|
||||||
async page(@Body(ALL) body: any) {
|
async page(@Body(ALL) body: any) {
|
||||||
const pageRet = await this.getService().page({
|
const pageRet = await this.getService().page({
|
||||||
query: body.query ?? {},
|
query: body.query ?? {},
|
||||||
@@ -16,7 +16,7 @@ export abstract class CrudController<T> extends BaseController {
|
|||||||
return this.ok(pageRet);
|
return this.ok(pageRet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/list")
|
@Post('/list')
|
||||||
async list(@Body(ALL) body: any) {
|
async list(@Body(ALL) body: any) {
|
||||||
const listRet = await this.getService().list({
|
const listRet = await this.getService().list({
|
||||||
query: body.query ?? {},
|
query: body.query ?? {},
|
||||||
@@ -25,33 +25,33 @@ export abstract class CrudController<T> extends BaseController {
|
|||||||
return this.ok(listRet);
|
return this.ok(listRet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/add")
|
@Post('/add')
|
||||||
async add(@Body(ALL) bean: any) {
|
async add(@Body(ALL) bean: any) {
|
||||||
delete bean.id;
|
delete bean.id;
|
||||||
const id = await this.getService().add(bean);
|
const id = await this.getService().add(bean);
|
||||||
return this.ok(id);
|
return this.ok(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/info")
|
@Post('/info')
|
||||||
async info(@Query("id") id: number) {
|
async info(@Query('id') id: number) {
|
||||||
const bean = await this.getService().info(id);
|
const bean = await this.getService().info(id);
|
||||||
return this.ok(bean);
|
return this.ok(bean);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/update")
|
@Post('/update')
|
||||||
async update(@Body(ALL) bean: any) {
|
async update(@Body(ALL) bean: any) {
|
||||||
await this.getService().update(bean);
|
await this.getService().update(bean);
|
||||||
return this.ok(null);
|
return this.ok(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/delete")
|
@Post('/delete')
|
||||||
async delete(@Query("id") id: number) {
|
async delete(@Query('id') id: number) {
|
||||||
await this.getService().delete([id]);
|
await this.getService().delete([id]);
|
||||||
return this.ok(null);
|
return this.ok(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/deleteByIds")
|
@Post('/deleteByIds')
|
||||||
async deleteByIds(@Body("ids") ids: number[]) {
|
async deleteByIds(@Body('ids') ids: number[]) {
|
||||||
await this.getService().delete(ids);
|
await this.getService().delete(ids);
|
||||||
return this.ok(null);
|
return this.ok(null);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
import { Constants } from "../constants.js";
|
import { Constants } from '../constants.js';
|
||||||
import { BaseException } from "./base-exception.js";
|
import { BaseException } from './base-exception.js';
|
||||||
/**
|
/**
|
||||||
* 通用异常
|
* 通用异常
|
||||||
*/
|
*/
|
||||||
export class LoginErrorException extends BaseException {
|
export class LoginErrorException extends BaseException {
|
||||||
leftCount: number;
|
leftCount: number;
|
||||||
userId?: number;
|
constructor(message, leftCount: number) {
|
||||||
constructor(message, leftCount: number, userId?: number) {
|
super('LoginErrorException', Constants.res.loginError.code, message ? message : Constants.res.loginError.message);
|
||||||
super("LoginErrorException", Constants.res.loginError.code, message ? message : Constants.res.loginError.message);
|
|
||||||
this.leftCount = leftCount;
|
this.leftCount = leftCount;
|
||||||
this.userId = userId;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
export * from "./base-controller.js";
|
export * from './base-controller.js';
|
||||||
export * from "./constants.js";
|
export * from './constants.js';
|
||||||
export * from "./crud-controller.js";
|
export * from './crud-controller.js';
|
||||||
export * from "./enum-item.js";
|
export * from './enum-item.js';
|
||||||
export * from "./exception/index.js";
|
export * from './exception/index.js';
|
||||||
export * from "./result.js";
|
export * from './result.js';
|
||||||
export * from "./base-service.js";
|
export * from './base-service.js';
|
||||||
export * from "./audit.js";
|
export * from "./mode.js"
|
||||||
export * from "./mode.js";
|
|
||||||
export * from "./core/index.js";
|
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
let adminMode = "saas";
|
let adminMode = "saas"
|
||||||
|
|
||||||
export function setAdminMode(mode: string = "saas") {
|
export function setAdminMode(mode:string = "saas"){
|
||||||
adminMode = mode;
|
adminMode = mode
|
||||||
}
|
}
|
||||||
export function getAdminMode() {
|
export function getAdminMode(){
|
||||||
return adminMode;
|
return adminMode
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isEnterprise() {
|
export function isEnterprise(){
|
||||||
return adminMode === "enterprise";
|
return adminMode === "enterprise"
|
||||||
}
|
}
|
||||||
@@ -1,15 +1,6 @@
|
|||||||
import { HttpClient, ILogger, utils } from "@certd/basic";
|
import { HttpClient, ILogger, utils } from "@certd/basic";
|
||||||
import {upperFirst} from "lodash-es";
|
import { upperFirst } from "lodash-es";
|
||||||
import {
|
import { accessRegistry, FormItemProps, IAccessService, IServiceGetter, PluginRequestHandleReq, Registrable, getRuntimeDepsService } from "@certd/pipeline";
|
||||||
accessRegistry,
|
|
||||||
FormItemProps,
|
|
||||||
IAccessService,
|
|
||||||
IRuntimeDepsService,
|
|
||||||
IServiceGetter,
|
|
||||||
PluginRequestHandleReq,
|
|
||||||
Registrable
|
|
||||||
} from "@certd/pipeline";
|
|
||||||
|
|
||||||
|
|
||||||
export type AddonRequestHandleReqInput<T = any> = {
|
export type AddonRequestHandleReqInput<T = any> = {
|
||||||
id?: number;
|
id?: number;
|
||||||
@@ -19,7 +10,7 @@ export type AddonRequestHandleReqInput<T = any> = {
|
|||||||
|
|
||||||
export type AddonRequestHandleReq<T = any> = {
|
export type AddonRequestHandleReq<T = any> = {
|
||||||
addonType: string;
|
addonType: string;
|
||||||
} &PluginRequestHandleReq<AddonRequestHandleReqInput<T>>;
|
} & PluginRequestHandleReq<AddonRequestHandleReqInput<T>>;
|
||||||
|
|
||||||
export type AddonInputDefine = FormItemProps & {
|
export type AddonInputDefine = FormItemProps & {
|
||||||
title: string;
|
title: string;
|
||||||
@@ -48,8 +39,6 @@ export type AddonInstanceConfig = {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export interface IAddon {
|
export interface IAddon {
|
||||||
ctx: AddonContext;
|
ctx: AddonContext;
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
@@ -67,13 +56,9 @@ export abstract class BaseAddon implements IAddon {
|
|||||||
ctx!: AddonContext;
|
ctx!: AddonContext;
|
||||||
http!: HttpClient;
|
http!: HttpClient;
|
||||||
logger!: ILogger;
|
logger!: ILogger;
|
||||||
runtimeDepsService?: IRuntimeDepsService;
|
|
||||||
|
|
||||||
async importRuntime(specifier: string) {
|
async importRuntime(specifier: string) {
|
||||||
if (!this.runtimeDepsService) {
|
return await getRuntimeDepsService().importRuntime(specifier, this.logger);
|
||||||
return await import(specifier);
|
|
||||||
}
|
|
||||||
return await this.runtimeDepsService.importRuntime(specifier, this.logger);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
title!: string;
|
title!: string;
|
||||||
@@ -85,7 +70,7 @@ export abstract class BaseAddon implements IAddon {
|
|||||||
if (accessId == null) {
|
if (accessId == null) {
|
||||||
throw new Error("您还没有配置授权");
|
throw new Error("您还没有配置授权");
|
||||||
}
|
}
|
||||||
const accessService = await this.ctx.serviceGetter.get<IAccessService>("accessService")
|
const accessService = await this.ctx.serviceGetter.get<IAccessService>("accessService");
|
||||||
let res: any = null;
|
let res: any = null;
|
||||||
if (isCommon) {
|
if (isCommon) {
|
||||||
res = await accessService.getCommonById(accessId);
|
res = await accessService.getCommonById(accessId);
|
||||||
@@ -118,15 +103,12 @@ export abstract class BaseAddon implements IAddon {
|
|||||||
this.ctx = ctx;
|
this.ctx = ctx;
|
||||||
this.http = ctx.http;
|
this.http = ctx.http;
|
||||||
this.logger = ctx.logger;
|
this.logger = ctx.logger;
|
||||||
if (!this.runtimeDepsService && this.ctx.serviceGetter) {
|
|
||||||
this.runtimeDepsService = await this.ctx.serviceGetter.get("runtimeDepsService");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
setDefine = (define:AddonDefine) => {
|
setDefine = (define: AddonDefine) => {
|
||||||
this.define = define;
|
this.define = define;
|
||||||
};
|
};
|
||||||
|
|
||||||
async onRequest(req:AddonRequestHandleReq) {
|
async onRequest(req: AddonRequestHandleReq) {
|
||||||
if (!req.action) {
|
if (!req.action) {
|
||||||
throw new Error("action is required");
|
throw new Error("action is required");
|
||||||
}
|
}
|
||||||
@@ -144,10 +126,8 @@ export abstract class BaseAddon implements IAddon {
|
|||||||
}
|
}
|
||||||
throw new Error(`action ${req.action} not found`);
|
throw new Error(`action ${req.action} not found`);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export interface IAddonGetter {
|
export interface IAddonGetter {
|
||||||
getById<T = any>(id: any): Promise<T>;
|
getById<T = any>(id: any): Promise<T>;
|
||||||
getCommonById<T = any>(id: any): Promise<T>;
|
getCommonById<T = any>(id: any): Promise<T>;
|
||||||
|
|||||||
@@ -3,6 +3,12 @@
|
|||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||||
|
|
||||||
|
## [1.42.5](https://github.com/certd/certd/compare/v1.42.4...v1.42.5) (2026-07-15)
|
||||||
|
|
||||||
|
### Performance Improvements
|
||||||
|
|
||||||
|
* 给SQLITE_IOERR_WRITE增加友好报错提示,将certd:latest镜像改为certd:slim ([b91c9e4](https://github.com/certd/certd/commit/b91c9e4ea671cb359ef164e27864de1d66cba9d3))
|
||||||
|
|
||||||
## [1.42.4](https://github.com/certd/certd/compare/v1.42.3...v1.42.4) (2026-07-11)
|
## [1.42.4](https://github.com/certd/certd/compare/v1.42.3...v1.42.4) (2026-07-11)
|
||||||
|
|
||||||
**Note:** Version bump only for package @certd/midway-flyway-js
|
**Note:** Version bump only for package @certd/midway-flyway-js
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@certd/midway-flyway-js",
|
"name": "@certd/midway-flyway-js",
|
||||||
"version": "1.42.4",
|
"version": "1.42.5",
|
||||||
"description": "midway with flyway, sql upgrade way ",
|
"description": "midway with flyway, sql upgrade way ",
|
||||||
"private": false,
|
"private": false,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import * as path from 'path';
|
import * as path from "path";
|
||||||
import * as fs from 'fs';
|
import * as fs from "fs";
|
||||||
import { QueryRunner, Table } from 'typeorm';
|
import { QueryRunner, Table } from "typeorm";
|
||||||
import { FlywayHistory } from './entity.js';
|
import { FlywayHistory } from "./entity.js";
|
||||||
import * as crypto from 'crypto';
|
import * as crypto from "crypto";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 脚本文件信息
|
* 脚本文件信息
|
||||||
@@ -32,10 +32,10 @@ const DefaultLogger = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
let customLogger:any = null;
|
let customLogger: any = null;
|
||||||
export function setFlywayLogger (logger: any) {
|
export function setFlywayLogger(logger: any) {
|
||||||
customLogger = logger;
|
customLogger = logger;
|
||||||
};
|
}
|
||||||
|
|
||||||
export class Flyway {
|
export class Flyway {
|
||||||
scriptDir;
|
scriptDir;
|
||||||
@@ -45,8 +45,8 @@ export class Flyway {
|
|||||||
connection;
|
connection;
|
||||||
logger;
|
logger;
|
||||||
constructor(opts: any) {
|
constructor(opts: any) {
|
||||||
this.scriptDir = opts.scriptDir ?? 'db/migration';
|
this.scriptDir = opts.scriptDir ?? "db/migration";
|
||||||
this.flywayTableName = opts.flywayTableName ?? 'flyway_history';
|
this.flywayTableName = opts.flywayTableName ?? "flyway_history";
|
||||||
this.baseline = opts.baseline ?? false;
|
this.baseline = opts.baseline ?? false;
|
||||||
this.allowHashNotMatch = opts.allowHashNotMatch ?? false;
|
this.allowHashNotMatch = opts.allowHashNotMatch ?? false;
|
||||||
this.logger = customLogger || opts.logger || DefaultLogger;
|
this.logger = customLogger || opts.logger || DefaultLogger;
|
||||||
@@ -54,9 +54,9 @@ export class Flyway {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async run(ignores?: (RegExp | string)[]) {
|
async run(ignores?: (RegExp | string)[]) {
|
||||||
this.logger.info('[ midfly ] start-------------');
|
this.logger.info("[ midfly ] start-------------");
|
||||||
if (!fs.existsSync(this.scriptDir)) {
|
if (!fs.existsSync(this.scriptDir)) {
|
||||||
this.logger.info('[ midfly ] scriptDir<' + this.scriptDir + '> not found');
|
this.logger.info("[ midfly ] scriptDir<" + this.scriptDir + "> not found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,7 +77,7 @@ export class Flyway {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!file.isBaseline) {
|
if (!file.isBaseline) {
|
||||||
this.logger.info('need exec script file: ', file.script);
|
this.logger.info("need exec script file: ", file.script);
|
||||||
//执行sql文件
|
//执行sql文件
|
||||||
if (/\.sql$/.test(file.script)) {
|
if (/\.sql$/.test(file.script)) {
|
||||||
await this.execSql(filepath, queryRunner);
|
await this.execSql(filepath, queryRunner);
|
||||||
@@ -87,7 +87,7 @@ export class Flyway {
|
|||||||
// await this.execJsOrTs(filepath, t);
|
// await this.execJsOrTs(filepath, t);
|
||||||
// }
|
// }
|
||||||
} else {
|
} else {
|
||||||
this.logger.info('baseline script file: ', file.script);
|
this.logger.info("baseline script file: ", file.script);
|
||||||
}
|
}
|
||||||
await this.storeSqlExecLog(file.script, filepath, true, queryRunner);
|
await this.storeSqlExecLog(file.script, filepath, true, queryRunner);
|
||||||
await queryRunner.commitTransaction();
|
await queryRunner.commitTransaction();
|
||||||
@@ -95,10 +95,15 @@ export class Flyway {
|
|||||||
this.logger.error(err);
|
this.logger.error(err);
|
||||||
await this.storeSqlExecLog(file.script, filepath, false, queryRunner);
|
await this.storeSqlExecLog(file.script, filepath, false, queryRunner);
|
||||||
await queryRunner.rollbackTransaction();
|
await queryRunner.rollbackTransaction();
|
||||||
|
|
||||||
|
if (err.code === "SQLITE_IOERR_WRITE") {
|
||||||
|
this.logger.warn("SQLite数据库写入失败,可能您的操作系统版本太低,请将「certd:latest」镜像改为「certd:slim」即可。(如需指定版本可以修改成「certd:[version]-slim」)", file.script);
|
||||||
|
}
|
||||||
|
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.logger.info('[ midfly ] end-------------');
|
this.logger.info("[ midfly ] end-------------");
|
||||||
}
|
}
|
||||||
|
|
||||||
private async storeSqlExecLog(filename: string, filepath: string, success: boolean, queryRunner: QueryRunner) {
|
private async storeSqlExecLog(filename: string, filepath: string, success: boolean, queryRunner: QueryRunner) {
|
||||||
@@ -160,17 +165,17 @@ export class Flyway {
|
|||||||
name: this.flywayTableName,
|
name: this.flywayTableName,
|
||||||
columns: [
|
columns: [
|
||||||
{
|
{
|
||||||
name: 'id',
|
name: "id",
|
||||||
type: this.connection.driver.normalizeType({
|
type: this.connection.driver.normalizeType({
|
||||||
type: this.connection.driver.mappedDataTypes.migrationId,
|
type: this.connection.driver.mappedDataTypes.migrationId,
|
||||||
}),
|
}),
|
||||||
isGenerated: true,
|
isGenerated: true,
|
||||||
generationStrategy: 'increment',
|
generationStrategy: "increment",
|
||||||
isPrimary: true,
|
isPrimary: true,
|
||||||
isNullable: false,
|
isNullable: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'timestamp',
|
name: "timestamp",
|
||||||
type: this.connection.driver.normalizeType({
|
type: this.connection.driver.normalizeType({
|
||||||
type: this.connection.driver.mappedDataTypes.migrationTimestamp,
|
type: this.connection.driver.mappedDataTypes.migrationTimestamp,
|
||||||
}),
|
}),
|
||||||
@@ -178,23 +183,23 @@ export class Flyway {
|
|||||||
isNullable: false,
|
isNullable: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'name',
|
name: "name",
|
||||||
type: this.connection.driver.normalizeType({
|
type: this.connection.driver.normalizeType({
|
||||||
type: this.connection.driver.mappedDataTypes.migrationName,
|
type: this.connection.driver.mappedDataTypes.migrationName,
|
||||||
}),
|
}),
|
||||||
isNullable: false,
|
isNullable: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'hash',
|
name: "hash",
|
||||||
type: this.connection.driver.normalizeType({
|
type: this.connection.driver.normalizeType({
|
||||||
type: this.connection.driver.mappedDataTypes.migrationName,
|
type: this.connection.driver.mappedDataTypes.migrationName,
|
||||||
}),
|
}),
|
||||||
isNullable: true,
|
isNullable: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'success',
|
name: "success",
|
||||||
type: this.connection.driver.normalizeType({
|
type: this.connection.driver.normalizeType({
|
||||||
type: 'boolean',
|
type: "boolean",
|
||||||
}),
|
}),
|
||||||
isNullable: true,
|
isNullable: true,
|
||||||
},
|
},
|
||||||
@@ -210,7 +215,7 @@ export class Flyway {
|
|||||||
}
|
}
|
||||||
let ret = false;
|
let ret = false;
|
||||||
for (const ignore of ignores) {
|
for (const ignore of ignores) {
|
||||||
if (typeof ignore === 'string' && file === ignore) {
|
if (typeof ignore === "string" && file === ignore) {
|
||||||
ret = true;
|
ret = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -233,20 +238,20 @@ export class Flyway {
|
|||||||
if (history.hash !== hash && this.allowHashNotMatch === false) {
|
if (history.hash !== hash && this.allowHashNotMatch === false) {
|
||||||
throw new Error(file + `hash conflict ,old: ${history.hash} != new: ${hash}`);
|
throw new Error(file + `hash conflict ,old: ${history.hash} != new: ${hash}`);
|
||||||
}
|
}
|
||||||
this.logger.info('[ midfly ] script<' + file + '> already executed');
|
this.logger.info("[ midfly ] script<" + file + "> already executed");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
this.logger.info('[ midfly ] script<' + file + '> not yet execute');
|
this.logger.info("[ midfly ] script<" + file + "> not yet execute");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getFileHash(filepath: string) {
|
private async getFileHash(filepath: string) {
|
||||||
const content = fs.readFileSync(filepath).toString();
|
const content = fs.readFileSync(filepath).toString();
|
||||||
return crypto.createHash('md5').update(content.toString()).digest('hex');
|
return crypto.createHash("md5").update(content.toString()).digest("hex");
|
||||||
}
|
}
|
||||||
|
|
||||||
private async execSql(filepath: string, queryRunner: QueryRunner) {
|
private async execSql(filepath: string, queryRunner: QueryRunner) {
|
||||||
this.logger.info('[ midfly ] exec ', filepath);
|
this.logger.info("[ midfly ] exec ", filepath);
|
||||||
const content = fs.readFileSync(filepath).toString().trim();
|
const content = fs.readFileSync(filepath).toString().trim();
|
||||||
const arr = this.splitSql2Array(content);
|
const arr = this.splitSql2Array(content);
|
||||||
for (const s of arr) {
|
for (const s of arr) {
|
||||||
@@ -255,11 +260,11 @@ export class Flyway {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async execOnePart(sql: string, queryRunner: QueryRunner) {
|
private async execOnePart(sql: string, queryRunner: QueryRunner) {
|
||||||
this.logger.debug('exec sql index: ', sql);
|
this.logger.debug("exec sql index: ", sql);
|
||||||
try {
|
try {
|
||||||
await queryRunner.query(sql);
|
await queryRunner.query(sql);
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
this.logger.error('exec sql error : ', err.message, err);
|
this.logger.error("exec sql error : ", err.message, err);
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -275,11 +280,11 @@ export class Flyway {
|
|||||||
|
|
||||||
const temp = String(str).trim();
|
const temp = String(str).trim();
|
||||||
|
|
||||||
if (temp === 'null') {
|
if (temp === "null") {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
const semicolon = ';';
|
const semicolon = ";";
|
||||||
const deepChars = ['"', "'"];
|
const deepChars = ['"', "'"];
|
||||||
const splits = [];
|
const splits = [];
|
||||||
|
|
||||||
@@ -289,7 +294,7 @@ export class Flyway {
|
|||||||
|
|
||||||
if (deepChars.indexOf(charAt) >= 0) {
|
if (deepChars.indexOf(charAt) >= 0) {
|
||||||
//如果是深度char
|
//如果是深度char
|
||||||
if (i !== 0 && temp.charAt(i - 1) === '\\') {
|
if (i !== 0 && temp.charAt(i - 1) === "\\") {
|
||||||
//如果前一个是转义字符,忽略它
|
//如果前一个是转义字符,忽略它
|
||||||
} else {
|
} else {
|
||||||
//说明需要进出深度了
|
//说明需要进出深度了
|
||||||
|
|||||||
@@ -3,6 +3,10 @@
|
|||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||||
|
|
||||||
|
## [1.42.5](https://github.com/certd/certd/compare/v1.42.4...v1.42.5) (2026-07-15)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @certd/plugin-cert
|
||||||
|
|
||||||
## [1.42.4](https://github.com/certd/certd/compare/v1.42.3...v1.42.4) (2026-07-11)
|
## [1.42.4](https://github.com/certd/certd/compare/v1.42.3...v1.42.4) (2026-07-11)
|
||||||
|
|
||||||
**Note:** Version bump only for package @certd/plugin-cert
|
**Note:** Version bump only for package @certd/plugin-cert
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@certd/plugin-cert",
|
"name": "@certd/plugin-cert",
|
||||||
"private": false,
|
"private": false,
|
||||||
"version": "1.42.4",
|
"version": "1.42.5",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
"types": "./dist/index.d.ts",
|
"types": "./dist/index.d.ts",
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
"lint": "eslint --fix"
|
"lint": "eslint --fix"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@certd/plugin-lib": "^1.42.4"
|
"@certd/plugin-lib": "^1.42.5"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/chai": "^4.3.12",
|
"@types/chai": "^4.3.12",
|
||||||
|
|||||||
@@ -3,6 +3,12 @@
|
|||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||||
|
|
||||||
|
## [1.42.5](https://github.com/certd/certd/compare/v1.42.4...v1.42.5) (2026-07-15)
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* 修复上传到cos报runtimeDepsService未初始化的问题 ([167b303](https://github.com/certd/certd/commit/167b303faeca02cc11cf97e4be2a3df914852167))
|
||||||
|
|
||||||
## [1.42.4](https://github.com/certd/certd/compare/v1.42.3...v1.42.4) (2026-07-11)
|
## [1.42.4](https://github.com/certd/certd/compare/v1.42.3...v1.42.4) (2026-07-11)
|
||||||
|
|
||||||
### Bug Fixes
|
### Bug Fixes
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@certd/plugin-lib",
|
"name": "@certd/plugin-lib",
|
||||||
"private": false,
|
"private": false,
|
||||||
"version": "1.42.4",
|
"version": "1.42.5",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
"types": "./dist/index.d.ts",
|
"types": "./dist/index.d.ts",
|
||||||
@@ -17,9 +17,9 @@
|
|||||||
"lint": "eslint --fix"
|
"lint": "eslint --fix"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@certd/acme-client": "^1.42.4",
|
"@certd/acme-client": "^1.42.5",
|
||||||
"@certd/basic": "^1.42.4",
|
"@certd/basic": "^1.42.5",
|
||||||
"@certd/pipeline": "^1.42.4",
|
"@certd/pipeline": "^1.42.5",
|
||||||
"dayjs": "^1.11.7",
|
"dayjs": "^1.11.7",
|
||||||
"jszip": "^3.10.1",
|
"jszip": "^3.10.1",
|
||||||
"lodash-es": "^4.17.21",
|
"lodash-es": "^4.17.21",
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { HttpClient, ILogger } from "@certd/basic";
|
import { HttpClient, ILogger } from "@certd/basic";
|
||||||
import { IAccessService, IRuntimeDepsService, PageRes, PageSearch } from "@certd/pipeline";
|
import { IAccessService, PageRes, PageSearch, getRuntimeDepsService } from "@certd/pipeline";
|
||||||
import punycode from "punycode.js";
|
import punycode from "punycode.js";
|
||||||
import { CreateRecordOptions, DnsProviderContext, DnsProviderDefine, DnsResolveRecord, DomainRecord, IDnsProvider, RemoveRecordOptions } from "./api.js";
|
import { CreateRecordOptions, DnsProviderContext, DnsProviderDefine, DnsResolveRecord, DomainRecord, IDnsProvider, RemoveRecordOptions } from "./api.js";
|
||||||
import { dnsProviderRegistry } from "./registry.js";
|
import { dnsProviderRegistry } from "./registry.js";
|
||||||
@@ -7,13 +7,9 @@ export abstract class AbstractDnsProvider<T = any> implements IDnsProvider<T> {
|
|||||||
ctx!: DnsProviderContext;
|
ctx!: DnsProviderContext;
|
||||||
http!: HttpClient;
|
http!: HttpClient;
|
||||||
logger!: ILogger;
|
logger!: ILogger;
|
||||||
runtimeDepsService?: IRuntimeDepsService;
|
|
||||||
|
|
||||||
async importRuntime(specifier: string) {
|
async importRuntime(specifier: string) {
|
||||||
if (!this.runtimeDepsService) {
|
return await getRuntimeDepsService().importRuntime(specifier, this.logger);
|
||||||
throw new Error("runtimeDepsService 未初始化");
|
|
||||||
}
|
|
||||||
return await this.runtimeDepsService.importRuntime(specifier, this.logger);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
usePunyCode(): boolean {
|
usePunyCode(): boolean {
|
||||||
@@ -42,9 +38,6 @@ export abstract class AbstractDnsProvider<T = any> implements IDnsProvider<T> {
|
|||||||
this.ctx = ctx;
|
this.ctx = ctx;
|
||||||
this.logger = ctx.logger;
|
this.logger = ctx.logger;
|
||||||
this.http = ctx.http;
|
this.http = ctx.http;
|
||||||
if (!this.runtimeDepsService && this.ctx.serviceGetter) {
|
|
||||||
this.runtimeDepsService = await this.ctx.serviceGetter.get("runtimeDepsService");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async parseDomain(fullDomain: string) {
|
async parseDomain(fullDomain: string) {
|
||||||
|
|||||||
@@ -3,6 +3,12 @@
|
|||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||||
|
|
||||||
|
## [1.42.5](https://github.com/certd/certd/compare/v1.42.4...v1.42.5) (2026-07-15)
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* 修复上传到cos报runtimeDepsService未初始化的问题 ([167b303](https://github.com/certd/certd/commit/167b303faeca02cc11cf97e4be2a3df914852167))
|
||||||
|
|
||||||
## [1.42.4](https://github.com/certd/certd/compare/v1.42.3...v1.42.4) (2026-07-11)
|
## [1.42.4](https://github.com/certd/certd/compare/v1.42.3...v1.42.4) (2026-07-11)
|
||||||
|
|
||||||
**Note:** Version bump only for package @certd/ui-client
|
**Note:** Version bump only for package @certd/ui-client
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@certd/ui-client",
|
"name": "@certd/ui-client",
|
||||||
"version": "1.42.4",
|
"version": "1.42.5",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite --open",
|
"dev": "vite --open",
|
||||||
@@ -59,7 +59,6 @@
|
|||||||
"class-variance-authority": "^0.7.1",
|
"class-variance-authority": "^0.7.1",
|
||||||
"clsx": "^2.1.1",
|
"clsx": "^2.1.1",
|
||||||
"core-js": "^3.36.0",
|
"core-js": "^3.36.0",
|
||||||
"cos-js-sdk-v5": "^1.7.0",
|
|
||||||
"cron-parser": "^4.9.0",
|
"cron-parser": "^4.9.0",
|
||||||
"cropperjs": "^1.6.1",
|
"cropperjs": "^1.6.1",
|
||||||
"cssnano": "^7.0.6",
|
"cssnano": "^7.0.6",
|
||||||
@@ -105,8 +104,8 @@
|
|||||||
"zod-defaults": "^0.1.3"
|
"zod-defaults": "^0.1.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@certd/lib-iframe": "^1.42.4",
|
"@certd/lib-iframe": "^1.42.5",
|
||||||
"@certd/pipeline": "^1.42.4",
|
"@certd/pipeline": "^1.42.5",
|
||||||
"@rollup/plugin-commonjs": "^25.0.7",
|
"@rollup/plugin-commonjs": "^25.0.7",
|
||||||
"@rollup/plugin-node-resolve": "^15.2.3",
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
||||||
"@types/chai": "^4.3.12",
|
"@types/chai": "^4.3.12",
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ async function doActive() {
|
|||||||
title: t("vip.successTitle"),
|
title: t("vip.successTitle"),
|
||||||
content: t("vip.successContent", {
|
content: t("vip.successContent", {
|
||||||
vipLabel,
|
vipLabel,
|
||||||
expireDate: settingStore.plusInfo.expireTime === -1 ? t("vip.permanent") : dayjs(settingStore.plusInfo.expireTime).format("YYYY-MM-DD"),
|
expireDate: dayjs(settingStore.plusInfo.expireTime).format("YYYY-MM-DD"),
|
||||||
}),
|
}),
|
||||||
onOk() {
|
onOk() {
|
||||||
if (!(settingStore.installInfo.bindUserId > 0)) {
|
if (!(settingStore.installInfo.bindUserId > 0)) {
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ export default {
|
|||||||
openKey: "Open API Key",
|
openKey: "Open API Key",
|
||||||
notification: "Notification Settings",
|
notification: "Notification Settings",
|
||||||
siteMonitorSetting: "Site Monitor Settings",
|
siteMonitorSetting: "Site Monitor Settings",
|
||||||
auditLog: "Audit Log",
|
|
||||||
userSecurity: "Security Settings",
|
userSecurity: "Security Settings",
|
||||||
userProfile: "Account Info",
|
userProfile: "Account Info",
|
||||||
userGrant: "Grant Delegation",
|
userGrant: "Grant Delegation",
|
||||||
@@ -68,7 +67,6 @@ export default {
|
|||||||
projectJoin: "Join Project",
|
projectJoin: "Join Project",
|
||||||
currentProject: "Current Project",
|
currentProject: "Current Project",
|
||||||
projectMemberManager: "Project Member",
|
projectMemberManager: "Project Member",
|
||||||
auditLog: "Audit Log",
|
|
||||||
domainMonitorSetting: "Domain Monitor Settings",
|
domainMonitorSetting: "Domain Monitor Settings",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -104,5 +104,4 @@ export default {
|
|||||||
not_effective: "Not effective or duration not sync?",
|
not_effective: "Not effective or duration not sync?",
|
||||||
learn_more: "More privileges",
|
learn_more: "More privileges",
|
||||||
question: "More VIP related questions",
|
question: "More VIP related questions",
|
||||||
permanent: "Permanent",
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ export default {
|
|||||||
openKey: "开放接口密钥",
|
openKey: "开放接口密钥",
|
||||||
notification: "通知设置",
|
notification: "通知设置",
|
||||||
siteMonitorSetting: "站点监控设置",
|
siteMonitorSetting: "站点监控设置",
|
||||||
auditLog: "操作日志",
|
|
||||||
userSecurity: "认证安全设置",
|
userSecurity: "认证安全设置",
|
||||||
userProfile: "账号信息",
|
userProfile: "账号信息",
|
||||||
userGrant: "授权委托",
|
userGrant: "授权委托",
|
||||||
@@ -68,7 +67,6 @@ export default {
|
|||||||
projectJoin: "加入项目",
|
projectJoin: "加入项目",
|
||||||
currentProject: "当前项目",
|
currentProject: "当前项目",
|
||||||
projectMemberManager: "项目成员管理",
|
projectMemberManager: "项目成员管理",
|
||||||
auditLog: "审计日志",
|
|
||||||
domainMonitorSetting: "域名监控设置",
|
domainMonitorSetting: "域名监控设置",
|
||||||
jobHistory: "监控执行记录",
|
jobHistory: "监控执行记录",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -103,5 +103,4 @@ export default {
|
|||||||
not_effective: "VIP没有生效/时长未同步?",
|
not_effective: "VIP没有生效/时长未同步?",
|
||||||
learn_more: "更多特权(加VIP群等)",
|
learn_more: "更多特权(加VIP群等)",
|
||||||
question: "更多VIP相关问题",
|
question: "更多VIP相关问题",
|
||||||
permanent: "永久",
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -287,22 +287,6 @@ export const certdResources = [
|
|||||||
isMenu: true,
|
isMenu: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
title: "certd.auditLog",
|
|
||||||
name: "AuditLog",
|
|
||||||
path: "/certd/audit",
|
|
||||||
component: "/certd/audit/index.vue",
|
|
||||||
meta: {
|
|
||||||
icon: "ion:document-text-outline",
|
|
||||||
auth: true,
|
|
||||||
keepAlive: true,
|
|
||||||
isMenu: true,
|
|
||||||
show: () => {
|
|
||||||
const settingStore = useSettingStore();
|
|
||||||
return settingStore.isPlus;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
title: "certd.userSecurity",
|
title: "certd.userSecurity",
|
||||||
name: "UserSecurity",
|
name: "UserSecurity",
|
||||||
|
|||||||
@@ -410,22 +410,6 @@ export const sysResources = [
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
|
||||||
title: "certd.sysResources.auditLog",
|
|
||||||
name: "SysAuditLog",
|
|
||||||
path: "/sys/enterprise/audit",
|
|
||||||
component: "/sys/enterprise/audit/index.vue",
|
|
||||||
meta: {
|
|
||||||
icon: "ion:document-text-outline",
|
|
||||||
keepAlive: true,
|
|
||||||
auth: true,
|
|
||||||
isMenu: true,
|
|
||||||
show: () => {
|
|
||||||
const settingStore = useSettingStore();
|
|
||||||
return settingStore.isPlus;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
title: "certd.sysResources.netTest",
|
title: "certd.sysResources.netTest",
|
||||||
name: "NetTest",
|
name: "NetTest",
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
import { request } from "/src/api/service";
|
|
||||||
|
|
||||||
const apiPrefix = "/pi/audit";
|
|
||||||
|
|
||||||
export function createAuditApi() {
|
|
||||||
return {
|
|
||||||
async GetList(query: any) {
|
|
||||||
return await request({
|
|
||||||
url: apiPrefix + "/page",
|
|
||||||
method: "post",
|
|
||||||
data: query,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
async DelObj(id: number) {
|
|
||||||
return await request({
|
|
||||||
url: apiPrefix + "/delete",
|
|
||||||
method: "post",
|
|
||||||
params: { id },
|
|
||||||
});
|
|
||||||
},
|
|
||||||
async GetDict() {
|
|
||||||
return await request({
|
|
||||||
url: apiPrefix + "/dict",
|
|
||||||
method: "post",
|
|
||||||
});
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,132 +0,0 @@
|
|||||||
import { ColumnProps, DataFormatterContext, CreateCrudOptionsProps, CreateCrudOptionsRet, DelReq, UserPageQuery, UserPageRes, dict } from "@fast-crud/fast-crud";
|
|
||||||
import { useI18n } from "/src/locales";
|
|
||||||
import { useDicts } from "../dicts";
|
|
||||||
|
|
||||||
const typeDict = dict({
|
|
||||||
url: "/pi/audit/dict",
|
|
||||||
getData: async () => {
|
|
||||||
const { createAuditApi } = await import("./api");
|
|
||||||
const api = createAuditApi();
|
|
||||||
const res = await api.GetDict();
|
|
||||||
return res.types || [];
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export default function ({ crudExpose, context }: CreateCrudOptionsProps): CreateCrudOptionsRet {
|
|
||||||
const { t } = useI18n();
|
|
||||||
const { myProjectDict } = useDicts();
|
|
||||||
const api = context.api;
|
|
||||||
|
|
||||||
const pageRequest = async (query: UserPageQuery): Promise<UserPageRes> => {
|
|
||||||
return await api.GetList(query);
|
|
||||||
};
|
|
||||||
const delRequest = async (req: DelReq) => {
|
|
||||||
return await api.DelObj(req.row.id);
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
|
||||||
crudOptions: {
|
|
||||||
request: { pageRequest, delRequest },
|
|
||||||
toolbar: {
|
|
||||||
buttons: {
|
|
||||||
export: { show: true },
|
|
||||||
},
|
|
||||||
export: {
|
|
||||||
dataFrom: "search",
|
|
||||||
columnFilter: (col: ColumnProps) => col.show === true,
|
|
||||||
dataFormatter: (opts: DataFormatterContext) => {
|
|
||||||
const { row, originalRow, col } = opts;
|
|
||||||
const key = col.key;
|
|
||||||
if (key === "createTime" && originalRow[key]) {
|
|
||||||
row[key] = new Date(originalRow[key]).toLocaleString();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
actionbar: {
|
|
||||||
buttons: {
|
|
||||||
add: { show: false },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
rowHandle: {
|
|
||||||
width: 120,
|
|
||||||
fixed: "right",
|
|
||||||
buttons: {
|
|
||||||
view: { show: false },
|
|
||||||
edit: { show: false },
|
|
||||||
remove: { show: true },
|
|
||||||
copy: { show: false },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
columns: {
|
|
||||||
id: {
|
|
||||||
title: "ID",
|
|
||||||
type: "number",
|
|
||||||
column: { width: 80 },
|
|
||||||
form: { show: false },
|
|
||||||
},
|
|
||||||
createTime: {
|
|
||||||
title: "操作时间",
|
|
||||||
type: "datetime",
|
|
||||||
search: {
|
|
||||||
show: true,
|
|
||||||
component: {
|
|
||||||
name: "a-range-picker",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
column: { width: 170, sorter: true },
|
|
||||||
form: { show: false },
|
|
||||||
},
|
|
||||||
type: {
|
|
||||||
title: "操作类型",
|
|
||||||
type: "dict-select",
|
|
||||||
dict: typeDict,
|
|
||||||
search: { show: true },
|
|
||||||
column: { width: 120 },
|
|
||||||
form: { show: false },
|
|
||||||
},
|
|
||||||
action: {
|
|
||||||
title: "操作动作",
|
|
||||||
type: "text",
|
|
||||||
search: { show: true },
|
|
||||||
column: { width: 200, tooltip: true },
|
|
||||||
form: { show: false },
|
|
||||||
},
|
|
||||||
success: {
|
|
||||||
title: "结果",
|
|
||||||
type: "dict-switch",
|
|
||||||
dict: dict({
|
|
||||||
data: [
|
|
||||||
{ value: true, label: "成功", color: "success" },
|
|
||||||
{ value: false, label: "失败", color: "error" },
|
|
||||||
],
|
|
||||||
}),
|
|
||||||
column: { width: 100, align: "center" },
|
|
||||||
form: { show: false },
|
|
||||||
search: { show: true },
|
|
||||||
},
|
|
||||||
content: {
|
|
||||||
title: "备注",
|
|
||||||
type: "text",
|
|
||||||
search: { show: true },
|
|
||||||
column: { width: 700, tooltip: true },
|
|
||||||
form: { show: false },
|
|
||||||
},
|
|
||||||
ipAddress: {
|
|
||||||
title: "IP地址",
|
|
||||||
type: "text",
|
|
||||||
column: { width: 140 },
|
|
||||||
form: { show: false },
|
|
||||||
},
|
|
||||||
projectId: {
|
|
||||||
title: t("certd.fields.projectName"),
|
|
||||||
type: "dict-select",
|
|
||||||
dict: myProjectDict,
|
|
||||||
form: {
|
|
||||||
show: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
<template>
|
|
||||||
<fs-page>
|
|
||||||
<template #header>
|
|
||||||
<div class="title">
|
|
||||||
操作日志
|
|
||||||
<span class="sub">查看您的操作记录</span>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
<fs-crud ref="crudRef" v-bind="crudBinding" />
|
|
||||||
</fs-page>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts" setup>
|
|
||||||
import { useFs } from "@fast-crud/fast-crud";
|
|
||||||
import createCrudOptions from "./crud";
|
|
||||||
import { createAuditApi } from "./api";
|
|
||||||
import { useMounted } from "/@/use/use-mounted";
|
|
||||||
|
|
||||||
defineOptions({ name: "AuditLog" });
|
|
||||||
|
|
||||||
const api = createAuditApi();
|
|
||||||
const { crudBinding, crudRef, crudExpose } = useFs({ createCrudOptions, context: { api } });
|
|
||||||
useMounted(() => crudExpose.doRefresh());
|
|
||||||
</script>
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
import { request } from "/src/api/service";
|
|
||||||
|
|
||||||
const apiPrefix = "/sys/audit";
|
|
||||||
|
|
||||||
export function createSysAuditApi() {
|
|
||||||
return {
|
|
||||||
async GetList(query: any) {
|
|
||||||
return await request({
|
|
||||||
url: apiPrefix + "/page",
|
|
||||||
method: "post",
|
|
||||||
data: query,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
async DelObj(id: number) {
|
|
||||||
return await request({
|
|
||||||
url: apiPrefix + "/delete",
|
|
||||||
method: "post",
|
|
||||||
params: { id },
|
|
||||||
});
|
|
||||||
},
|
|
||||||
async Clean(retentionDays: number) {
|
|
||||||
return await request({
|
|
||||||
url: apiPrefix + "/clean",
|
|
||||||
method: "post",
|
|
||||||
data: { retentionDays },
|
|
||||||
});
|
|
||||||
},
|
|
||||||
async GetDict() {
|
|
||||||
return await request({
|
|
||||||
url: apiPrefix + "/dict",
|
|
||||||
method: "post",
|
|
||||||
});
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,180 +0,0 @@
|
|||||||
import { CreateCrudOptionsProps, CreateCrudOptionsRet, DelReq, UserPageQuery, UserPageRes, dict } from "@fast-crud/fast-crud";
|
|
||||||
import { Modal } from "ant-design-vue";
|
|
||||||
import { useI18n } from "/src/locales";
|
|
||||||
import { useDicts } from "/@/views/certd/dicts";
|
|
||||||
|
|
||||||
const typeDict = dict({
|
|
||||||
url: "/sys/audit/dict",
|
|
||||||
getData: async () => {
|
|
||||||
const { createSysAuditApi } = await import("./api");
|
|
||||||
const api = createSysAuditApi();
|
|
||||||
const res = await api.GetDict();
|
|
||||||
return res.types || [];
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const actionDict = dict({
|
|
||||||
url: "/sys/audit/dict",
|
|
||||||
getData: async () => {
|
|
||||||
const { createSysAuditApi } = await import("./api");
|
|
||||||
const api = createSysAuditApi();
|
|
||||||
const res = await api.GetDict();
|
|
||||||
return res.actions || [];
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export default function ({ crudExpose, context }: CreateCrudOptionsProps): CreateCrudOptionsRet {
|
|
||||||
const { t } = useI18n();
|
|
||||||
const { myProjectDict } = useDicts();
|
|
||||||
const api = context.api;
|
|
||||||
|
|
||||||
const pageRequest = async (query: UserPageQuery): Promise<UserPageRes> => {
|
|
||||||
return await api.GetList(query);
|
|
||||||
};
|
|
||||||
const delRequest = async (req: DelReq) => {
|
|
||||||
return await api.DelObj(req.row.id);
|
|
||||||
};
|
|
||||||
|
|
||||||
const cleanExpired = async () => {
|
|
||||||
Modal.confirm({
|
|
||||||
title: "确认清理",
|
|
||||||
content: "确定要清理90天前的审计日志吗?此操作不可撤销。",
|
|
||||||
okText: "确认清理",
|
|
||||||
okType: "danger",
|
|
||||||
cancelText: "取消",
|
|
||||||
async onOk() {
|
|
||||||
await api.Clean(90);
|
|
||||||
crudExpose.doRefresh();
|
|
||||||
},
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
|
||||||
crudOptions: {
|
|
||||||
request: { pageRequest, delRequest },
|
|
||||||
tabs: {
|
|
||||||
name: "scope",
|
|
||||||
show: true,
|
|
||||||
dict: {
|
|
||||||
data: [
|
|
||||||
{ value: "system", label: "系统级", color: "red" },
|
|
||||||
{ value: "user", label: "用户级", color: "blue" },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
actionbar: {
|
|
||||||
buttons: {
|
|
||||||
add: { show: false },
|
|
||||||
clean: {
|
|
||||||
text: "清理过期日志(90天)",
|
|
||||||
type: "primary",
|
|
||||||
danger: true,
|
|
||||||
click: cleanExpired,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
rowHandle: {
|
|
||||||
width: 120,
|
|
||||||
fixed: "right",
|
|
||||||
buttons: {
|
|
||||||
view: { show: false },
|
|
||||||
edit: { show: false },
|
|
||||||
remove: { show: true },
|
|
||||||
copy: { show: false },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
search: {
|
|
||||||
initialForm: { scope: "system" },
|
|
||||||
},
|
|
||||||
columns: {
|
|
||||||
id: {
|
|
||||||
title: "ID",
|
|
||||||
type: "number",
|
|
||||||
column: { width: 80 },
|
|
||||||
form: { show: false },
|
|
||||||
},
|
|
||||||
createTime: {
|
|
||||||
title: "操作时间",
|
|
||||||
type: "datetime",
|
|
||||||
search: {
|
|
||||||
show: true,
|
|
||||||
component: {
|
|
||||||
name: "a-range-picker",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
column: { width: 170, sorter: true },
|
|
||||||
form: { show: false },
|
|
||||||
},
|
|
||||||
username: {
|
|
||||||
title: "操作人",
|
|
||||||
type: "text",
|
|
||||||
search: { show: true },
|
|
||||||
column: { width: 120 },
|
|
||||||
form: { show: false },
|
|
||||||
},
|
|
||||||
type: {
|
|
||||||
title: "类型",
|
|
||||||
type: "dict-select",
|
|
||||||
dict: typeDict,
|
|
||||||
search: { show: true },
|
|
||||||
column: { width: 120 },
|
|
||||||
form: { show: false },
|
|
||||||
},
|
|
||||||
action: {
|
|
||||||
title: "操作",
|
|
||||||
type: "text",
|
|
||||||
search: { show: true },
|
|
||||||
column: { width: 200, tooltip: true },
|
|
||||||
form: { show: false },
|
|
||||||
},
|
|
||||||
success: {
|
|
||||||
title: "结果",
|
|
||||||
type: "dict-switch",
|
|
||||||
dict: dict({
|
|
||||||
data: [
|
|
||||||
{ value: true, label: "成功", color: "success" },
|
|
||||||
{ value: false, label: "失败", color: "error" },
|
|
||||||
],
|
|
||||||
}),
|
|
||||||
column: { width: 100, align: "center" },
|
|
||||||
form: { show: false },
|
|
||||||
search: { show: true },
|
|
||||||
},
|
|
||||||
content: {
|
|
||||||
title: "备注",
|
|
||||||
type: "text",
|
|
||||||
search: { show: true },
|
|
||||||
column: { width: 500, tooltip: true },
|
|
||||||
form: { show: false },
|
|
||||||
},
|
|
||||||
ipAddress: {
|
|
||||||
title: "IP地址",
|
|
||||||
type: "text",
|
|
||||||
column: { width: 140 },
|
|
||||||
form: { show: false },
|
|
||||||
},
|
|
||||||
projectId: {
|
|
||||||
title: t("certd.fields.projectName"),
|
|
||||||
type: "dict-select",
|
|
||||||
dict: myProjectDict,
|
|
||||||
form: {
|
|
||||||
show: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
scope: {
|
|
||||||
title: "范围",
|
|
||||||
type: "dict-select",
|
|
||||||
dict: dict({
|
|
||||||
data: [
|
|
||||||
{ value: "system", label: "系统级", color: "blue" },
|
|
||||||
{ value: "user", label: "用户级", color: "green" },
|
|
||||||
],
|
|
||||||
}),
|
|
||||||
search: { show: true },
|
|
||||||
column: { width: 100 },
|
|
||||||
form: { show: false },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
<template>
|
|
||||||
<fs-page>
|
|
||||||
<template #header>
|
|
||||||
<div class="title">
|
|
||||||
操作日志
|
|
||||||
<span class="sub">查看所有用户的操作记录</span>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
<fs-crud ref="crudRef" v-bind="crudBinding" />
|
|
||||||
</fs-page>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts" setup>
|
|
||||||
import { useFs } from "@fast-crud/fast-crud";
|
|
||||||
import createCrudOptions from "./crud";
|
|
||||||
import { createSysAuditApi } from "./api";
|
|
||||||
import { useMounted } from "/@/use/use-mounted";
|
|
||||||
|
|
||||||
defineOptions({ name: "SysAuditLog" });
|
|
||||||
|
|
||||||
const api = createSysAuditApi();
|
|
||||||
const { crudBinding, crudRef, crudExpose } = useFs({ createCrudOptions, context: { api } });
|
|
||||||
useMounted(() => crudExpose.doRefresh());
|
|
||||||
</script>
|
|
||||||
@@ -1,35 +1,75 @@
|
|||||||
import { request } from "/src/api/service";
|
import { request } from "/src/api/service";
|
||||||
|
|
||||||
const apiPrefix = "/sys/audit";
|
const apiPrefix = "/sys/project/provider";
|
||||||
|
|
||||||
export function createSysAuditApi() {
|
export async function GetList(query: any) {
|
||||||
return {
|
return await request({
|
||||||
async GetList(query: any) {
|
url: apiPrefix + "/page",
|
||||||
return await request({
|
method: "post",
|
||||||
url: apiPrefix + "/page",
|
data: query,
|
||||||
method: "post",
|
});
|
||||||
data: query,
|
}
|
||||||
});
|
|
||||||
},
|
export async function AddObj(obj: any) {
|
||||||
async DelObj(id: number) {
|
return await request({
|
||||||
return await request({
|
url: apiPrefix + "/add",
|
||||||
url: apiPrefix + "/delete",
|
method: "post",
|
||||||
method: "post",
|
data: obj,
|
||||||
params: { id },
|
});
|
||||||
});
|
}
|
||||||
},
|
|
||||||
async Clean(retentionDays: number) {
|
export async function UpdateObj(obj: any) {
|
||||||
return await request({
|
return await request({
|
||||||
url: apiPrefix + "/clean",
|
url: apiPrefix + "/update",
|
||||||
method: "post",
|
method: "post",
|
||||||
data: { retentionDays },
|
data: obj,
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
async GetDict() {
|
|
||||||
return await request({
|
export async function DelObj(id: any) {
|
||||||
url: apiPrefix + "/dict",
|
return await request({
|
||||||
method: "post",
|
url: apiPrefix + "/delete",
|
||||||
});
|
method: "post",
|
||||||
},
|
params: { id },
|
||||||
};
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function GetObj(id: any) {
|
||||||
|
return await request({
|
||||||
|
url: apiPrefix + "/info",
|
||||||
|
method: "post",
|
||||||
|
params: { id },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function GetDetail(id: any) {
|
||||||
|
return await request({
|
||||||
|
url: apiPrefix + "/detail",
|
||||||
|
method: "post",
|
||||||
|
params: { id },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function DeleteBatch(ids: any[]) {
|
||||||
|
return await request({
|
||||||
|
url: apiPrefix + "/deleteByIds",
|
||||||
|
method: "post",
|
||||||
|
data: { ids },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function SetDefault(id: any) {
|
||||||
|
return await request({
|
||||||
|
url: apiPrefix + "/setDefault",
|
||||||
|
method: "post",
|
||||||
|
data: { id },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function SetDisabled(id: any, disabled: boolean) {
|
||||||
|
return await request({
|
||||||
|
url: apiPrefix + "/setDisabled",
|
||||||
|
method: "post",
|
||||||
|
data: { id, disabled },
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,194 +1,252 @@
|
|||||||
import { ColumnProps, DataFormatterContext, CreateCrudOptionsProps, CreateCrudOptionsRet, DelReq, UserPageQuery, UserPageRes, dict } from "@fast-crud/fast-crud";
|
import * as api from "./api";
|
||||||
import { Modal } from "ant-design-vue";
|
|
||||||
import { useI18n } from "/src/locales";
|
import { useI18n } from "/src/locales";
|
||||||
import { useDicts } from "/@/views/certd/dicts";
|
import { computed, Ref, ref } from "vue";
|
||||||
|
import { useRouter } from "vue-router";
|
||||||
const typeDict = dict({
|
import { AddReq, compute, CreateCrudOptionsProps, CreateCrudOptionsRet, DelReq, dict, EditReq, UserPageQuery, UserPageRes, utils } from "@fast-crud/fast-crud";
|
||||||
url: "/sys/audit/dict",
|
import { useUserStore } from "/@/store/user";
|
||||||
getData: async () => {
|
import { useSettingStore } from "/@/store/settings";
|
||||||
const { createSysAuditApi } = await import("./api");
|
import { Modal } from "ant-design-vue";
|
||||||
const api = createSysAuditApi();
|
|
||||||
const res = await api.GetDict();
|
|
||||||
return res.types || [];
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const actionDict = dict({
|
|
||||||
url: "/sys/audit/dict",
|
|
||||||
getData: async () => {
|
|
||||||
const { createSysAuditApi } = await import("./api");
|
|
||||||
const api = createSysAuditApi();
|
|
||||||
const res = await api.GetDict();
|
|
||||||
return res.actions || [];
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export default function ({ crudExpose, context }: CreateCrudOptionsProps): CreateCrudOptionsRet {
|
export default function ({ crudExpose, context }: CreateCrudOptionsProps): CreateCrudOptionsRet {
|
||||||
|
const router = useRouter();
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const { myProjectDict } = useDicts();
|
|
||||||
const api = context.api;
|
|
||||||
|
|
||||||
const pageRequest = async (query: UserPageQuery): Promise<UserPageRes> => {
|
const pageRequest = async (query: UserPageQuery): Promise<UserPageRes> => {
|
||||||
return await api.GetList(query);
|
return await api.GetList(query);
|
||||||
};
|
};
|
||||||
const delRequest = async (req: DelReq) => {
|
const editRequest = async ({ form, row }: EditReq) => {
|
||||||
return await api.DelObj(req.row.id);
|
form.id = row.id;
|
||||||
|
const res = await api.UpdateObj(form);
|
||||||
|
return res;
|
||||||
|
};
|
||||||
|
const delRequest = async ({ row }: DelReq) => {
|
||||||
|
return await api.DelObj(row.id);
|
||||||
};
|
};
|
||||||
|
|
||||||
const cleanExpired = async () => {
|
const addRequest = async ({ form }: AddReq) => {
|
||||||
Modal.confirm({
|
const res = await api.AddObj(form);
|
||||||
title: "确认清理",
|
return res;
|
||||||
content: "确定要清理90天前的审计日志吗?此操作不可撤销。",
|
|
||||||
okText: "确认清理",
|
|
||||||
okType: "danger",
|
|
||||||
cancelText: "取消",
|
|
||||||
async onOk() {
|
|
||||||
await api.Clean(90);
|
|
||||||
crudExpose.doRefresh();
|
|
||||||
},
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const userStore = useUserStore();
|
||||||
|
const settingStore = useSettingStore();
|
||||||
|
const selectedRowKeys: Ref<any[]> = ref([]);
|
||||||
|
context.selectedRowKeys = selectedRowKeys;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
crudOptions: {
|
crudOptions: {
|
||||||
request: { pageRequest, delRequest },
|
settings: {
|
||||||
tabs: {
|
plugins: {
|
||||||
name: "scope",
|
//这里使用行选择插件,生成行选择crudOptions配置,最终会与crudOptions合并
|
||||||
show: true,
|
rowSelection: {
|
||||||
dict: {
|
enabled: true,
|
||||||
data: [
|
order: -2,
|
||||||
{ value: "system", label: "系统级", color: "red" },
|
before: true,
|
||||||
{ value: "user", label: "用户级", color: "blue" },
|
// handle: (pluginProps,useCrudProps)=>CrudOptions,
|
||||||
],
|
props: {
|
||||||
},
|
multiple: true,
|
||||||
},
|
crossPage: true,
|
||||||
toolbar: {
|
selectedRowKeys,
|
||||||
buttons: {
|
},
|
||||||
export: { show: true },
|
|
||||||
},
|
|
||||||
export: {
|
|
||||||
dataFrom: "search",
|
|
||||||
columnFilter: (col: ColumnProps) => col.show === true,
|
|
||||||
dataFormatter: (opts: DataFormatterContext) => {
|
|
||||||
const { row, originalRow, col } = opts;
|
|
||||||
const key = col.key;
|
|
||||||
if (key === "createTime" && originalRow[key]) {
|
|
||||||
row[key] = new Date(originalRow[key]).toLocaleString();
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
actionbar: {
|
request: {
|
||||||
buttons: {
|
pageRequest,
|
||||||
add: { show: false },
|
addRequest,
|
||||||
clean: {
|
editRequest,
|
||||||
text: "清理过期日志(90天)",
|
delRequest,
|
||||||
type: "primary",
|
|
||||||
danger: true,
|
|
||||||
click: cleanExpired,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
rowHandle: {
|
rowHandle: {
|
||||||
width: 120,
|
minWidth: 200,
|
||||||
fixed: "right",
|
fixed: "right",
|
||||||
buttons: {
|
|
||||||
view: { show: false },
|
|
||||||
edit: { show: false },
|
|
||||||
remove: { show: true },
|
|
||||||
copy: { show: false },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
search: {
|
|
||||||
initialForm: { scope: "system" },
|
|
||||||
},
|
},
|
||||||
columns: {
|
columns: {
|
||||||
id: {
|
id: {
|
||||||
title: "ID",
|
title: "ID",
|
||||||
|
key: "id",
|
||||||
type: "number",
|
type: "number",
|
||||||
column: { width: 80 },
|
column: {
|
||||||
form: { show: false },
|
width: 100,
|
||||||
},
|
|
||||||
createTime: {
|
|
||||||
title: "操作时间",
|
|
||||||
type: "datetime",
|
|
||||||
search: {
|
|
||||||
show: true,
|
|
||||||
component: {
|
|
||||||
name: "a-range-picker",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
column: { width: 170, sorter: true },
|
|
||||||
form: { show: false },
|
|
||||||
},
|
|
||||||
username: {
|
|
||||||
title: "操作人",
|
|
||||||
type: "text",
|
|
||||||
search: { show: true },
|
|
||||||
column: { width: 120 },
|
|
||||||
form: { show: false },
|
|
||||||
},
|
|
||||||
type: {
|
|
||||||
title: "类型",
|
|
||||||
type: "dict-select",
|
|
||||||
dict: typeDict,
|
|
||||||
search: { show: true },
|
|
||||||
column: { width: 120 },
|
|
||||||
form: { show: false },
|
|
||||||
},
|
|
||||||
action: {
|
|
||||||
title: "操作",
|
|
||||||
type: "text",
|
|
||||||
search: { show: true },
|
|
||||||
column: { width: 200, tooltip: true },
|
|
||||||
form: { show: false },
|
|
||||||
},
|
|
||||||
success: {
|
|
||||||
title: "结果",
|
|
||||||
type: "dict-switch",
|
|
||||||
dict: dict({
|
|
||||||
data: [
|
|
||||||
{ value: true, label: "成功", color: "success" },
|
|
||||||
{ value: false, label: "失败", color: "error" },
|
|
||||||
],
|
|
||||||
}),
|
|
||||||
column: { width: 100, align: "center" },
|
|
||||||
form: { show: false },
|
|
||||||
search: { show: true },
|
|
||||||
},
|
|
||||||
content: {
|
|
||||||
title: "备注",
|
|
||||||
type: "text",
|
|
||||||
search: { show: true },
|
|
||||||
column: { width: 500, tooltip: true },
|
|
||||||
form: { show: false },
|
|
||||||
},
|
|
||||||
ipAddress: {
|
|
||||||
title: "IP地址",
|
|
||||||
type: "text",
|
|
||||||
column: { width: 140 },
|
|
||||||
form: { show: false },
|
|
||||||
},
|
|
||||||
projectId: {
|
|
||||||
title: t("certd.fields.projectName"),
|
|
||||||
type: "dict-select",
|
|
||||||
dict: myProjectDict,
|
|
||||||
form: {
|
form: {
|
||||||
show: false,
|
show: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
scope: {
|
domain: {
|
||||||
title: "范围",
|
title: t("certd.cnameDomain"),
|
||||||
|
type: "text",
|
||||||
|
editForm: {
|
||||||
|
component: {
|
||||||
|
disabled: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
search: {
|
||||||
|
show: true,
|
||||||
|
},
|
||||||
|
form: {
|
||||||
|
component: {
|
||||||
|
placeholder: t("certd.cnameDomainPlaceholder"),
|
||||||
|
},
|
||||||
|
helper: t("certd.cnameDomainHelper"),
|
||||||
|
rules: [
|
||||||
|
{ required: true, message: t("certd.requiredField") },
|
||||||
|
{ pattern: /^[^*]+$/, message: t("certd.cnameDomainPattern") },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
column: {
|
||||||
|
width: 200,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
dnsProviderType: {
|
||||||
|
title: t("certd.dnsProvider"),
|
||||||
|
type: "dict-select",
|
||||||
|
search: {
|
||||||
|
show: true,
|
||||||
|
},
|
||||||
|
dict: dict({
|
||||||
|
url: "pi/dnsProvider/list",
|
||||||
|
value: "key",
|
||||||
|
label: "title",
|
||||||
|
}),
|
||||||
|
form: {
|
||||||
|
rules: [{ required: true, message: t("certd.requiredField") }],
|
||||||
|
},
|
||||||
|
column: {
|
||||||
|
width: 150,
|
||||||
|
component: {
|
||||||
|
color: "auto",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
accessId: {
|
||||||
|
title: t("certd.dnsProviderAuthorization"),
|
||||||
type: "dict-select",
|
type: "dict-select",
|
||||||
|
dict: dict({
|
||||||
|
url: "/pi/access/list",
|
||||||
|
value: "id",
|
||||||
|
label: "name",
|
||||||
|
}),
|
||||||
|
form: {
|
||||||
|
component: {
|
||||||
|
name: "access-selector",
|
||||||
|
vModel: "modelValue",
|
||||||
|
type: compute(({ form }) => {
|
||||||
|
return form.dnsProviderType;
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
rules: [{ required: true, message: t("certd.requiredField") }],
|
||||||
|
},
|
||||||
|
column: {
|
||||||
|
width: 150,
|
||||||
|
component: {
|
||||||
|
color: "auto",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
isDefault: {
|
||||||
|
title: t("certd.isDefault"),
|
||||||
|
type: "dict-switch",
|
||||||
dict: dict({
|
dict: dict({
|
||||||
data: [
|
data: [
|
||||||
{ value: "system", label: "系统级", color: "blue" },
|
{ label: t("certd.yes"), value: true, color: "success" },
|
||||||
{ value: "user", label: "用户级", color: "green" },
|
{ label: t("certd.no"), value: false, color: "default" },
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
search: { show: true },
|
form: {
|
||||||
column: { width: 100 },
|
value: false,
|
||||||
form: { show: false },
|
rules: [{ required: true, message: t("certd.selectIsDefault") }],
|
||||||
|
},
|
||||||
|
column: {
|
||||||
|
align: "center",
|
||||||
|
width: 100,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
setDefault: {
|
||||||
|
title: t("certd.setDefault"),
|
||||||
|
type: "text",
|
||||||
|
form: {
|
||||||
|
show: false,
|
||||||
|
},
|
||||||
|
column: {
|
||||||
|
width: 100,
|
||||||
|
align: "center",
|
||||||
|
conditionalRenderDisabled: true,
|
||||||
|
cellRender: ({ row }) => {
|
||||||
|
if (row.isDefault) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const onClick = async () => {
|
||||||
|
Modal.confirm({
|
||||||
|
title: t("certd.prompt"),
|
||||||
|
content: t("certd.confirmSetDefault"),
|
||||||
|
onOk: async () => {
|
||||||
|
await api.SetDefault(row.id);
|
||||||
|
await crudExpose.doRefresh();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<a-button type={"link"} size={"small"} onClick={onClick}>
|
||||||
|
{t("certd.setAsDefault")}
|
||||||
|
</a-button>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
disabled: {
|
||||||
|
title: t("certd.disabled"),
|
||||||
|
type: "dict-switch",
|
||||||
|
dict: dict({
|
||||||
|
data: [
|
||||||
|
{ label: t("certd.enabled"), value: false, color: "success" },
|
||||||
|
{ label: t("certd.disabledLabel"), value: true, color: "error" },
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
form: {
|
||||||
|
value: false,
|
||||||
|
},
|
||||||
|
column: {
|
||||||
|
width: 100,
|
||||||
|
component: {
|
||||||
|
title: t("certd.clickToToggle"),
|
||||||
|
on: {
|
||||||
|
async click({ value, row }) {
|
||||||
|
Modal.confirm({
|
||||||
|
title: t("certd.prompt"),
|
||||||
|
content: t("certd.confirmToggleStatus", { action: !value ? t("certd.disable") : t("certd.enable") }),
|
||||||
|
onOk: async () => {
|
||||||
|
await api.SetDisabled(row.id, !value);
|
||||||
|
await crudExpose.doRefresh();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
createTime: {
|
||||||
|
title: t("certd.createTime"),
|
||||||
|
type: "datetime",
|
||||||
|
form: {
|
||||||
|
show: false,
|
||||||
|
},
|
||||||
|
column: {
|
||||||
|
sorter: true,
|
||||||
|
width: 160,
|
||||||
|
align: "center",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
updateTime: {
|
||||||
|
title: t("certd.updateTime"),
|
||||||
|
type: "datetime",
|
||||||
|
form: {
|
||||||
|
show: false,
|
||||||
|
},
|
||||||
|
column: {
|
||||||
|
show: true,
|
||||||
|
width: 160,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,24 +1,63 @@
|
|||||||
<template>
|
<template>
|
||||||
<fs-page>
|
<fs-page class="page-cert">
|
||||||
<template #header>
|
<template #header>
|
||||||
<div class="title">
|
<div class="title">
|
||||||
操作日志
|
{{ t("certd.cnameTitle") }}
|
||||||
<span class="sub">查看所有用户的操作记录</span>
|
<span class="sub">
|
||||||
|
{{ t("certd.cnameDescription") }}
|
||||||
|
<a href="https://certd.docmirror.cn/guide/feature/cname/" target="_blank">
|
||||||
|
{{ t("certd.cnameLinkText") }}
|
||||||
|
</a>
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<fs-crud ref="crudRef" v-bind="crudBinding" />
|
<fs-crud ref="crudRef" v-bind="crudBinding">
|
||||||
|
<template #pagination-left>
|
||||||
|
<a-tooltip :title="t('certd.batchDelete')">
|
||||||
|
<fs-button icon="DeleteOutlined" @click="handleBatchDelete"></fs-button>
|
||||||
|
</a-tooltip>
|
||||||
|
</template>
|
||||||
|
</fs-crud>
|
||||||
</fs-page>
|
</fs-page>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
|
import { useMounted } from "/@/use/use-mounted";
|
||||||
import { useFs } from "@fast-crud/fast-crud";
|
import { useFs } from "@fast-crud/fast-crud";
|
||||||
import createCrudOptions from "./crud";
|
import createCrudOptions from "./crud";
|
||||||
import { createSysAuditApi } from "./api";
|
import { message, Modal } from "ant-design-vue";
|
||||||
import { useMounted } from "/@/use/use-mounted";
|
import { DeleteBatch } from "./api";
|
||||||
|
import { useI18n } from "/src/locales";
|
||||||
|
import { useCrudPermission } from "/@/plugin/permission";
|
||||||
|
|
||||||
defineOptions({ name: "SysAuditLog" });
|
const { t } = useI18n();
|
||||||
|
|
||||||
const api = createSysAuditApi();
|
defineOptions({
|
||||||
const { crudBinding, crudRef, crudExpose } = useFs({ createCrudOptions, context: { api } });
|
name: "CnameProvider",
|
||||||
useMounted(() => crudExpose.doRefresh());
|
});
|
||||||
|
const { crudBinding, crudRef, crudExpose, context } = useFs({ createCrudOptions });
|
||||||
|
|
||||||
|
const selectedRowKeys = context.selectedRowKeys;
|
||||||
|
const handleBatchDelete = () => {
|
||||||
|
if (selectedRowKeys.value?.length > 0) {
|
||||||
|
Modal.confirm({
|
||||||
|
title: t("certd.confirmTitle"),
|
||||||
|
content: t("certd.confirmDeleteBatch", { count: selectedRowKeys.value.length }),
|
||||||
|
async onOk() {
|
||||||
|
await DeleteBatch(selectedRowKeys.value);
|
||||||
|
message.info(t("certd.deleteSuccess"));
|
||||||
|
crudExpose.doRefresh();
|
||||||
|
selectedRowKeys.value = [];
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
message.error(t("certd.selectRecordsFirst"));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 页面打开后获取列表数据
|
||||||
|
useMounted(async () => {
|
||||||
|
await crudExpose.doRefresh();
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
<style lang="less"></style>
|
||||||
|
|||||||
@@ -1,26 +0,0 @@
|
|||||||
{
|
|
||||||
"parser": "@typescript-eslint/parser",
|
|
||||||
"plugins": [
|
|
||||||
"@typescript-eslint"
|
|
||||||
],
|
|
||||||
"ignorePatterns": ["dist"],
|
|
||||||
"extends": [
|
|
||||||
"plugin:@typescript-eslint/recommended",
|
|
||||||
"plugin:prettier/recommended",
|
|
||||||
"prettier"
|
|
||||||
],
|
|
||||||
"env": {
|
|
||||||
"mocha": true
|
|
||||||
},
|
|
||||||
"rules": {
|
|
||||||
"@typescript-eslint/no-var-requires": "off",
|
|
||||||
"@typescript-eslint/ban-ts-comment": "off",
|
|
||||||
"@typescript-eslint/ban-ts-ignore": "off",
|
|
||||||
"@typescript-eslint/no-explicit-any": "off",
|
|
||||||
"@typescript-eslint/no-empty-function": "off",
|
|
||||||
"@typescript-eslint/no-unused-vars": "off",
|
|
||||||
"@typescript-eslint/no-this-alias": "off",
|
|
||||||
// 允许any
|
|
||||||
"@typescript-eslint/no-unsafe-anyassignment": "off"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,6 +3,17 @@
|
|||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||||
|
|
||||||
|
## [1.42.5](https://github.com/certd/certd/compare/v1.42.4...v1.42.5) (2026-07-15)
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* 修复上传到cos报runtimeDepsService未初始化的问题 ([167b303](https://github.com/certd/certd/commit/167b303faeca02cc11cf97e4be2a3df914852167))
|
||||||
|
* 修复dingtalk通知格式没有换行的bug ([7ed1be9](https://github.com/certd/certd/commit/7ed1be994f8b4b74cdeb38743060c912c027248b))
|
||||||
|
|
||||||
|
### Performance Improvements
|
||||||
|
|
||||||
|
* 优化vke keubconfig获取方式,改成先查询,如果没有再创建临时config ([604fa5b](https://github.com/certd/certd/commit/604fa5be634d099d797bfee5c2b0f26ce0ac8461))
|
||||||
|
|
||||||
## [1.42.4](https://github.com/certd/certd/compare/v1.42.3...v1.42.4) (2026-07-11)
|
## [1.42.4](https://github.com/certd/certd/compare/v1.42.3...v1.42.4) (2026-07-11)
|
||||||
|
|
||||||
### Bug Fixes
|
### Bug Fixes
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
ALTER TABLE `cd_audit_log` ADD COLUMN `scope` varchar(32) NOT NULL DEFAULT 'user';
|
|
||||||
CREATE INDEX `index_audit_log_scope` ON `cd_audit_log` (`scope`);
|
|
||||||
|
|
||||||
ALTER TABLE `cd_audit_log` ADD COLUMN `success` tinyint(1) NOT NULL DEFAULT 1;
|
|
||||||
|
|
||||||
-- 审计日志表索引
|
|
||||||
CREATE INDEX `index_audit_log_type` ON `cd_audit_log` (`type`);
|
|
||||||
CREATE INDEX `index_audit_log_create_time` ON `cd_audit_log` (`create_time`);
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
ALTER TABLE "cd_audit_log" ADD COLUMN "scope" varchar(32) NOT NULL DEFAULT ('user');
|
|
||||||
CREATE INDEX "index_audit_log_scope" ON "cd_audit_log" ("scope");
|
|
||||||
|
|
||||||
ALTER TABLE "cd_audit_log" ADD COLUMN "success" boolean NOT NULL DEFAULT true;
|
|
||||||
|
|
||||||
-- 审计日志表索引
|
|
||||||
CREATE INDEX "index_audit_log_type" ON "cd_audit_log" ("type");
|
|
||||||
CREATE INDEX "index_audit_log_create_time" ON "cd_audit_log" ("create_time");
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
ALTER TABLE "cd_audit_log" ADD COLUMN "scope" varchar(32) NOT NULL DEFAULT ('user');
|
|
||||||
CREATE INDEX "index_audit_log_scope" ON "cd_audit_log" ("scope");
|
|
||||||
|
|
||||||
ALTER TABLE "cd_audit_log" ADD COLUMN "success" boolean NOT NULL DEFAULT (1);
|
|
||||||
|
|
||||||
-- 审计日志表索引
|
|
||||||
CREATE INDEX "index_audit_log_type" ON "cd_audit_log" ("type");
|
|
||||||
CREATE INDEX "index_audit_log_create_time" ON "cd_audit_log" ("create_time");
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@certd/ui-server",
|
"name": "@certd/ui-server",
|
||||||
"version": "1.42.4",
|
"version": "1.42.5",
|
||||||
"description": "fast-server base midway",
|
"description": "fast-server base midway",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
@@ -25,6 +25,7 @@
|
|||||||
"format": "prettier --write src",
|
"format": "prettier --write src",
|
||||||
"lint": "mwts fix",
|
"lint": "mwts fix",
|
||||||
"ci": "pnpm run cov",
|
"ci": "pnpm run cov",
|
||||||
|
"lint2": "cross-env NODE_ENV=production mwtsc -p tsconfig.build.json",
|
||||||
"build-only": "cross-env NODE_ENV=production mwtsc -p tsconfig.build.json --cleanOutDir --skipLibCheck",
|
"build-only": "cross-env NODE_ENV=production mwtsc -p tsconfig.build.json --cleanOutDir --skipLibCheck",
|
||||||
"build": "pnpm run build-only && pnpm run export-metadata",
|
"build": "pnpm run build-only && pnpm run export-metadata",
|
||||||
"export-metadata": "node export-plugin-yaml.js",
|
"export-metadata": "node export-plugin-yaml.js",
|
||||||
@@ -41,20 +42,20 @@
|
|||||||
"lint1": "eslint --fix"
|
"lint1": "eslint --fix"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@certd/acme-client": "^1.42.4",
|
"@certd/acme-client": "^1.42.5",
|
||||||
"@certd/basic": "^1.42.4",
|
"@certd/basic": "^1.42.5",
|
||||||
"@certd/commercial-core": "^1.42.4",
|
"@certd/commercial-core": "^1.42.5",
|
||||||
"@certd/cv4pve-api-javascript": "^8.4.2",
|
"@certd/cv4pve-api-javascript": "^8.4.2",
|
||||||
"@certd/jdcloud": "^1.42.4",
|
"@certd/jdcloud": "^1.42.5",
|
||||||
"@certd/lib-huawei": "^1.42.4",
|
"@certd/lib-huawei": "^1.42.5",
|
||||||
"@certd/lib-k8s": "^1.42.4",
|
"@certd/lib-k8s": "^1.42.5",
|
||||||
"@certd/lib-server": "^1.42.4",
|
"@certd/lib-server": "^1.42.5",
|
||||||
"@certd/midway-flyway-js": "^1.42.4",
|
"@certd/midway-flyway-js": "^1.42.5",
|
||||||
"@certd/pipeline": "^1.42.4",
|
"@certd/pipeline": "^1.42.5",
|
||||||
"@certd/plugin-cert": "^1.42.4",
|
"@certd/plugin-cert": "^1.42.5",
|
||||||
"@certd/plugin-lib": "^1.42.4",
|
"@certd/plugin-lib": "^1.42.5",
|
||||||
"@certd/plugin-plus": "^1.42.4",
|
"@certd/plugin-plus": "^1.42.5",
|
||||||
"@certd/plus-core": "^1.42.4",
|
"@certd/plus-core": "^1.42.5",
|
||||||
"@koa/cors": "^5.0.0",
|
"@koa/cors": "^5.0.0",
|
||||||
"@midwayjs/bootstrap": "3.20.11",
|
"@midwayjs/bootstrap": "3.20.11",
|
||||||
"@midwayjs/cache": "3.14.0",
|
"@midwayjs/cache": "3.14.0",
|
||||||
@@ -125,6 +126,7 @@
|
|||||||
"@types/nodemailer": "^6.4.8",
|
"@types/nodemailer": "^6.4.8",
|
||||||
"c8": "^10.1.2",
|
"c8": "^10.1.2",
|
||||||
"cross-env": "^7.0.3",
|
"cross-env": "^7.0.3",
|
||||||
|
"eslint": "^7.32.0",
|
||||||
"esmock": "^2.7.5",
|
"esmock": "^2.7.5",
|
||||||
"mocha": "^10.6.0",
|
"mocha": "^10.6.0",
|
||||||
"mwts": "^1.3.0",
|
"mwts": "^1.3.0",
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import cors from "@koa/cors";
|
|||||||
import { GlobalExceptionMiddleware } from "./middleware/global-exception.js";
|
import { GlobalExceptionMiddleware } from "./middleware/global-exception.js";
|
||||||
import { PreviewMiddleware } from "./middleware/preview.js";
|
import { PreviewMiddleware } from "./middleware/preview.js";
|
||||||
import { AuthorityMiddleware } from "./middleware/authority.js";
|
import { AuthorityMiddleware } from "./middleware/authority.js";
|
||||||
import { AuditLogMiddleware } from "./middleware/audit-log.js";
|
|
||||||
import { logger } from "@certd/basic";
|
import { logger } from "@certd/basic";
|
||||||
import { ResetPasswdMiddleware } from "./middleware/reset-passwd/middleware.js";
|
import { ResetPasswdMiddleware } from "./middleware/reset-passwd/middleware.js";
|
||||||
import DefaultConfig from "./config/config.default.js";
|
import DefaultConfig from "./config/config.default.js";
|
||||||
@@ -114,7 +113,6 @@ export class MainConfiguration {
|
|||||||
PreviewMiddleware,
|
PreviewMiddleware,
|
||||||
//授权处理
|
//授权处理
|
||||||
AuthorityMiddleware,
|
AuthorityMiddleware,
|
||||||
AuditLogMiddleware,
|
|
||||||
|
|
||||||
//resetPasswd,重置密码模式下不提供服务
|
//resetPasswd,重置密码模式下不提供服务
|
||||||
ResetPasswdMiddleware,
|
ResetPasswdMiddleware,
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import { BaseController, CommonException, Constants, SysSettingsService } from "
|
|||||||
import { CodeService } from "../../../modules/basic/service/code-service.js";
|
import { CodeService } from "../../../modules/basic/service/code-service.js";
|
||||||
import { UserService } from "../../../modules/sys/authority/service/user-service.js";
|
import { UserService } from "../../../modules/sys/authority/service/user-service.js";
|
||||||
import { LoginService } from "../../../modules/login/service/login-service.js";
|
import { LoginService } from "../../../modules/login/service/login-service.js";
|
||||||
import { AuditType } from "../../../modules/sys/enterprise/service/audit-constants.js";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
@@ -20,11 +19,7 @@ export class ForgotPasswordController extends BaseController {
|
|||||||
@Inject()
|
@Inject()
|
||||||
sysSettingsService: SysSettingsService;
|
sysSettingsService: SysSettingsService;
|
||||||
|
|
||||||
getAuditType(): string {
|
@Post("/forgotPassword", { description: Constants.per.guest })
|
||||||
return AuditType.login.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post("/forgotPassword", { description: Constants.per.guest, summary: "找回密码" })
|
|
||||||
public async forgotPassword(
|
public async forgotPassword(
|
||||||
@Body(ALL)
|
@Body(ALL)
|
||||||
body: any
|
body: any
|
||||||
@@ -33,13 +28,15 @@ export class ForgotPasswordController extends BaseController {
|
|||||||
if (!sysSettings.selfServicePasswordRetrievalEnabled) {
|
if (!sysSettings.selfServicePasswordRetrievalEnabled) {
|
||||||
throw new CommonException("暂未开启自助找回");
|
throw new CommonException("暂未开启自助找回");
|
||||||
}
|
}
|
||||||
|
// 找回密码的验证码允许错误次数
|
||||||
|
const maxErrorCount = 5;
|
||||||
|
|
||||||
if (body.type === "email") {
|
if (body.type === "email") {
|
||||||
this.codeService.checkEmailCode({
|
this.codeService.checkEmailCode({
|
||||||
verificationType: "forgotPassword",
|
verificationType: "forgotPassword",
|
||||||
email: body.input,
|
email: body.input,
|
||||||
validateCode: body.validateCode,
|
validateCode: body.validateCode,
|
||||||
maxErrorCount: 5,
|
maxErrorCount: maxErrorCount,
|
||||||
throwError: true,
|
throwError: true,
|
||||||
});
|
});
|
||||||
} else if (body.type === "mobile") {
|
} else if (body.type === "mobile") {
|
||||||
@@ -48,15 +45,14 @@ export class ForgotPasswordController extends BaseController {
|
|||||||
mobile: body.input,
|
mobile: body.input,
|
||||||
phoneCode: body.phoneCode,
|
phoneCode: body.phoneCode,
|
||||||
smsCode: body.validateCode,
|
smsCode: body.validateCode,
|
||||||
maxErrorCount: 5,
|
maxErrorCount: maxErrorCount,
|
||||||
throwError: true,
|
throwError: true,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
throw new CommonException("暂不支持的找回类型,请联系管理员找回");
|
throw new CommonException("暂不支持的找回类型,请联系管理员找回");
|
||||||
}
|
}
|
||||||
const { id, username } = await this.userService.forgotPassword(body);
|
const username = await this.userService.forgotPassword(body);
|
||||||
username && this.loginService.clearCacheOnSuccess(username);
|
username && this.loginService.clearCacheOnSuccess(username);
|
||||||
this.auditLog({ userId: id, content: "用户请求找回密码" });
|
|
||||||
return this.ok();
|
return this.ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,9 @@ import { CodeService } from "../../../modules/basic/service/code-service.js";
|
|||||||
import { checkComm } from "@certd/plus-core";
|
import { checkComm } from "@certd/plus-core";
|
||||||
import { CaptchaService } from "../../../modules/basic/service/captcha-service.js";
|
import { CaptchaService } from "../../../modules/basic/service/captcha-service.js";
|
||||||
import { PasskeyService } from "../../../modules/login/service/passkey-service.js";
|
import { PasskeyService } from "../../../modules/login/service/passkey-service.js";
|
||||||
import { AuditType } from "../../../modules/sys/enterprise/service/audit-constants.js";
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
@Provide()
|
@Provide()
|
||||||
@Controller("/api/")
|
@Controller("/api/")
|
||||||
export class LoginController extends BaseController {
|
export class LoginController extends BaseController {
|
||||||
@@ -26,11 +27,7 @@ export class LoginController extends BaseController {
|
|||||||
@Inject()
|
@Inject()
|
||||||
passkeyService: PasskeyService;
|
passkeyService: PasskeyService;
|
||||||
|
|
||||||
getAuditType(): string {
|
@Post("/login", { description: Constants.per.guest })
|
||||||
return AuditType.login.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post("/login", { description: Constants.per.guest, summary: "用户名密码登录" })
|
|
||||||
public async login(
|
public async login(
|
||||||
@Body(ALL)
|
@Body(ALL)
|
||||||
body: any,
|
body: any,
|
||||||
@@ -41,22 +38,16 @@ export class LoginController extends BaseController {
|
|||||||
if (settings.captchaEnabled === true) {
|
if (settings.captchaEnabled === true) {
|
||||||
await this.captchaService.doValidate({ form: body.captcha, must: false, captchaAddonId: settings.captchaAddonId, req: { remoteIp } });
|
await this.captchaService.doValidate({ form: body.captcha, must: false, captchaAddonId: settings.captchaAddonId, req: { remoteIp } });
|
||||||
}
|
}
|
||||||
try {
|
const token = await this.loginService.loginByPassword(body);
|
||||||
const token = await this.loginService.loginByPassword(body);
|
this.writeTokenCookie(token);
|
||||||
this.writeTokenCookie(token);
|
return this.ok(token);
|
||||||
this.auditLog({ userId: token.userId, username: token.username, content: `用户「${body.username}」登录成功` });
|
|
||||||
return this.ok(token);
|
|
||||||
} catch (err: any) {
|
|
||||||
this.auditLog({ userId: err.userId, username: body.username, content: `用户「${body.username}」登录失败:${err.message}` });
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private writeTokenCookie(token: { expire: any; token: any }) {
|
private writeTokenCookie(token: { expire: any; token: any }) {
|
||||||
// this.loginService.writeTokenCookie(this.ctx,token);
|
// this.loginService.writeTokenCookie(this.ctx,token);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/loginBySms", { description: Constants.per.guest, summary: "短信验证码登录" })
|
@Post("/loginBySms", { description: Constants.per.guest })
|
||||||
public async loginBySms(
|
public async loginBySms(
|
||||||
@Body(ALL)
|
@Body(ALL)
|
||||||
body: any
|
body: any
|
||||||
@@ -67,42 +58,31 @@ export class LoginController extends BaseController {
|
|||||||
}
|
}
|
||||||
checkComm();
|
checkComm();
|
||||||
|
|
||||||
try {
|
const token = await this.loginService.loginBySmsCode({
|
||||||
const token = await this.loginService.loginBySmsCode({
|
phoneCode: body.phoneCode,
|
||||||
phoneCode: body.phoneCode,
|
mobile: body.mobile,
|
||||||
mobile: body.mobile,
|
smsCode: body.smsCode,
|
||||||
smsCode: body.smsCode,
|
randomStr: body.randomStr,
|
||||||
randomStr: body.randomStr,
|
inviteCode: body.inviteCode,
|
||||||
inviteCode: body.inviteCode,
|
});
|
||||||
});
|
|
||||||
|
|
||||||
this.writeTokenCookie(token);
|
this.writeTokenCookie(token);
|
||||||
this.auditLog({ userId: token.userId, username: token.username, content: `用户「${body.mobile}」短信登录成功` });
|
|
||||||
return this.ok(token);
|
return this.ok(token);
|
||||||
} catch (err: any) {
|
|
||||||
this.auditLog({ userId: err.userId, username: body.mobile, content: `用户「${body.mobile}」短信登录失败:${err.message}` });
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/loginByTwoFactor", { description: Constants.per.guest, summary: "两步验证登录" })
|
@Post("/loginByTwoFactor", { description: Constants.per.guest })
|
||||||
public async loginByTwoFactor(
|
public async loginByTwoFactor(
|
||||||
@Body(ALL)
|
@Body(ALL)
|
||||||
body: any
|
body: any
|
||||||
) {
|
) {
|
||||||
try {
|
const token = await this.loginService.loginByTwoFactor({
|
||||||
const token = await this.loginService.loginByTwoFactor({
|
loginId: body.loginId,
|
||||||
loginId: body.loginId,
|
verifyCode: body.verifyCode,
|
||||||
verifyCode: body.verifyCode,
|
});
|
||||||
});
|
|
||||||
|
|
||||||
this.writeTokenCookie(token);
|
this.writeTokenCookie(token);
|
||||||
this.auditLog({ userId: token.userId, username: token.username, content: `用户「${body.loginId}」两步验证登录成功` });
|
return this.ok(token);
|
||||||
return this.ok(token);
|
|
||||||
} catch (err: any) {
|
|
||||||
this.auditLog({ userId: err.userId, username: body.loginId, content: `用户「${body.loginId}」两步验证登录失败:${err.message}` });
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/passkey/generateAuthentication", { description: Constants.per.guest })
|
@Post("/passkey/generateAuthentication", { description: Constants.per.guest })
|
||||||
@@ -112,30 +92,24 @@ export class LoginController extends BaseController {
|
|||||||
return this.ok(options);
|
return this.ok(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/loginByPasskey", { description: Constants.per.guest, summary: "Passkey登录" })
|
@Post("/loginByPasskey", { description: Constants.per.guest })
|
||||||
public async loginByPasskey(
|
public async loginByPasskey(
|
||||||
@Body(ALL)
|
@Body(ALL)
|
||||||
body: any
|
body: any
|
||||||
) {
|
) {
|
||||||
try {
|
const credential = body.credential;
|
||||||
const credential = body.credential;
|
const challenge = body.challenge;
|
||||||
const challenge = body.challenge;
|
|
||||||
|
|
||||||
const token = await this.loginService.loginByPasskey(
|
const token = await this.loginService.loginByPasskey(
|
||||||
{
|
{
|
||||||
credential,
|
credential,
|
||||||
challenge,
|
challenge,
|
||||||
},
|
},
|
||||||
this.ctx
|
this.ctx
|
||||||
);
|
);
|
||||||
|
|
||||||
this.writeTokenCookie(token);
|
// this.writeTokenCookie(token);
|
||||||
this.auditLog({ userId: token.userId, username: token.username, content: "用户Passkey登录成功" });
|
return this.ok(token);
|
||||||
return this.ok(token);
|
|
||||||
} catch (err: any) {
|
|
||||||
this.auditLog({ userId: err.userId, username: body.credential, content: `用户Passkey登录失败:${err.message}` });
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/logout", { description: Constants.per.authOnly })
|
@Post("/logout", { description: Constants.per.authOnly })
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import { LoginService } from "../../../modules/login/service/login-service.js";
|
|||||||
import { OauthBoundService } from "../../../modules/login/service/oauth-bound-service.js";
|
import { OauthBoundService } from "../../../modules/login/service/oauth-bound-service.js";
|
||||||
import { AddonGetterService } from "../../../modules/pipeline/service/addon-getter-service.js";
|
import { AddonGetterService } from "../../../modules/pipeline/service/addon-getter-service.js";
|
||||||
import { UserEntity } from "../../../modules/sys/authority/entity/user.js";
|
import { UserEntity } from "../../../modules/sys/authority/entity/user.js";
|
||||||
import { AuditType } from "../../../modules/sys/enterprise/service/audit-constants.js";
|
|
||||||
import { IOauthProvider } from "../../../plugins/plugin-oauth/api.js";
|
import { IOauthProvider } from "../../../plugins/plugin-oauth/api.js";
|
||||||
|
|
||||||
type OauthProviderSetting = {
|
type OauthProviderSetting = {
|
||||||
@@ -49,10 +48,6 @@ export class ConnectController extends BaseController {
|
|||||||
@Inject()
|
@Inject()
|
||||||
addonService: AddonService;
|
addonService: AddonService;
|
||||||
|
|
||||||
getAuditType(): string {
|
|
||||||
return AuditType.login.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async getOauthProvider(type: string) {
|
private async getOauthProvider(type: string) {
|
||||||
const publicSettings = await this.sysSettingsService.getPublicSettings();
|
const publicSettings = await this.sysSettingsService.getPublicSettings();
|
||||||
if (!publicSettings?.oauthEnabled) {
|
if (!publicSettings?.oauthEnabled) {
|
||||||
@@ -73,11 +68,12 @@ export class ConnectController extends BaseController {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/login", { description: Constants.per.guest, summary: "第三方登录" })
|
@Post("/login", { description: Constants.per.guest })
|
||||||
public async login(@Body(ALL) body: { type: string; subtype?: string; forType?: string; from?: string }) {
|
public async login(@Body(ALL) body: { type: string; subtype?: string; forType?: string; from?: string }) {
|
||||||
const oauthProvider = await this.getOauthProvider(body.type);
|
const oauthProvider = await this.getOauthProvider(body.type);
|
||||||
const installInfo = await this.sysSettingsService.getSetting<SysInstallInfo>(SysInstallInfo);
|
const installInfo = await this.sysSettingsService.getSetting<SysInstallInfo>(SysInstallInfo);
|
||||||
const bindUrl = installInfo?.bindUrl || "";
|
const bindUrl = installInfo?.bindUrl || "";
|
||||||
|
//构造登录url
|
||||||
const redirectUrl = `${bindUrl}api/oauth/callback/${body.type}`;
|
const redirectUrl = `${bindUrl}api/oauth/callback/${body.type}`;
|
||||||
|
|
||||||
const stateObj = {
|
const stateObj = {
|
||||||
@@ -99,6 +95,8 @@ export class ConnectController extends BaseController {
|
|||||||
});
|
});
|
||||||
this.ctx.cookies.set("oauth_ticket", ticket, {
|
this.ctx.cookies.set("oauth_ticket", ticket, {
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
|
// secure: true,
|
||||||
|
// sameSite: "strict",
|
||||||
});
|
});
|
||||||
return this.ok({ loginUrl, ticket });
|
return this.ok({ loginUrl, ticket });
|
||||||
}
|
}
|
||||||
@@ -155,7 +153,7 @@ export class ConnectController extends BaseController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/getLogoutUrl", { description: Constants.per.guest, summary: "第三方登出" })
|
@Post("/getLogoutUrl", { description: Constants.per.guest })
|
||||||
public async logout(@Body(ALL) body: any) {
|
public async logout(@Body(ALL) body: any) {
|
||||||
checkPlus();
|
checkPlus();
|
||||||
const oauthProvider = await this.getOauthProvider(body.type);
|
const oauthProvider = await this.getOauthProvider(body.type);
|
||||||
@@ -197,7 +195,7 @@ export class ConnectController extends BaseController {
|
|||||||
// this.loginService.writeTokenCookie(this.ctx,token);
|
// this.loginService.writeTokenCookie(this.ctx,token);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/autoRegister", { description: Constants.per.guest, summary: "第三方自动注册" })
|
@Post("/autoRegister", { description: Constants.per.guest })
|
||||||
public async autoRegister(@Body(ALL) body: { validationCode: string; type: string; inviteCode?: string }) {
|
public async autoRegister(@Body(ALL) body: { validationCode: string; type: string; inviteCode?: string }) {
|
||||||
const validationValue = this.codeService.getValidationValue(body.validationCode);
|
const validationValue = this.codeService.getValidationValue(body.validationCode);
|
||||||
if (!validationValue) {
|
if (!validationValue) {
|
||||||
@@ -221,12 +219,12 @@ export class ConnectController extends BaseController {
|
|||||||
|
|
||||||
const loginRes = await this.loginService.generateToken(newUser);
|
const loginRes = await this.loginService.generateToken(newUser);
|
||||||
this.writeTokenCookie(loginRes);
|
this.writeTokenCookie(loginRes);
|
||||||
this.auditLog({ userId: newUser.id, content: `第三方账号自动注册,类型: ${body.type}` });
|
|
||||||
return this.ok(loginRes);
|
return this.ok(loginRes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/bind", { description: Constants.per.loginOnly, summary: "绑定第三方账号" })
|
@Post("/bind", { description: Constants.per.loginOnly })
|
||||||
public async bind(@Body(ALL) body: any) {
|
public async bind(@Body(ALL) body: any) {
|
||||||
|
//需要已登录
|
||||||
const userId = this.getUserId();
|
const userId = this.getUserId();
|
||||||
const validationValue = this.codeService.getValidationValue(body.validationCode);
|
const validationValue = this.codeService.getValidationValue(body.validationCode);
|
||||||
if (!validationValue) {
|
if (!validationValue) {
|
||||||
@@ -240,18 +238,17 @@ export class ConnectController extends BaseController {
|
|||||||
type,
|
type,
|
||||||
openId,
|
openId,
|
||||||
});
|
});
|
||||||
this.auditLog({ userId, content: `第三方账号绑定,类型: ${body.type}` });
|
|
||||||
return this.ok(1);
|
return this.ok(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/unbind", { description: Constants.per.loginOnly, summary: "解绑第三方账号" })
|
@Post("/unbind", { description: Constants.per.loginOnly })
|
||||||
public async unbind(@Body(ALL) body: any) {
|
public async unbind(@Body(ALL) body: any) {
|
||||||
|
//需要已登录
|
||||||
const userId = this.getUserId();
|
const userId = this.getUserId();
|
||||||
await this.oauthBoundService.unbind({
|
await this.oauthBoundService.unbind({
|
||||||
userId,
|
userId,
|
||||||
type: body.type,
|
type: body.type,
|
||||||
});
|
});
|
||||||
this.auditLog({ userId, content: `第三方账号解绑,类型: ${body.type}` });
|
|
||||||
return this.ok(1);
|
return this.ok(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import { RegisterType } from "../../../modules/sys/authority/service/user-servic
|
|||||||
import { CodeService } from "../../../modules/basic/service/code-service.js";
|
import { CodeService } from "../../../modules/basic/service/code-service.js";
|
||||||
import { checkComm, checkPlus } from "@certd/plus-core";
|
import { checkComm, checkPlus } from "@certd/plus-core";
|
||||||
import { LoginService } from "../../../modules/login/service/login-service.js";
|
import { LoginService } from "../../../modules/login/service/login-service.js";
|
||||||
import { AuditType } from "../../../modules/sys/enterprise/service/audit-constants.js";
|
|
||||||
|
|
||||||
export type RegisterReq = {
|
export type RegisterReq = {
|
||||||
type: RegisterType;
|
type: RegisterType;
|
||||||
@@ -32,11 +31,7 @@ export class RegisterController extends BaseController {
|
|||||||
@Inject()
|
@Inject()
|
||||||
sysSettingsService: SysSettingsService;
|
sysSettingsService: SysSettingsService;
|
||||||
|
|
||||||
getAuditType(): string {
|
@Post("/register", { description: Constants.per.guest })
|
||||||
return AuditType.login.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post("/register", { description: Constants.per.guest, summary: "用户注册" })
|
|
||||||
public async register(
|
public async register(
|
||||||
@Body(ALL)
|
@Body(ALL)
|
||||||
body: RegisterReq,
|
body: RegisterReq,
|
||||||
@@ -65,7 +60,6 @@ export class RegisterController extends BaseController {
|
|||||||
password: body.password,
|
password: body.password,
|
||||||
} as any;
|
} as any;
|
||||||
const newUser = await this.loginService.register(body.type, registerUser, body.inviteCode);
|
const newUser = await this.loginService.register(body.type, registerUser, body.inviteCode);
|
||||||
this.auditLog({ userId: newUser.id, username: body.username, content: `用户「${body.username}」注册成功` });
|
|
||||||
return this.ok(newUser);
|
return this.ok(newUser);
|
||||||
} else if (body.type === "mobile") {
|
} else if (body.type === "mobile") {
|
||||||
if (sysPublicSettings.mobileRegisterEnabled === false) {
|
if (sysPublicSettings.mobileRegisterEnabled === false) {
|
||||||
@@ -86,7 +80,6 @@ export class RegisterController extends BaseController {
|
|||||||
password: body.password,
|
password: body.password,
|
||||||
} as any;
|
} as any;
|
||||||
const newUser = await this.loginService.register(body.type, registerUser, body.inviteCode);
|
const newUser = await this.loginService.register(body.type, registerUser, body.inviteCode);
|
||||||
this.auditLog({ userId: newUser.id, username: body.mobile, content: `用户「${body.mobile}」注册成功` });
|
|
||||||
return this.ok(newUser);
|
return this.ok(newUser);
|
||||||
} else if (body.type === "email") {
|
} else if (body.type === "email") {
|
||||||
if (sysPublicSettings.emailRegisterEnabled === false) {
|
if (sysPublicSettings.emailRegisterEnabled === false) {
|
||||||
@@ -104,7 +97,6 @@ export class RegisterController extends BaseController {
|
|||||||
password: body.password,
|
password: body.password,
|
||||||
} as any;
|
} as any;
|
||||||
const newUser = await this.loginService.register(body.type, registerUser, body.inviteCode);
|
const newUser = await this.loginService.register(body.type, registerUser, body.inviteCode);
|
||||||
this.auditLog({ userId: newUser.id, username: body.email, content: `用户「${body.email}」注册成功` });
|
|
||||||
return this.ok(newUser);
|
return this.ok(newUser);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { ALL, Body, Controller, Inject, Post, Provide } from "@midwayjs/core";
|
import { ALL, Body, Controller, Inject, Post, Provide } from "@midwayjs/core";
|
||||||
import { BaseController, PlusService, SysInstallInfo, SysSettingsService } from "@certd/lib-server";
|
import { BaseController, PlusService, SysInstallInfo, SysSettingsService } from "@certd/lib-server";
|
||||||
import { AuditType } from "../../../modules/sys/enterprise/service/audit-constants.js";
|
|
||||||
|
|
||||||
export type PreBindUserReq = {
|
export type PreBindUserReq = {
|
||||||
userId: number;
|
userId: number;
|
||||||
@@ -19,21 +18,17 @@ export class BasicController extends BaseController {
|
|||||||
@Inject()
|
@Inject()
|
||||||
sysSettingsService: SysSettingsService;
|
sysSettingsService: SysSettingsService;
|
||||||
|
|
||||||
getAuditType(): string {
|
@Post("/preBindUser", { description: "sys:settings:edit" })
|
||||||
return AuditType.account.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post("/preBindUser", { description: "sys:settings:edit", summary: "预绑定用户" })
|
|
||||||
public async preBindUser(@Body(ALL) body: PreBindUserReq) {
|
public async preBindUser(@Body(ALL) body: PreBindUserReq) {
|
||||||
|
// 设置缓存内容
|
||||||
if (body.userId == null || body.userId <= 0) {
|
if (body.userId == null || body.userId <= 0) {
|
||||||
throw new Error("用户ID不能为空");
|
throw new Error("用户ID不能为空");
|
||||||
}
|
}
|
||||||
await this.plusService.userPreBind(body.userId);
|
await this.plusService.userPreBind(body.userId);
|
||||||
await this.auditLog({ content: `预绑定了用户(ID:${body.userId})` });
|
|
||||||
return this.ok({});
|
return this.ok({});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/bindUser", { description: "sys:settings:edit", summary: "绑定用户" })
|
@Post("/bindUser", { description: "sys:settings:edit" })
|
||||||
public async bindUser(@Body(ALL) body: BindUserReq) {
|
public async bindUser(@Body(ALL) body: BindUserReq) {
|
||||||
if (body.userId == null || body.userId <= 0) {
|
if (body.userId == null || body.userId <= 0) {
|
||||||
throw new Error("用户ID不能为空");
|
throw new Error("用户ID不能为空");
|
||||||
@@ -41,23 +36,20 @@ export class BasicController extends BaseController {
|
|||||||
const installInfo: SysInstallInfo = await this.sysSettingsService.getSetting(SysInstallInfo);
|
const installInfo: SysInstallInfo = await this.sysSettingsService.getSetting(SysInstallInfo);
|
||||||
installInfo.bindUserId = body.userId;
|
installInfo.bindUserId = body.userId;
|
||||||
await this.sysSettingsService.saveSetting(installInfo);
|
await this.sysSettingsService.saveSetting(installInfo);
|
||||||
await this.auditLog({ content: `绑定了用户(ID:${body.userId})` });
|
|
||||||
return this.ok({});
|
return this.ok({});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/unbindUser", { description: "sys:settings:edit", summary: "解绑用户" })
|
@Post("/unbindUser", { description: "sys:settings:edit" })
|
||||||
public async unbindUser() {
|
public async unbindUser() {
|
||||||
const installInfo: SysInstallInfo = await this.sysSettingsService.getSetting(SysInstallInfo);
|
const installInfo: SysInstallInfo = await this.sysSettingsService.getSetting(SysInstallInfo);
|
||||||
installInfo.bindUserId = null;
|
installInfo.bindUserId = null;
|
||||||
await this.sysSettingsService.saveSetting(installInfo);
|
await this.sysSettingsService.saveSetting(installInfo);
|
||||||
await this.auditLog({ content: "解绑了用户" });
|
|
||||||
return this.ok({});
|
return this.ok({});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/updateLicense", { description: "sys:settings:edit", summary: "更新许可证" })
|
@Post("/updateLicense", { description: "sys:settings:edit" })
|
||||||
public async updateLicense(@Body(ALL) body: { license: string }) {
|
public async updateLicense(@Body(ALL) body: { license: string }) {
|
||||||
await this.plusService.updateLicense(body.license);
|
await this.plusService.updateLicense(body.license);
|
||||||
await this.auditLog({ content: "更新了许可证" });
|
|
||||||
return this.ok(true);
|
return this.ok(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,42 +0,0 @@
|
|||||||
import { BaseController, Constants } from "@certd/lib-server";
|
|
||||||
import { ALL, Body, Controller, Inject, Post, Provide, Query } from "@midwayjs/core";
|
|
||||||
import { ApiTags } from "@midwayjs/swagger";
|
|
||||||
import { AuditService } from "../../../modules/sys/enterprise/service/audit-service.js";
|
|
||||||
import { buildAuditTypeDict, buildAuditActionDict } from "../../../modules/sys/enterprise/service/audit-constants.js";
|
|
||||||
|
|
||||||
@Provide()
|
|
||||||
@ApiTags(["audit"])
|
|
||||||
@Controller("/api/sys/audit")
|
|
||||||
export class SysAuditLogController extends BaseController {
|
|
||||||
@Inject()
|
|
||||||
auditService: AuditService;
|
|
||||||
|
|
||||||
@Post("/page", { description: Constants.per.authOnly, summary: "分页查询审计日志" })
|
|
||||||
async page(@Body(ALL) body: any) {
|
|
||||||
if (body.query?.scope) {
|
|
||||||
delete body.query.userId;
|
|
||||||
}
|
|
||||||
const pageRet = await this.auditService.page(body);
|
|
||||||
return this.ok(pageRet);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post("/delete", { description: Constants.per.authOnly, summary: "删除审计日志" })
|
|
||||||
async delete(@Query("id") id: number) {
|
|
||||||
await this.auditService.delete([id]);
|
|
||||||
return this.ok({});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post("/clean", { description: Constants.per.authOnly, summary: "清理过期审计日志" })
|
|
||||||
async clean(@Body("retentionDays") retentionDays: number) {
|
|
||||||
const count = await this.auditService.cleanExpired(retentionDays || 90);
|
|
||||||
return this.ok({ deletedCount: count });
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post("/dict", { description: Constants.per.authOnly, summary: "获取审计类型和动作字典" })
|
|
||||||
async getDict() {
|
|
||||||
return this.ok({
|
|
||||||
types: buildAuditTypeDict(),
|
|
||||||
actions: buildAuditActionDict(),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
import { ALL, Body, Controller, Inject, Post, Provide, Query } from "@midwayjs/core";
|
import { ALL, Body, Controller, Inject, Post, Provide, Query } from "@midwayjs/core";
|
||||||
import { CrudController } from "@certd/lib-server";
|
import { CrudController } from "@certd/lib-server";
|
||||||
import { PermissionService } from "../../../modules/sys/authority/service/permission-service.js";
|
import { PermissionService } from "../../../modules/sys/authority/service/permission-service.js";
|
||||||
import { AuditType } from "../../../modules/sys/enterprise/service/audit-constants.js";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 权限资源
|
* 权限资源
|
||||||
@@ -15,11 +14,8 @@ export class PermissionController extends CrudController<PermissionService> {
|
|||||||
getService() {
|
getService() {
|
||||||
return this.service;
|
return this.service;
|
||||||
}
|
}
|
||||||
getAuditType(): string {
|
|
||||||
return AuditType.permission.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post("/page", { description: "sys:auth:per:view", summary: "查询权限分页列表" })
|
@Post("/page", { description: "sys:auth:per:view" })
|
||||||
async page(
|
async page(
|
||||||
@Body(ALL)
|
@Body(ALL)
|
||||||
body
|
body
|
||||||
@@ -27,42 +23,30 @@ export class PermissionController extends CrudController<PermissionService> {
|
|||||||
return await super.page(body);
|
return await super.page(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/add", { description: "sys:auth:per:add", summary: "添加权限" })
|
@Post("/add", { description: "sys:auth:per:add" })
|
||||||
async add(
|
async add(
|
||||||
@Body(ALL)
|
@Body(ALL)
|
||||||
bean
|
bean
|
||||||
) {
|
) {
|
||||||
const res = await super.add(bean);
|
return await super.add(bean);
|
||||||
await this.auditLog({
|
|
||||||
content: `新增了权限「${bean.name}」(ID:${res.data})`,
|
|
||||||
});
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/update", { description: "sys:auth:per:edit", summary: "更新权限" })
|
@Post("/update", { description: "sys:auth:per:edit" })
|
||||||
async update(
|
async update(
|
||||||
@Body(ALL)
|
@Body(ALL)
|
||||||
bean
|
bean
|
||||||
) {
|
) {
|
||||||
const res = await super.update(bean);
|
return await super.update(bean);
|
||||||
await this.auditLog({
|
|
||||||
content: `修改了权限「${bean.name}」(ID:${bean.id})`,
|
|
||||||
});
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
@Post("/delete", { description: "sys:auth:per:remove", summary: "删除权限" })
|
@Post("/delete", { description: "sys:auth:per:remove" })
|
||||||
async delete(
|
async delete(
|
||||||
@Query("id")
|
@Query("id")
|
||||||
id: number
|
id: number
|
||||||
) {
|
) {
|
||||||
const res = await super.delete(id);
|
return await super.delete(id);
|
||||||
await this.auditLog({
|
|
||||||
content: `删除了权限(ID:${id})`,
|
|
||||||
});
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/tree", { description: "sys:auth:per:view", summary: "查询权限树" })
|
@Post("/tree", { description: "sys:auth:per:view" })
|
||||||
async tree() {
|
async tree() {
|
||||||
const tree = await this.service.tree({});
|
const tree = await this.service.tree({});
|
||||||
return this.ok(tree);
|
return this.ok(tree);
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { ALL, Body, Controller, Inject, Post, Provide, Query } from "@midwayjs/core";
|
import { ALL, Body, Controller, Inject, Post, Provide, Query } from "@midwayjs/core";
|
||||||
import { CrudController } from "@certd/lib-server";
|
import { CrudController } from "@certd/lib-server";
|
||||||
import { RoleService } from "../../../modules/sys/authority/service/role-service.js";
|
import { RoleService } from "../../../modules/sys/authority/service/role-service.js";
|
||||||
import { AuditType } from "../../../modules/sys/enterprise/service/audit-constants.js";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 系统用户
|
* 系统用户
|
||||||
@@ -16,10 +15,6 @@ export class RoleController extends CrudController<RoleService> {
|
|||||||
return this.service;
|
return this.service;
|
||||||
}
|
}
|
||||||
|
|
||||||
getAuditType(): string {
|
|
||||||
return AuditType.role.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post("/page", { description: "sys:auth:role:view" })
|
@Post("/page", { description: "sys:auth:role:view" })
|
||||||
async page(
|
async page(
|
||||||
@Body(ALL)
|
@Body(ALL)
|
||||||
@@ -34,30 +29,22 @@ export class RoleController extends CrudController<RoleService> {
|
|||||||
return this.ok(ret);
|
return this.ok(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/add", { description: "sys:auth:role:add", summary: "新增角色" })
|
@Post("/add", { description: "sys:auth:role:add" })
|
||||||
async add(
|
async add(
|
||||||
@Body(ALL)
|
@Body(ALL)
|
||||||
bean
|
bean
|
||||||
) {
|
) {
|
||||||
const res = await super.add(bean);
|
return await super.add(bean);
|
||||||
await this.auditLog({
|
|
||||||
content: `新增了角色「${bean.name}」(ID:${res.data})`,
|
|
||||||
});
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/update", { description: "sys:auth:role:edit", summary: "修改角色" })
|
@Post("/update", { description: "sys:auth:role:edit" })
|
||||||
async update(
|
async update(
|
||||||
@Body(ALL)
|
@Body(ALL)
|
||||||
bean
|
bean
|
||||||
) {
|
) {
|
||||||
const res = await super.update(bean);
|
return await super.update(bean);
|
||||||
await this.auditLog({
|
|
||||||
content: `修改了角色「${bean.name}」(ID:${bean.id})`,
|
|
||||||
});
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
@Post("/delete", { description: "sys:auth:role:remove", summary: "删除角色" })
|
@Post("/delete", { description: "sys:auth:role:remove" })
|
||||||
async delete(
|
async delete(
|
||||||
@Query("id")
|
@Query("id")
|
||||||
id: number
|
id: number
|
||||||
@@ -65,11 +52,7 @@ export class RoleController extends CrudController<RoleService> {
|
|||||||
if (id === 1) {
|
if (id === 1) {
|
||||||
throw new Error("不能删除默认的管理员角色");
|
throw new Error("不能删除默认的管理员角色");
|
||||||
}
|
}
|
||||||
const res = await super.delete(id);
|
return await super.delete(id);
|
||||||
await this.auditLog({
|
|
||||||
content: `删除了角色(ID:${id})`,
|
|
||||||
});
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/getPermissionTree", { description: "sys:auth:role:view" })
|
@Post("/getPermissionTree", { description: "sys:auth:role:view" })
|
||||||
@@ -95,10 +78,9 @@ export class RoleController extends CrudController<RoleService> {
|
|||||||
* @param roleId
|
* @param roleId
|
||||||
* @param permissionIds
|
* @param permissionIds
|
||||||
*/
|
*/
|
||||||
@Post("/authz", { description: "sys:auth:role:edit", summary: "角色授权" })
|
@Post("/authz", { description: "sys:auth:role:edit" })
|
||||||
async authz(@Body("roleId") roleId, @Body("permissionIds") permissionIds) {
|
async authz(@Body("roleId") roleId, @Body("permissionIds") permissionIds) {
|
||||||
await this.service.authz(roleId, permissionIds);
|
await this.service.authz(roleId, permissionIds);
|
||||||
await this.auditLog({ content: `为角色(ID:${roleId})进行了授权` });
|
|
||||||
return this.ok(null);
|
return this.ok(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import { PermissionService } from "../../../modules/sys/authority/service/permis
|
|||||||
import { Constants } from "@certd/lib-server";
|
import { Constants } from "@certd/lib-server";
|
||||||
import { In } from "typeorm";
|
import { In } from "typeorm";
|
||||||
import { LoginService } from "../../../modules/login/service/login-service.js";
|
import { LoginService } from "../../../modules/login/service/login-service.js";
|
||||||
import { AuditType } from "../../../modules/sys/enterprise/service/audit-constants.js";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 系统用户
|
* 系统用户
|
||||||
@@ -25,10 +24,6 @@ export class UserController extends CrudController<UserService> {
|
|||||||
@Inject()
|
@Inject()
|
||||||
loginService: LoginService;
|
loginService: LoginService;
|
||||||
|
|
||||||
getAuditType(): string {
|
|
||||||
return AuditType.user.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
getService() {
|
getService() {
|
||||||
return this.service;
|
return this.service;
|
||||||
}
|
}
|
||||||
@@ -97,31 +92,23 @@ export class UserController extends CrudController<UserService> {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/add", { description: "sys:auth:user:add", summary: "新增用户" })
|
@Post("/add", { description: "sys:auth:user:add" })
|
||||||
async add(
|
async add(
|
||||||
@Body(ALL)
|
@Body(ALL)
|
||||||
bean
|
bean
|
||||||
) {
|
) {
|
||||||
const res = await super.add(bean);
|
return await super.add(bean);
|
||||||
await this.auditLog({
|
|
||||||
content: `新增了用户「${bean.username}」(ID:${res.data})`,
|
|
||||||
});
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/update", { description: "sys:auth:user:edit", summary: "修改用户" })
|
@Post("/update", { description: "sys:auth:user:edit" })
|
||||||
async update(
|
async update(
|
||||||
@Body(ALL)
|
@Body(ALL)
|
||||||
bean
|
bean
|
||||||
) {
|
) {
|
||||||
const res = await super.update(bean);
|
return await super.update(bean);
|
||||||
await this.auditLog({
|
|
||||||
content: `修改了用户「${bean.username}」(ID:${bean.id})`,
|
|
||||||
});
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/delete", { description: "sys:auth:user:remove", summary: "删除用户" })
|
@Post("/delete", { description: "sys:auth:user:remove" })
|
||||||
async delete(
|
async delete(
|
||||||
@Query("id")
|
@Query("id")
|
||||||
id: number
|
id: number
|
||||||
@@ -132,24 +119,19 @@ export class UserController extends CrudController<UserService> {
|
|||||||
if (id === 3) {
|
if (id === 3) {
|
||||||
throw new Error("不能删除默认的普通用户角色");
|
throw new Error("不能删除默认的普通用户角色");
|
||||||
}
|
}
|
||||||
const res = await super.delete(id);
|
return await super.delete(id);
|
||||||
await this.auditLog({
|
|
||||||
content: `删除了用户(ID:${id})`,
|
|
||||||
});
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 解除登录锁定
|
* 解除登录锁定
|
||||||
*/
|
*/
|
||||||
@Post("/unlockBlock", { description: "sys:auth:user:edit", summary: "解锁登录锁定" })
|
@Post("/unlockBlock", { description: "sys:auth:user:edit" })
|
||||||
public async unlockBlock(@Body("id") id: number) {
|
public async unlockBlock(@Body("id") id: number) {
|
||||||
const info = await this.service.info(id, ["password"]);
|
const info = await this.service.info(id, ["password"]);
|
||||||
this.loginService.clearCacheOnSuccess(info.username);
|
this.loginService.clearCacheOnSuccess(info.username);
|
||||||
if (info.mobile) {
|
if (info.mobile) {
|
||||||
this.loginService.clearCacheOnSuccess(info.mobile);
|
this.loginService.clearCacheOnSuccess(info.mobile);
|
||||||
}
|
}
|
||||||
await this.auditLog({ content: `解锁了用户登录锁定(ID:${id})` });
|
|
||||||
return this.ok(info);
|
return this.ok(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { ALL, Body, Controller, Inject, Post, Provide, Query } from "@midwayjs/c
|
|||||||
import { CrudController } from "@certd/lib-server";
|
import { CrudController } from "@certd/lib-server";
|
||||||
import { merge } from "lodash-es";
|
import { merge } from "lodash-es";
|
||||||
import { CnameProviderService } from "../../../modules/cname/service/cname-provider-service.js";
|
import { CnameProviderService } from "../../../modules/cname/service/cname-provider-service.js";
|
||||||
import { AuditType } from "../../../modules/sys/enterprise/service/audit-constants.js";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 授权
|
* 授权
|
||||||
@@ -17,10 +16,6 @@ export class CnameRecordController extends CrudController<CnameProviderService>
|
|||||||
return this.service;
|
return this.service;
|
||||||
}
|
}
|
||||||
|
|
||||||
getAuditType(): string {
|
|
||||||
return AuditType.cname.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post("/page", { description: "sys:settings:view" })
|
@Post("/page", { description: "sys:settings:view" })
|
||||||
async page(@Body(ALL) body: any) {
|
async page(@Body(ALL) body: any) {
|
||||||
body.query = body.query ?? {};
|
body.query = body.query ?? {};
|
||||||
@@ -32,7 +27,7 @@ export class CnameRecordController extends CrudController<CnameProviderService>
|
|||||||
return super.list(body);
|
return super.list(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/add", { description: "sys:settings:edit", summary: "添加CNAME服务" })
|
@Post("/add", { description: "sys:settings:edit" })
|
||||||
async add(@Body(ALL) bean: any) {
|
async add(@Body(ALL) bean: any) {
|
||||||
const def: any = {
|
const def: any = {
|
||||||
isDefault: false,
|
isDefault: false,
|
||||||
@@ -40,17 +35,13 @@ export class CnameRecordController extends CrudController<CnameProviderService>
|
|||||||
};
|
};
|
||||||
merge(bean, def);
|
merge(bean, def);
|
||||||
bean.userId = this.getUserId();
|
bean.userId = this.getUserId();
|
||||||
const res = await super.add(bean);
|
return super.add(bean);
|
||||||
await this.auditLog({ content: `添加了CNAME服务(ID:${res.data})` });
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/update", { description: "sys:settings:edit", summary: "更新CNAME服务" })
|
@Post("/update", { description: "sys:settings:edit" })
|
||||||
async update(@Body(ALL) bean: any) {
|
async update(@Body(ALL) bean: any) {
|
||||||
bean.userId = this.getUserId();
|
bean.userId = this.getUserId();
|
||||||
const res = await super.update(bean);
|
return super.update(bean);
|
||||||
await this.auditLog({ content: `更新了CNAME服务(ID:${bean.id})` });
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/info", { description: "sys:settings:view" })
|
@Post("/info", { description: "sys:settings:view" })
|
||||||
@@ -58,31 +49,26 @@ export class CnameRecordController extends CrudController<CnameProviderService>
|
|||||||
return super.info(id);
|
return super.info(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/delete", { description: "sys:settings:edit", summary: "删除CNAME服务" })
|
@Post("/delete", { description: "sys:settings:edit" })
|
||||||
async delete(@Query("id") id: number) {
|
async delete(@Query("id") id: number) {
|
||||||
const res = await super.delete(id);
|
return super.delete(id);
|
||||||
await this.auditLog({ content: `删除了CNAME服务(ID:${id})` });
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/deleteByIds", { description: "sys:settings:edit", summary: "批量删除CNAME服务" })
|
@Post("/deleteByIds", { description: "sys:settings:edit" })
|
||||||
async deleteByIds(@Body("ids") ids: number[]) {
|
async deleteByIds(@Body("ids") ids: number[]) {
|
||||||
const res = await this.service.delete(ids);
|
const res = await this.service.delete(ids);
|
||||||
await this.auditLog({ content: `批量删除了${ids.length}条CNAME服务` });
|
|
||||||
return this.ok(res);
|
return this.ok(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/setDefault", { description: "sys:settings:edit", summary: "设置默认CNAME服务" })
|
@Post("/setDefault", { description: "sys:settings:edit" })
|
||||||
async setDefault(@Body("id") id: number) {
|
async setDefault(@Body("id") id: number) {
|
||||||
await this.service.setDefault(id);
|
await this.service.setDefault(id);
|
||||||
await this.auditLog({ content: `设置了默认CNAME服务(ID:${id})` });
|
|
||||||
return this.ok();
|
return this.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/setDisabled", { description: "sys:settings:edit", summary: "禁用/启用CNAME服务" })
|
@Post("/setDisabled", { description: "sys:settings:edit" })
|
||||||
async setDisabled(@Body("id") id: number, @Body("disabled") disabled: boolean) {
|
async setDisabled(@Body("id") id: number, @Body("disabled") disabled: boolean) {
|
||||||
await this.service.setDisabled(id, disabled);
|
await this.service.setDisabled(id, disabled);
|
||||||
await this.auditLog({ content: `${disabled ? "禁用" : "启用"}了CNAME服务(ID:${id})` });
|
|
||||||
return this.ok();
|
return this.ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import { ALL, Body, Controller, Inject, Post, Provide, Query } from "@midwayjs/c
|
|||||||
import { ProjectService } from "../../../modules/sys/enterprise/service/project-service.js";
|
import { ProjectService } from "../../../modules/sys/enterprise/service/project-service.js";
|
||||||
import { ProjectEntity } from "../../../modules/sys/enterprise/entity/project.js";
|
import { ProjectEntity } from "../../../modules/sys/enterprise/entity/project.js";
|
||||||
import { merge } from "lodash-es";
|
import { merge } from "lodash-es";
|
||||||
import { AuditType } from "../../../modules/sys/enterprise/service/audit-constants.js";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
@@ -16,26 +15,22 @@ export class SysProjectController extends CrudController<ProjectEntity> {
|
|||||||
@Inject()
|
@Inject()
|
||||||
sysSettingsService: SysSettingsService;
|
sysSettingsService: SysSettingsService;
|
||||||
|
|
||||||
getAuditType(): string {
|
|
||||||
return AuditType.project.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
getService<T>() {
|
getService<T>() {
|
||||||
return this.service;
|
return this.service;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/page", { description: "sys:settings:view", summary: "查询项目分页列表" })
|
@Post("/page", { description: "sys:settings:view" })
|
||||||
async page(@Body(ALL) body: any) {
|
async page(@Body(ALL) body: any) {
|
||||||
body.query = body.query ?? {};
|
body.query = body.query ?? {};
|
||||||
return await super.page(body);
|
return await super.page(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/list", { description: "sys:settings:view", summary: "查询项目列表" })
|
@Post("/list", { description: "sys:settings:view" })
|
||||||
async list(@Body(ALL) body: any) {
|
async list(@Body(ALL) body: any) {
|
||||||
return super.list(body);
|
return super.list(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/add", { description: "sys:settings:edit", summary: "添加项目" })
|
@Post("/add", { description: "sys:settings:edit" })
|
||||||
async add(@Body(ALL) bean: any) {
|
async add(@Body(ALL) bean: any) {
|
||||||
const def: any = {
|
const def: any = {
|
||||||
isDefault: false,
|
isDefault: false,
|
||||||
@@ -43,57 +38,37 @@ export class SysProjectController extends CrudController<ProjectEntity> {
|
|||||||
};
|
};
|
||||||
merge(bean, def);
|
merge(bean, def);
|
||||||
bean.userId = this.getUserId();
|
bean.userId = this.getUserId();
|
||||||
const res = await super.add({
|
return super.add({
|
||||||
...bean,
|
...bean,
|
||||||
userId: -1, //企业用户id固定为-1
|
userId: -1, //企业用户id固定为-1
|
||||||
adminId: bean.userId,
|
adminId: bean.userId,
|
||||||
});
|
});
|
||||||
await this.auditLog({
|
|
||||||
content: `新增了项目「${bean.name}」(ID:${res.data})`,
|
|
||||||
});
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/update", { description: "sys:settings:edit", summary: "更新项目" })
|
@Post("/update", { description: "sys:settings:edit" })
|
||||||
async update(@Body(ALL) bean: any) {
|
async update(@Body(ALL) bean: any) {
|
||||||
bean.userId = this.getUserId();
|
bean.userId = this.getUserId();
|
||||||
const res = await super.update(bean);
|
return super.update(bean);
|
||||||
await this.auditLog({
|
|
||||||
content: `修改了项目「${bean.name}」(ID:${bean.id})`,
|
|
||||||
});
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/info", { description: "sys:settings:view", summary: "查询项目详情" })
|
@Post("/info", { description: "sys:settings:view" })
|
||||||
async info(@Query("id") id: number) {
|
async info(@Query("id") id: number) {
|
||||||
return super.info(id);
|
return super.info(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/delete", { description: "sys:settings:edit", summary: "删除项目" })
|
@Post("/delete", { description: "sys:settings:edit" })
|
||||||
async delete(@Query("id") id: number) {
|
async delete(@Query("id") id: number) {
|
||||||
const res = await super.delete(id);
|
return super.delete(id);
|
||||||
await this.auditLog({
|
|
||||||
content: `删除了项目(ID:${id})`,
|
|
||||||
});
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/deleteByIds", { description: "sys:settings:edit", summary: "批量删除项目" })
|
@Post("/deleteByIds", { description: "sys:settings:edit" })
|
||||||
async deleteByIds(@Body("ids") ids: number[]) {
|
async deleteByIds(@Body("ids") ids: number[]) {
|
||||||
const res = await this.service.delete(ids);
|
const res = await this.service.delete(ids);
|
||||||
await this.auditLog({
|
|
||||||
content: `批量删除了${ids.length}个项目`,
|
|
||||||
});
|
|
||||||
return this.ok(res);
|
return this.ok(res);
|
||||||
}
|
}
|
||||||
@Post("/setDisabled", { description: "sys:settings:edit", summary: "禁用/启用项目" })
|
@Post("/setDisabled", { description: "sys:settings:edit" })
|
||||||
async setDisabled(@Body("id") id: number, @Body("disabled") disabled: boolean) {
|
async setDisabled(@Body("id") id: number, @Body("disabled") disabled: boolean) {
|
||||||
await this.service.setDisabled(id, disabled);
|
await this.service.setDisabled(id, disabled);
|
||||||
const project = await this.service.info(id);
|
|
||||||
const actionText = disabled ? "禁用了" : "启用了";
|
|
||||||
await this.auditLog({
|
|
||||||
content: `${actionText}项目「${project.name}」(ID:${id})`,
|
|
||||||
});
|
|
||||||
return this.ok();
|
return this.ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-20
@@ -4,7 +4,6 @@ import { ProjectMemberEntity } from "../../../modules/sys/enterprise/entity/proj
|
|||||||
import { ProjectMemberService } from "../../../modules/sys/enterprise/service/project-member-service.js";
|
import { ProjectMemberService } from "../../../modules/sys/enterprise/service/project-member-service.js";
|
||||||
import { merge } from "lodash-es";
|
import { merge } from "lodash-es";
|
||||||
import { ProjectService } from "../../../modules/sys/enterprise/service/project-service.js";
|
import { ProjectService } from "../../../modules/sys/enterprise/service/project-service.js";
|
||||||
import { AuditType } from "../../../modules/sys/enterprise/service/audit-constants.js";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
@@ -16,6 +15,7 @@ export class SysProjectMemberController extends CrudController<ProjectMemberEnti
|
|||||||
|
|
||||||
@Inject()
|
@Inject()
|
||||||
sysSettingsService: SysSettingsService;
|
sysSettingsService: SysSettingsService;
|
||||||
|
|
||||||
@Inject()
|
@Inject()
|
||||||
projectService: ProjectService;
|
projectService: ProjectService;
|
||||||
|
|
||||||
@@ -23,22 +23,18 @@ export class SysProjectMemberController extends CrudController<ProjectMemberEnti
|
|||||||
return this.service;
|
return this.service;
|
||||||
}
|
}
|
||||||
|
|
||||||
getAuditType(): string {
|
@Post("/page", { description: "sys:settings:view" })
|
||||||
return AuditType.enterprise.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post("/page", { description: "sys:settings:view", summary: "查询项目成员分页列表" })
|
|
||||||
async page(@Body(ALL) body: any) {
|
async page(@Body(ALL) body: any) {
|
||||||
body.query = body.query ?? {};
|
body.query = body.query ?? {};
|
||||||
return await super.page(body);
|
return await super.page(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/list", { description: "sys:settings:view", summary: "查询项目成员列表" })
|
@Post("/list", { description: "sys:settings:view" })
|
||||||
async list(@Body(ALL) body: any) {
|
async list(@Body(ALL) body: any) {
|
||||||
return super.list(body);
|
return super.list(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/add", { description: "sys:settings:edit", summary: "添加项目成员" })
|
@Post("/add", { description: "sys:settings:edit" })
|
||||||
async add(@Body(ALL) bean: any) {
|
async add(@Body(ALL) bean: any) {
|
||||||
const def: any = {
|
const def: any = {
|
||||||
isDefault: false,
|
isDefault: false,
|
||||||
@@ -51,12 +47,10 @@ export class SysProjectMemberController extends CrudController<ProjectMemberEnti
|
|||||||
projectId: bean.projectId,
|
projectId: bean.projectId,
|
||||||
});
|
});
|
||||||
|
|
||||||
const res = await super.add(bean);
|
return super.add(bean);
|
||||||
await this.auditLog({ content: `添加了项目成员(ID:${res.data})` });
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/update", { description: "sys:settings:edit", summary: "更新项目成员" })
|
@Post("/update", { description: "sys:settings:edit" })
|
||||||
async update(@Body(ALL) bean: any) {
|
async update(@Body(ALL) bean: any) {
|
||||||
if (!bean.id) {
|
if (!bean.id) {
|
||||||
throw new Error("id is required");
|
throw new Error("id is required");
|
||||||
@@ -71,11 +65,10 @@ export class SysProjectMemberController extends CrudController<ProjectMemberEnti
|
|||||||
permission: bean.permission,
|
permission: bean.permission,
|
||||||
status: bean.status,
|
status: bean.status,
|
||||||
});
|
});
|
||||||
await this.auditLog({ content: `更新了项目成员(ID:${bean.id})` });
|
|
||||||
return this.ok(res);
|
return this.ok(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/info", { description: "sys:settings:view", summary: "查询项目成员详情" })
|
@Post("/info", { description: "sys:settings:view" })
|
||||||
async info(@Query("id") id: number) {
|
async info(@Query("id") id: number) {
|
||||||
if (!id) {
|
if (!id) {
|
||||||
throw new Error("id is required");
|
throw new Error("id is required");
|
||||||
@@ -88,7 +81,7 @@ export class SysProjectMemberController extends CrudController<ProjectMemberEnti
|
|||||||
return super.info(id);
|
return super.info(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/delete", { description: "sys:settings:edit", summary: "删除项目成员" })
|
@Post("/delete", { description: "sys:settings:edit" })
|
||||||
async delete(@Query("id") id: number) {
|
async delete(@Query("id") id: number) {
|
||||||
if (!id) {
|
if (!id) {
|
||||||
throw new Error("id is required");
|
throw new Error("id is required");
|
||||||
@@ -98,12 +91,10 @@ export class SysProjectMemberController extends CrudController<ProjectMemberEnti
|
|||||||
userId: this.getUserId(),
|
userId: this.getUserId(),
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
});
|
});
|
||||||
const res = await super.delete(id);
|
return super.delete(id);
|
||||||
await this.auditLog({ content: `删除了项目成员(ID:${id})` });
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/deleteByIds", { description: "sys:settings:edit", summary: "批量删除项目成员" })
|
@Post("/deleteByIds", { description: "sys:settings:edit" })
|
||||||
async deleteByIds(@Body("ids") ids: number[]) {
|
async deleteByIds(@Body("ids") ids: number[]) {
|
||||||
for (const id of ids) {
|
for (const id of ids) {
|
||||||
if (!id) {
|
if (!id) {
|
||||||
@@ -117,7 +108,6 @@ export class SysProjectMemberController extends CrudController<ProjectMemberEnti
|
|||||||
await this.service.delete(id as any);
|
await this.service.delete(id as any);
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.auditLog({ content: `批量删除了${ids.length}个项目成员` });
|
|
||||||
return this.ok({});
|
return this.ok({});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { ALL, Body, Controller, Inject, Post, Provide, Query } from "@midwayjs/c
|
|||||||
import { CrudController } from "@certd/lib-server";
|
import { CrudController } from "@certd/lib-server";
|
||||||
import { SiteInfoService } from "../../../modules/monitor/service/site-info-service.js";
|
import { SiteInfoService } from "../../../modules/monitor/service/site-info-service.js";
|
||||||
import { ApiTags } from "@midwayjs/swagger";
|
import { ApiTags } from "@midwayjs/swagger";
|
||||||
import { AuditType } from "../../../modules/sys/enterprise/service/audit-constants.js";
|
|
||||||
|
|
||||||
@Provide()
|
@Provide()
|
||||||
@Controller("/api/sys/monitor/site")
|
@Controller("/api/sys/monitor/site")
|
||||||
@@ -15,10 +14,6 @@ export class SysSiteInfoController extends CrudController<SiteInfoService> {
|
|||||||
return this.service;
|
return this.service;
|
||||||
}
|
}
|
||||||
|
|
||||||
getAuditType(): string {
|
|
||||||
return AuditType.monitor.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post("/page", { description: "sys:settings:view", summary: "管理员查询站点监控分页列表" })
|
@Post("/page", { description: "sys:settings:view", summary: "管理员查询站点监控分页列表" })
|
||||||
async page(@Body(ALL) body: any) {
|
async page(@Body(ALL) body: any) {
|
||||||
body.query = body.query ?? {};
|
body.query = body.query ?? {};
|
||||||
@@ -49,16 +44,12 @@ export class SysSiteInfoController extends CrudController<SiteInfoService> {
|
|||||||
|
|
||||||
@Post("/delete", { description: "sys:settings:edit", summary: "管理员删除站点监控" })
|
@Post("/delete", { description: "sys:settings:edit", summary: "管理员删除站点监控" })
|
||||||
async delete(@Query("id") id: number) {
|
async delete(@Query("id") id: number) {
|
||||||
await super.delete(id);
|
return await super.delete(id);
|
||||||
await this.auditLog({ content: `管理员删除了站点监控(ID:${id})` });
|
|
||||||
return this.ok();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/batchDelete", { description: "sys:settings:edit", summary: "管理员批量删除站点监控" })
|
@Post("/batchDelete", { description: "sys:settings:edit", summary: "管理员批量删除站点监控" })
|
||||||
async batchDelete(@Body("ids") ids: number[]) {
|
async batchDelete(@Body("ids") ids: number[]) {
|
||||||
const count = ids.length;
|
|
||||||
await this.service.delete(ids);
|
await this.service.delete(ids);
|
||||||
await this.auditLog({ content: `管理员批量删除了${count}条站点监控` });
|
|
||||||
return this.ok();
|
return this.ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import { CrudController } from "@certd/lib-server";
|
|||||||
import { ApiTags } from "@midwayjs/swagger";
|
import { ApiTags } from "@midwayjs/swagger";
|
||||||
import { PipelineService } from "../../../modules/pipeline/service/pipeline-service.js";
|
import { PipelineService } from "../../../modules/pipeline/service/pipeline-service.js";
|
||||||
import { checkPlus } from "@certd/plus-core";
|
import { checkPlus } from "@certd/plus-core";
|
||||||
import { AuditType } from "../../../modules/sys/enterprise/service/audit-constants.js";
|
|
||||||
|
|
||||||
@Provide()
|
@Provide()
|
||||||
@Controller("/api/sys/pipeline")
|
@Controller("/api/sys/pipeline")
|
||||||
@@ -16,10 +15,6 @@ export class SysPipelineController extends CrudController<PipelineService> {
|
|||||||
return this.service;
|
return this.service;
|
||||||
}
|
}
|
||||||
|
|
||||||
getAuditType(): string {
|
|
||||||
return AuditType.pipeline.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post("/page", { description: "sys:settings:view", summary: "管理员查询用户流水线分页列表" })
|
@Post("/page", { description: "sys:settings:view", summary: "管理员查询用户流水线分页列表" })
|
||||||
async page(@Body(ALL) body: any) {
|
async page(@Body(ALL) body: any) {
|
||||||
body.query = body.query ?? {};
|
body.query = body.query ?? {};
|
||||||
@@ -46,16 +41,13 @@ export class SysPipelineController extends CrudController<PipelineService> {
|
|||||||
@Post("/delete", { description: "sys:settings:edit", summary: "管理员删除用户流水线" })
|
@Post("/delete", { description: "sys:settings:edit", summary: "管理员删除用户流水线" })
|
||||||
async delete(@Query("id") id: number) {
|
async delete(@Query("id") id: number) {
|
||||||
await this.service.delete(id);
|
await this.service.delete(id);
|
||||||
await this.auditLog({ content: `管理员删除了用户流水线(ID:${id})` });
|
|
||||||
return this.ok();
|
return this.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/batchDelete", { description: "sys:settings:edit", summary: "管理员批量删除用户流水线" })
|
@Post("/batchDelete", { description: "sys:settings:edit", summary: "管理员批量删除用户流水线" })
|
||||||
async batchDelete(@Body("ids") ids: number[]) {
|
async batchDelete(@Body("ids") ids: number[]) {
|
||||||
checkPlus();
|
checkPlus();
|
||||||
const count = ids.length;
|
|
||||||
await this.service.batchDelete(ids);
|
await this.service.batchDelete(ids);
|
||||||
await this.auditLog({ content: `管理员批量删除了${count}条用户流水线` });
|
|
||||||
return this.ok();
|
return this.ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import { merge } from "lodash-es";
|
|||||||
import { CrudController } from "@certd/lib-server";
|
import { CrudController } from "@certd/lib-server";
|
||||||
import { PluginImportReq, PluginService } from "../../../modules/plugin/service/plugin-service.js";
|
import { PluginImportReq, PluginService } from "../../../modules/plugin/service/plugin-service.js";
|
||||||
import { CommPluginConfig, PluginConfig, PluginConfigService } from "../../../modules/plugin/service/plugin-config-service.js";
|
import { CommPluginConfig, PluginConfig, PluginConfigService } from "../../../modules/plugin/service/plugin-config-service.js";
|
||||||
import { AuditType } from "../../../modules/sys/enterprise/service/audit-constants.js";
|
|
||||||
/**
|
/**
|
||||||
* 插件
|
* 插件
|
||||||
*/
|
*/
|
||||||
@@ -20,10 +19,6 @@ export class PluginController extends CrudController<PluginService> {
|
|||||||
return this.service;
|
return this.service;
|
||||||
}
|
}
|
||||||
|
|
||||||
getAuditType(): string {
|
|
||||||
return AuditType.plugin.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post("/page", { description: "sys:settings:view" })
|
@Post("/page", { description: "sys:settings:view" })
|
||||||
async page(@Body(ALL) body: any) {
|
async page(@Body(ALL) body: any) {
|
||||||
body.query = body.query ?? {};
|
body.query = body.query ?? {};
|
||||||
@@ -35,22 +30,19 @@ export class PluginController extends CrudController<PluginService> {
|
|||||||
return super.list(body);
|
return super.list(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/add", { description: "sys:settings:edit", summary: "添加插件" })
|
@Post("/add", { description: "sys:settings:edit" })
|
||||||
async add(@Body(ALL) bean: any) {
|
async add(@Body(ALL) bean: any) {
|
||||||
const def: any = {
|
const def: any = {
|
||||||
isDefault: false,
|
isDefault: false,
|
||||||
disabled: false,
|
disabled: false,
|
||||||
};
|
};
|
||||||
merge(bean, def);
|
merge(bean, def);
|
||||||
const res = await super.add(bean);
|
return super.add(bean);
|
||||||
await this.auditLog({ content: `新增了插件「${bean.name}」(ID:${res.data}, 类型:${bean.type})` });
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/update", { description: "sys:settings:edit", summary: "更新插件" })
|
@Post("/update", { description: "sys:settings:edit" })
|
||||||
async update(@Body(ALL) bean: any) {
|
async update(@Body(ALL) bean: any) {
|
||||||
const res = await super.update(bean);
|
const res = await super.update(bean);
|
||||||
await this.auditLog({ content: `修改了插件「${bean.name}」(ID:${bean.id})` });
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,25 +51,21 @@ export class PluginController extends CrudController<PluginService> {
|
|||||||
return super.info(id);
|
return super.info(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/delete", { description: "sys:settings:edit", summary: "删除插件" })
|
@Post("/delete", { description: "sys:settings:edit" })
|
||||||
async delete(@Query("id") id: number) {
|
async delete(@Query("id") id: number) {
|
||||||
const res = await this.service.deleteByIds([id]);
|
const res = await this.service.deleteByIds([id]);
|
||||||
await this.auditLog({ content: `删除了插件(ID:${id})` });
|
|
||||||
return this.ok(res);
|
return this.ok(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/deleteByIds", { description: "sys:settings:edit", summary: "批量删除插件" })
|
@Post("/deleteByIds", { description: "sys:settings:edit" })
|
||||||
async deleteByIds(@Body("ids") ids: number[]) {
|
async deleteByIds(@Body("ids") ids: number[]) {
|
||||||
const res = await this.service.deleteByIds(ids);
|
const res = await this.service.deleteByIds(ids);
|
||||||
await this.auditLog({ content: `批量删除了${ids.length}条插件` });
|
|
||||||
return this.ok(res);
|
return this.ok(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/setDisabled", { description: "sys:settings:edit", summary: "禁用/启用插件" })
|
@Post("/setDisabled", { description: "sys:settings:edit" })
|
||||||
async setDisabled(@Body(ALL) body: { id: number; name: string; type: string; disabled: boolean }) {
|
async setDisabled(@Body(ALL) body: { id: number; name: string; type: string; disabled: boolean }) {
|
||||||
await this.service.setDisabled(body);
|
await this.service.setDisabled(body);
|
||||||
const { id, disabled } = body;
|
|
||||||
await this.auditLog({ content: `${disabled ? "禁用" : "启用"}了插件(ID:${id})` });
|
|
||||||
return this.ok();
|
return this.ok();
|
||||||
}
|
}
|
||||||
@Post("/getCommPluginConfigs", { description: "sys:settings:view" })
|
@Post("/getCommPluginConfigs", { description: "sys:settings:view" })
|
||||||
@@ -86,10 +74,9 @@ export class PluginController extends CrudController<PluginService> {
|
|||||||
return this.ok(res);
|
return this.ok(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/saveCommPluginConfigs", { description: "sys:settings:edit", summary: "保存公共插件配置" })
|
@Post("/saveCommPluginConfigs", { description: "sys:settings:edit" })
|
||||||
async saveCommPluginConfigs(@Body(ALL) body: CommPluginConfig) {
|
async saveCommPluginConfigs(@Body(ALL) body: CommPluginConfig) {
|
||||||
const res = await this.pluginConfigService.saveCommPluginConfig(body);
|
const res = await this.pluginConfigService.saveCommPluginConfig(body);
|
||||||
await this.auditLog({ content: "保存了公共插件配置" });
|
|
||||||
return this.ok(res);
|
return this.ok(res);
|
||||||
}
|
}
|
||||||
@Post("/getPluginByName", { description: "sys:settings:view" })
|
@Post("/getPluginByName", { description: "sys:settings:view" })
|
||||||
@@ -101,21 +88,19 @@ export class PluginController extends CrudController<PluginService> {
|
|||||||
return this.ok(res);
|
return this.ok(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/saveSetting", { description: "sys:settings:edit", summary: "保存插件设置" })
|
@Post("/saveSetting", { description: "sys:settings:edit" })
|
||||||
async saveSetting(@Body(ALL) body: PluginConfig) {
|
async saveSetting(@Body(ALL) body: PluginConfig) {
|
||||||
const res = await this.pluginConfigService.savePluginConfig(body);
|
const res = await this.pluginConfigService.savePluginConfig(body);
|
||||||
await this.auditLog({ content: "保存了插件设置" });
|
|
||||||
return this.ok(res);
|
return this.ok(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/import", { description: "sys:settings:edit", summary: "导入插件" })
|
@Post("/import", { description: "sys:settings:edit" })
|
||||||
async import(@Body(ALL) body: PluginImportReq) {
|
async import(@Body(ALL) body: PluginImportReq) {
|
||||||
const res = await this.service.importPlugin(body);
|
const res = await this.service.importPlugin(body);
|
||||||
await this.auditLog({ content: "导入了插件配置" });
|
|
||||||
return this.ok(res);
|
return this.ok(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/export", { description: "sys:settings:edit", summary: "导出插件" })
|
@Post("/export", { description: "sys:settings:edit" })
|
||||||
async export(@Body("id") id: number) {
|
async export(@Body("id") id: number) {
|
||||||
const res = await this.service.exportPlugin(id);
|
const res = await this.service.exportPlugin(id);
|
||||||
return this.ok(res);
|
return this.ok(res);
|
||||||
|
|||||||
+1
-10
@@ -2,7 +2,6 @@ import { ALL, Body, Controller, Inject, Post, Provide } from "@midwayjs/core";
|
|||||||
import { BaseController, SysSafeSetting } from "@certd/lib-server";
|
import { BaseController, SysSafeSetting } from "@certd/lib-server";
|
||||||
import { cloneDeep } from "lodash-es";
|
import { cloneDeep } from "lodash-es";
|
||||||
import { SafeService } from "../../../modules/sys/settings/safe-service.js";
|
import { SafeService } from "../../../modules/sys/settings/safe-service.js";
|
||||||
import { AuditType } from "../../../modules/sys/enterprise/service/audit-constants.js";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
@@ -12,10 +11,6 @@ export class SysSettingsController extends BaseController {
|
|||||||
@Inject()
|
@Inject()
|
||||||
safeService: SafeService;
|
safeService: SafeService;
|
||||||
|
|
||||||
getAuditType(): string {
|
|
||||||
return AuditType.settings.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post("/get", { description: "sys:settings:view" })
|
@Post("/get", { description: "sys:settings:view" })
|
||||||
async safeGet() {
|
async safeGet() {
|
||||||
const res = await this.safeService.getSafeSetting();
|
const res = await this.safeService.getSafeSetting();
|
||||||
@@ -27,19 +22,15 @@ export class SysSettingsController extends BaseController {
|
|||||||
@Post("/save", { description: "sys:settings:edit" })
|
@Post("/save", { description: "sys:settings:edit" })
|
||||||
async safeSave(@Body(ALL) body: any) {
|
async safeSave(@Body(ALL) body: any) {
|
||||||
await this.safeService.saveSafeSetting(body);
|
await this.safeService.saveSafeSetting(body);
|
||||||
await this.auditLog({
|
|
||||||
content: "修改了安全设置",
|
|
||||||
});
|
|
||||||
return this.ok({});
|
return this.ok({});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 立即隐藏
|
* 立即隐藏
|
||||||
*/
|
*/
|
||||||
@Post("/hidden", { description: "sys:settings:edit", summary: "立刻隐藏系统" })
|
@Post("/hidden", { description: "sys:settings:edit" })
|
||||||
async hiddenImmediate() {
|
async hiddenImmediate() {
|
||||||
await this.safeService.hiddenImmediately();
|
await this.safeService.hiddenImmediately();
|
||||||
await this.auditLog({ content: "立刻隐藏了系统" });
|
|
||||||
return this.ok({});
|
return this.ok({});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { getRuntimeDepsService } from "@certd/pipeline";
|
||||||
import { ALL, Body, Controller, Inject, Post, Provide, Query, RequestIP } from "@midwayjs/core";
|
import { ALL, Body, Controller, Inject, Post, Provide, Query, RequestIP } from "@midwayjs/core";
|
||||||
import { addonRegistry, AddonService, CrudController, SysPrivateSettings, SysPublicSettings, SysSafeSetting, SysSettingsEntity, SysSettingsService } from "@certd/lib-server";
|
import { addonRegistry, AddonService, CrudController, SysPrivateSettings, SysPublicSettings, SysSafeSetting, SysSettingsEntity, SysSettingsService } from "@certd/lib-server";
|
||||||
import { cloneDeep, merge } from "lodash-es";
|
import { cloneDeep, merge } from "lodash-es";
|
||||||
@@ -7,8 +8,6 @@ import { getEmailSettings } from "../../../modules/sys/settings/fix.js";
|
|||||||
import { http, logger, utils } from "@certd/basic";
|
import { http, logger, utils } from "@certd/basic";
|
||||||
import { CodeService } from "../../../modules/basic/service/code-service.js";
|
import { CodeService } from "../../../modules/basic/service/code-service.js";
|
||||||
import { SmsServiceFactory } from "../../../modules/basic/sms/factory.js";
|
import { SmsServiceFactory } from "../../../modules/basic/sms/factory.js";
|
||||||
import { RuntimeDepsService } from "../../../modules/runtime-deps/runtime-deps-service.js";
|
|
||||||
import { AuditType } from "../../../modules/sys/enterprise/service/audit-constants.js";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
@@ -25,78 +24,62 @@ export class SysSettingsController extends CrudController<SysSettingsService> {
|
|||||||
codeService: CodeService;
|
codeService: CodeService;
|
||||||
@Inject()
|
@Inject()
|
||||||
addonService: AddonService;
|
addonService: AddonService;
|
||||||
@Inject()
|
|
||||||
runtimeDepsService: RuntimeDepsService;
|
|
||||||
|
|
||||||
getService() {
|
getService() {
|
||||||
return this.service;
|
return this.service;
|
||||||
}
|
}
|
||||||
|
|
||||||
getAuditType(): string {
|
@Post("/page", { description: "sys:settings:view" })
|
||||||
return AuditType.settings.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post("/page", { description: "sys:settings:view", summary: "查询系统设置分页列表" })
|
|
||||||
async page(@Body(ALL) body) {
|
async page(@Body(ALL) body) {
|
||||||
return super.page(body);
|
return super.page(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/list", { description: "sys:settings:view", summary: "查询系统设置列表" })
|
@Post("/list", { description: "sys:settings:view" })
|
||||||
async list(@Body(ALL) body) {
|
async list(@Body(ALL) body) {
|
||||||
return super.list(body);
|
return super.list(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/add", { description: "sys:settings:edit", summary: "添加系统设置" })
|
@Post("/add", { description: "sys:settings:edit" })
|
||||||
async add(@Body(ALL) bean) {
|
async add(@Body(ALL) bean) {
|
||||||
const res = await super.add(bean);
|
return super.add(bean);
|
||||||
await this.auditLog({ content: "添加了系统设置" });
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/update", { description: "sys:settings:edit", summary: "更新系统设置" })
|
@Post("/update", { description: "sys:settings:edit" })
|
||||||
async update(@Body(ALL) bean) {
|
async update(@Body(ALL) bean) {
|
||||||
await this.service.checkUserId(bean.id, this.getUserId());
|
await this.service.checkUserId(bean.id, this.getUserId());
|
||||||
const res = await super.update(bean);
|
return super.update(bean);
|
||||||
await this.auditLog({ content: "更新了系统设置" });
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
@Post("/info", { description: "sys:settings:view", summary: "查询系统设置详情" })
|
@Post("/info", { description: "sys:settings:view" })
|
||||||
async info(@Query("id") id: number) {
|
async info(@Query("id") id: number) {
|
||||||
await this.service.checkUserId(id, this.getUserId());
|
await this.service.checkUserId(id, this.getUserId());
|
||||||
return super.info(id);
|
return super.info(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/delete", { description: "sys:settings:edit", summary: "删除系统设置" })
|
@Post("/delete", { description: "sys:settings:edit" })
|
||||||
async delete(@Query("id") id: number) {
|
async delete(@Query("id") id: number) {
|
||||||
await this.service.checkUserId(id, this.getUserId());
|
await this.service.checkUserId(id, this.getUserId());
|
||||||
const res = await super.delete(id);
|
return super.delete(id);
|
||||||
await this.auditLog({ content: "删除了系统设置" });
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/save", { description: "sys:settings:edit", summary: "保存系统设置" })
|
@Post("/save", { description: "sys:settings:edit" })
|
||||||
async save(@Body(ALL) bean: SysSettingsEntity) {
|
async save(@Body(ALL) bean: SysSettingsEntity) {
|
||||||
await this.service.save(bean);
|
await this.service.save(bean);
|
||||||
await this.auditLog({
|
|
||||||
content: "修改了系统设置",
|
|
||||||
});
|
|
||||||
return this.ok({});
|
return this.ok({});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/get", { description: "sys:settings:view", summary: "查询系统设置" })
|
@Post("/get", { description: "sys:settings:view" })
|
||||||
async get(@Query("key") key: string) {
|
async get(@Query("key") key: string) {
|
||||||
const entity = await this.service.getByKey(key);
|
const entity = await this.service.getByKey(key);
|
||||||
return this.ok(entity);
|
return this.ok(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
// savePublicSettings
|
// savePublicSettings
|
||||||
@Post("/getEmailSettings", { description: "sys:settings:view", summary: "查询邮件服务器设置" })
|
@Post("/getEmailSettings", { description: "sys:settings:view" })
|
||||||
async getEmailSettings(@Body(ALL) body) {
|
async getEmailSettings(@Body(ALL) body) {
|
||||||
const conf = await getEmailSettings(this.service, this.userSettingsService);
|
const conf = await getEmailSettings(this.service, this.userSettingsService);
|
||||||
return this.ok(conf);
|
return this.ok(conf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/getEmailTemplates", { description: "sys:settings:view", summary: "查询邮件模板列表" })
|
@Post("/getEmailTemplates", { description: "sys:settings:view" })
|
||||||
async getEmailTemplates(@Body(ALL) body) {
|
async getEmailTemplates(@Body(ALL) body) {
|
||||||
const conf = await getEmailSettings(this.service, this.userSettingsService);
|
const conf = await getEmailSettings(this.service, this.userSettingsService);
|
||||||
const templates = conf.templates || {};
|
const templates = conf.templates || {};
|
||||||
@@ -115,16 +98,15 @@ export class SysSettingsController extends CrudController<SysSettingsService> {
|
|||||||
return this.ok(proviers);
|
return this.ok(proviers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/saveEmailSettings", { description: "sys:settings:edit", summary: "保存邮件服务器设置" })
|
@Post("/saveEmailSettings", { description: "sys:settings:edit" })
|
||||||
async saveEmailSettings(@Body(ALL) body) {
|
async saveEmailSettings(@Body(ALL) body) {
|
||||||
const conf = await getEmailSettings(this.service, this.userSettingsService);
|
const conf = await getEmailSettings(this.service, this.userSettingsService);
|
||||||
merge(conf, body);
|
merge(conf, body);
|
||||||
await this.service.saveSetting(conf);
|
await this.service.saveSetting(conf);
|
||||||
await this.auditLog({ content: "保存了邮件服务器设置" });
|
|
||||||
return this.ok(conf);
|
return this.ok(conf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/getSysSettings", { description: "sys:settings:view", summary: "查询系统配置" })
|
@Post("/getSysSettings", { description: "sys:settings:view" })
|
||||||
async getSysSettings() {
|
async getSysSettings() {
|
||||||
const publicSettings = await this.service.getPublicSettings();
|
const publicSettings = await this.service.getPublicSettings();
|
||||||
let privateSettings = await this.service.getPrivateSettings();
|
let privateSettings = await this.service.getPrivateSettings();
|
||||||
@@ -133,7 +115,7 @@ export class SysSettingsController extends CrudController<SysSettingsService> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// savePublicSettings
|
// savePublicSettings
|
||||||
@Post("/saveSysSettings", { description: "sys:settings:edit", summary: "保存系统设置" })
|
@Post("/saveSysSettings", { description: "sys:settings:edit" })
|
||||||
async saveSysSettings(@Body(ALL) body: { public: SysPublicSettings; private: SysPrivateSettings }) {
|
async saveSysSettings(@Body(ALL) body: { public: SysPublicSettings; private: SysPrivateSettings }) {
|
||||||
const publicSettings = await this.service.getPublicSettings();
|
const publicSettings = await this.service.getPublicSettings();
|
||||||
const privateSettings = await this.service.getPrivateSettings();
|
const privateSettings = await this.service.getPrivateSettings();
|
||||||
@@ -141,18 +123,16 @@ export class SysSettingsController extends CrudController<SysSettingsService> {
|
|||||||
merge(privateSettings, body.private);
|
merge(privateSettings, body.private);
|
||||||
await this.service.savePublicSettings(publicSettings);
|
await this.service.savePublicSettings(publicSettings);
|
||||||
await this.service.savePrivateSettings(privateSettings);
|
await this.service.savePrivateSettings(privateSettings);
|
||||||
await this.auditLog({ content: "保存了系统设置" });
|
|
||||||
return this.ok({});
|
return this.ok({});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/stopOtherUserTimer", { description: "sys:settings:edit", summary: "停止其他用户定时任务" })
|
@Post("/stopOtherUserTimer", { description: "sys:settings:edit" })
|
||||||
async stopOtherUserTimer(@Body(ALL) body) {
|
async stopOtherUserTimer(@Body(ALL) body) {
|
||||||
await this.pipelineService.stopOtherUserPipeline(1);
|
await this.pipelineService.stopOtherUserPipeline(1);
|
||||||
await this.auditLog({ content: "停止了其他用户定时任务" });
|
|
||||||
return this.ok({});
|
return this.ok({});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/testProxy", { description: "sys:settings:edit", summary: "测试代理" })
|
@Post("/testProxy", { description: "sys:settings:edit" })
|
||||||
async testProxy(@Body(ALL) body) {
|
async testProxy(@Body(ALL) body) {
|
||||||
const google = "https://www.google.com/";
|
const google = "https://www.google.com/";
|
||||||
const baidu = "https://www.baidu.com/";
|
const baidu = "https://www.baidu.com/";
|
||||||
@@ -190,19 +170,19 @@ export class SysSettingsController extends CrudController<SysSettingsService> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/testSms", { description: "sys:settings:edit", summary: "测试短信" })
|
@Post("/testSms", { description: "sys:settings:edit" })
|
||||||
async testSms(@Body(ALL) body) {
|
async testSms(@Body(ALL) body) {
|
||||||
await this.codeService.sendSmsCode(body.phoneCode, body.mobile);
|
await this.codeService.sendSmsCode(body.phoneCode, body.mobile);
|
||||||
return this.ok({});
|
return this.ok({});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/getSmsTypeDefine", { description: "sys:settings:view", summary: "查询短信类型定义" })
|
@Post("/getSmsTypeDefine", { description: "sys:settings:view" })
|
||||||
async getSmsTypeDefine(@Body("type") type: string) {
|
async getSmsTypeDefine(@Body("type") type: string) {
|
||||||
const define = await SmsServiceFactory.getDefine(type);
|
const define = await SmsServiceFactory.getDefine(type);
|
||||||
return this.ok(define);
|
return this.ok(define);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/safe/get", { description: "sys:settings:view", summary: "查询安全设置" })
|
@Post("/safe/get", { description: "sys:settings:view" })
|
||||||
async safeGet() {
|
async safeGet() {
|
||||||
const res = await this.service.getSetting<SysSafeSetting>(SysSafeSetting);
|
const res = await this.service.getSetting<SysSafeSetting>(SysSafeSetting);
|
||||||
const clone: SysSafeSetting = cloneDeep(res);
|
const clone: SysSafeSetting = cloneDeep(res);
|
||||||
@@ -210,7 +190,7 @@ export class SysSettingsController extends CrudController<SysSettingsService> {
|
|||||||
return this.ok(clone);
|
return this.ok(clone);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/safe/save", { description: "sys:settings:edit", summary: "保存安全设置" })
|
@Post("/safe/save", { description: "sys:settings:edit" })
|
||||||
async safeSave(@Body(ALL) body: any) {
|
async safeSave(@Body(ALL) body: any) {
|
||||||
if (body.hidden.openPassword) {
|
if (body.hidden.openPassword) {
|
||||||
body.hidden.openPassword = utils.hash.md5(body.hidden.openPassword);
|
body.hidden.openPassword = utils.hash.md5(body.hidden.openPassword);
|
||||||
@@ -222,26 +202,24 @@ export class SysSettingsController extends CrudController<SysSettingsService> {
|
|||||||
throw new Error("首次设置需要填写解锁密码");
|
throw new Error("首次设置需要填写解锁密码");
|
||||||
}
|
}
|
||||||
await this.service.saveSetting(blankSetting);
|
await this.service.saveSetting(blankSetting);
|
||||||
await this.auditLog({ content: "保存了安全设置" });
|
|
||||||
return this.ok({});
|
return this.ok({});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/captchaTest", { description: "sys:settings:edit", summary: "测试验证码" })
|
@Post("/captchaTest", { description: "sys:settings:edit" })
|
||||||
async captchaTest(@Body(ALL) body: any, @RequestIP() remoteIp: string) {
|
async captchaTest(@Body(ALL) body: any, @RequestIP() remoteIp: string) {
|
||||||
await this.codeService.checkCaptcha(body, { remoteIp });
|
await this.codeService.checkCaptcha(body, { remoteIp });
|
||||||
return this.ok({});
|
return this.ok({});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/oauth/providers", { description: "sys:settings:view", summary: "查询OAuth提供商列表" })
|
@Post("/oauth/providers", { description: "sys:settings:view" })
|
||||||
async oauthProviders() {
|
async oauthProviders() {
|
||||||
const list = await addonRegistry.getDefineList("oauth");
|
const list = await addonRegistry.getDefineList("oauth");
|
||||||
return this.ok(list);
|
return this.ok(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/clearRuntimeDeps", { description: "sys:settings:edit", summary: "清除运行时依赖" })
|
@Post("/clearRuntimeDeps", { description: "sys:settings:edit" })
|
||||||
async clearRuntimeDeps() {
|
async clearRuntimeDeps() {
|
||||||
await this.runtimeDepsService.clearRuntimeDeps();
|
await getRuntimeDepsService().clearRuntimeDeps();
|
||||||
await this.auditLog({ content: "清除了运行时依赖" });
|
|
||||||
return this.ok(true);
|
return this.ok(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import { checkPlus } from "@certd/plus-core";
|
|||||||
import { http, logger, utils } from "@certd/basic";
|
import { http, logger, utils } from "@certd/basic";
|
||||||
import { TaskServiceBuilder } from "../../../modules/pipeline/service/getter/task-service-getter.js";
|
import { TaskServiceBuilder } from "../../../modules/pipeline/service/getter/task-service-getter.js";
|
||||||
import { ApiTags } from "@midwayjs/swagger";
|
import { ApiTags } from "@midwayjs/swagger";
|
||||||
import { AuditType } from "../../../modules/sys/enterprise/service/audit-constants.js";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Addon
|
* Addon
|
||||||
@@ -25,10 +24,6 @@ export class AddonController extends CrudController<AddonService> {
|
|||||||
return this.service;
|
return this.service;
|
||||||
}
|
}
|
||||||
|
|
||||||
getAuditType(): string {
|
|
||||||
return AuditType.addon.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post("/page", { description: Constants.per.authOnly, summary: "查询Addon分页列表" })
|
@Post("/page", { description: Constants.per.authOnly, summary: "查询Addon分页列表" })
|
||||||
async page(@Body(ALL) body) {
|
async page(@Body(ALL) body) {
|
||||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||||
@@ -73,9 +68,7 @@ export class AddonController extends CrudController<AddonService> {
|
|||||||
if (define.needPlus) {
|
if (define.needPlus) {
|
||||||
checkPlus();
|
checkPlus();
|
||||||
}
|
}
|
||||||
const res = await super.add(bean);
|
return super.add(bean);
|
||||||
this.auditLog({ content: `新增了Addon「${bean.name}」(ID:${res.data}, 类型:${bean.type})` });
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/update", { description: Constants.per.authOnly, summary: "更新Addon" })
|
@Post("/update", { description: Constants.per.authOnly, summary: "更新Addon" })
|
||||||
@@ -98,9 +91,7 @@ export class AddonController extends CrudController<AddonService> {
|
|||||||
}
|
}
|
||||||
delete bean.userId;
|
delete bean.userId;
|
||||||
delete bean.projectId;
|
delete bean.projectId;
|
||||||
const res = await super.update(bean);
|
return super.update(bean);
|
||||||
this.auditLog({ content: `修改了Addon「${bean.name}」(ID:${bean.id})` });
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/info", { description: Constants.per.authOnly, summary: "查询Addon详情" })
|
@Post("/info", { description: Constants.per.authOnly, summary: "查询Addon详情" })
|
||||||
@@ -112,9 +103,7 @@ export class AddonController extends CrudController<AddonService> {
|
|||||||
@Post("/delete", { description: Constants.per.authOnly, summary: "删除Addon" })
|
@Post("/delete", { description: Constants.per.authOnly, summary: "删除Addon" })
|
||||||
async delete(@Query("id") id: number) {
|
async delete(@Query("id") id: number) {
|
||||||
await this.checkOwner(this.getService(), id, "write");
|
await this.checkOwner(this.getService(), id, "write");
|
||||||
const res = await super.delete(id);
|
return super.delete(id);
|
||||||
this.auditLog({ content: `删除了Addon(ID:${id})` });
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/define", { description: Constants.per.authOnly, summary: "查询Addon插件定义" })
|
@Post("/define", { description: Constants.per.authOnly, summary: "查询Addon插件定义" })
|
||||||
@@ -169,7 +158,6 @@ export class AddonController extends CrudController<AddonService> {
|
|||||||
async setDefault(@Query("addonType") addonType: string, @Query("id") id: number) {
|
async setDefault(@Query("addonType") addonType: string, @Query("id") id: number) {
|
||||||
const { projectId, userId } = await this.checkOwner(this.getService(), id, "write", true);
|
const { projectId, userId } = await this.checkOwner(this.getService(), id, "write", true);
|
||||||
const res = await this.service.setDefault(id, userId, addonType, projectId);
|
const res = await this.service.setDefault(id, userId, addonType, projectId);
|
||||||
this.auditLog({ content: `设置了默认Addon(ID:${id})` });
|
|
||||||
return this.ok(res);
|
return this.ok(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,41 +0,0 @@
|
|||||||
import { BaseController, Constants } from "@certd/lib-server";
|
|
||||||
import { ALL, Body, Controller, Inject, Post, Provide } from "@midwayjs/core";
|
|
||||||
import { ApiTags } from "@midwayjs/swagger";
|
|
||||||
import { AuditService } from "../../../modules/sys/enterprise/service/audit-service.js";
|
|
||||||
import { buildAuditTypeDict, buildAuditActionDict } from "../../../modules/sys/enterprise/service/audit-constants.js";
|
|
||||||
|
|
||||||
@Provide()
|
|
||||||
@ApiTags(["audit"])
|
|
||||||
@Controller("/api/pi/audit")
|
|
||||||
export class AuditLogController extends BaseController {
|
|
||||||
@Inject()
|
|
||||||
auditService: AuditService;
|
|
||||||
|
|
||||||
@Post("/page", { description: Constants.per.authOnly, summary: "分页查询当前用户操作日志" })
|
|
||||||
async page(@Body(ALL) body: any) {
|
|
||||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
|
||||||
const query: any = {};
|
|
||||||
if (projectId) {
|
|
||||||
//如果是项目级别,排除userId参数,因为日志这里userId不是-1 ,而是实际的用户
|
|
||||||
query.projectId = projectId;
|
|
||||||
} else {
|
|
||||||
query.userId = userId;
|
|
||||||
}
|
|
||||||
body.query = {
|
|
||||||
...(body.query || {}),
|
|
||||||
...query,
|
|
||||||
scope: "user",
|
|
||||||
};
|
|
||||||
|
|
||||||
const pageRet = await this.auditService.page(body);
|
|
||||||
return this.ok(pageRet);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post("/dict", { description: Constants.per.authOnly, summary: "获取审计类型和动作字典" })
|
|
||||||
async getDict() {
|
|
||||||
return this.ok({
|
|
||||||
types: buildAuditTypeDict(),
|
|
||||||
actions: buildAuditActionDict(),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,7 +3,6 @@ import { Constants, CrudController } from "@certd/lib-server";
|
|||||||
import { AuthService } from "../../../modules/sys/authority/service/auth-service.js";
|
import { AuthService } from "../../../modules/sys/authority/service/auth-service.js";
|
||||||
import { GroupService } from "../../../modules/basic/service/group-service.js";
|
import { GroupService } from "../../../modules/basic/service/group-service.js";
|
||||||
import { ApiTags } from "@midwayjs/swagger";
|
import { ApiTags } from "@midwayjs/swagger";
|
||||||
import { AuditType } from "../../../modules/sys/enterprise/service/audit-constants.js";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通知
|
* 通知
|
||||||
@@ -21,10 +20,6 @@ export class GroupController extends CrudController<GroupService> {
|
|||||||
return this.service;
|
return this.service;
|
||||||
}
|
}
|
||||||
|
|
||||||
getAuditType(): string {
|
|
||||||
return AuditType.pipelineGroup.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post("/page", { description: Constants.per.authOnly, summary: "查询分组分页列表" })
|
@Post("/page", { description: Constants.per.authOnly, summary: "查询分组分页列表" })
|
||||||
async page(@Body(ALL) body: any) {
|
async page(@Body(ALL) body: any) {
|
||||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||||
@@ -57,9 +52,7 @@ export class GroupController extends CrudController<GroupService> {
|
|||||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||||
bean.projectId = projectId;
|
bean.projectId = projectId;
|
||||||
bean.userId = userId;
|
bean.userId = userId;
|
||||||
const res = await super.add(bean);
|
return await super.add(bean);
|
||||||
this.auditLog({ content: `新增了分组「${bean.name}」(ID:${res.data})` });
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/update", { description: Constants.per.authOnly, summary: "更新分组" })
|
@Post("/update", { description: Constants.per.authOnly, summary: "更新分组" })
|
||||||
@@ -67,9 +60,7 @@ export class GroupController extends CrudController<GroupService> {
|
|||||||
await this.checkOwner(this.getService(), bean.id, "write");
|
await this.checkOwner(this.getService(), bean.id, "write");
|
||||||
delete bean.userId;
|
delete bean.userId;
|
||||||
delete bean.projectId;
|
delete bean.projectId;
|
||||||
const res = await super.update(bean);
|
return await super.update(bean);
|
||||||
this.auditLog({ content: `修改了分组「${bean.name}」(ID:${bean.id})` });
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
@Post("/info", { description: Constants.per.authOnly, summary: "查询分组详情" })
|
@Post("/info", { description: Constants.per.authOnly, summary: "查询分组详情" })
|
||||||
async info(@Query("id") id: number) {
|
async info(@Query("id") id: number) {
|
||||||
@@ -80,9 +71,7 @@ export class GroupController extends CrudController<GroupService> {
|
|||||||
@Post("/delete", { description: Constants.per.authOnly, summary: "删除分组" })
|
@Post("/delete", { description: Constants.per.authOnly, summary: "删除分组" })
|
||||||
async delete(@Query("id") id: number) {
|
async delete(@Query("id") id: number) {
|
||||||
await this.checkOwner(this.getService(), id, "write");
|
await this.checkOwner(this.getService(), id, "write");
|
||||||
const res = await super.delete(id);
|
return await super.delete(id);
|
||||||
this.auditLog({ content: `删除了分组(ID:${id})` });
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/all", { description: Constants.per.authOnly, summary: "查询所有分组" })
|
@Post("/all", { description: Constants.per.authOnly, summary: "查询所有分组" })
|
||||||
|
|||||||
+4
-17
@@ -2,7 +2,6 @@ import { ALL, Body, Controller, Inject, Post, Provide, Query } from "@midwayjs/c
|
|||||||
import { Constants, CrudController } from "@certd/lib-server";
|
import { Constants, CrudController } from "@certd/lib-server";
|
||||||
import { ApiTags } from "@midwayjs/swagger";
|
import { ApiTags } from "@midwayjs/swagger";
|
||||||
import { CertApplyTemplateService } from "../../../modules/cert/service/cert-apply-template-service.js";
|
import { CertApplyTemplateService } from "../../../modules/cert/service/cert-apply-template-service.js";
|
||||||
import { AuditType } from "../../../modules/sys/enterprise/service/audit-constants.js";
|
|
||||||
|
|
||||||
@Provide()
|
@Provide()
|
||||||
@Controller("/api/cert/apply-template")
|
@Controller("/api/cert/apply-template")
|
||||||
@@ -15,10 +14,6 @@ export class CertApplyTemplateController extends CrudController<CertApplyTemplat
|
|||||||
return this.service;
|
return this.service;
|
||||||
}
|
}
|
||||||
|
|
||||||
getAuditType(): string {
|
|
||||||
return AuditType.certTemplate.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
private removeContent(data: any) {
|
private removeContent(data: any) {
|
||||||
const records = Array.isArray(data) ? data : data?.records;
|
const records = Array.isArray(data) ? data : data?.records;
|
||||||
if (!records) {
|
if (!records) {
|
||||||
@@ -58,9 +53,7 @@ export class CertApplyTemplateController extends CrudController<CertApplyTemplat
|
|||||||
const { projectId, userId } = await this.getProjectUserIdWrite();
|
const { projectId, userId } = await this.getProjectUserIdWrite();
|
||||||
bean.projectId = projectId;
|
bean.projectId = projectId;
|
||||||
bean.userId = userId;
|
bean.userId = userId;
|
||||||
const res = await super.add(bean);
|
return super.add(bean);
|
||||||
this.auditLog({ content: `新增了证书参数模版「${bean.name}」(ID:${res.data})` });
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/update", { description: Constants.per.authOnly, summary: "更新证书申请参数模版" })
|
@Post("/update", { description: Constants.per.authOnly, summary: "更新证书申请参数模版" })
|
||||||
@@ -68,9 +61,7 @@ export class CertApplyTemplateController extends CrudController<CertApplyTemplat
|
|||||||
await this.checkOwner(this.getService(), bean.id, "write");
|
await this.checkOwner(this.getService(), bean.id, "write");
|
||||||
delete bean.userId;
|
delete bean.userId;
|
||||||
delete bean.projectId;
|
delete bean.projectId;
|
||||||
const res = await super.update(bean);
|
return super.update(bean);
|
||||||
this.auditLog({ content: `修改了证书参数模版「${bean.name}」(ID:${bean.id})` });
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/info", { description: Constants.per.authOnly, summary: "查询证书申请参数模版详情" })
|
@Post("/info", { description: Constants.per.authOnly, summary: "查询证书申请参数模版详情" })
|
||||||
@@ -82,17 +73,13 @@ export class CertApplyTemplateController extends CrudController<CertApplyTemplat
|
|||||||
@Post("/delete", { description: Constants.per.authOnly, summary: "删除证书申请参数模版" })
|
@Post("/delete", { description: Constants.per.authOnly, summary: "删除证书申请参数模版" })
|
||||||
async delete(@Query("id") id: number) {
|
async delete(@Query("id") id: number) {
|
||||||
await this.checkOwner(this.getService(), id, "write");
|
await this.checkOwner(this.getService(), id, "write");
|
||||||
const res = await super.delete(id);
|
return super.delete(id);
|
||||||
this.auditLog({ content: `删除了证书参数模版(ID:${id})` });
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/setDefault", { description: Constants.per.authOnly, summary: "设置默认证书申请参数模版" })
|
@Post("/setDefault", { description: Constants.per.authOnly, summary: "设置默认证书申请参数模版" })
|
||||||
async setDefault(@Body("id") id: number) {
|
async setDefault(@Body("id") id: number) {
|
||||||
const { projectId, userId } = await this.getProjectUserIdWrite();
|
const { projectId, userId } = await this.getProjectUserIdWrite();
|
||||||
const defaultId = await this.service.setDefault(id, userId, projectId);
|
return this.ok(await this.service.setDefault(id, userId, projectId));
|
||||||
this.auditLog({ content: `设置了默认证书参数模版(ID:${id})` });
|
|
||||||
return this.ok(defaultId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/default", { description: Constants.per.authOnly, summary: "查询默认证书申请参数模版" })
|
@Post("/default", { description: Constants.per.authOnly, summary: "查询默认证书申请参数模版" })
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { ALL, Body, Controller, Inject, Post, Provide, Query } from "@midwayjs/c
|
|||||||
import { Constants, CrudController } from "@certd/lib-server";
|
import { Constants, CrudController } from "@certd/lib-server";
|
||||||
import { ApiTags } from "@midwayjs/swagger";
|
import { ApiTags } from "@midwayjs/swagger";
|
||||||
import { DnsPersistRecordService } from "../../../modules/cert/service/dns-persist-record-service.js";
|
import { DnsPersistRecordService } from "../../../modules/cert/service/dns-persist-record-service.js";
|
||||||
import { AuditType } from "../../../modules/sys/enterprise/service/audit-constants.js";
|
|
||||||
|
|
||||||
@Provide()
|
@Provide()
|
||||||
@Controller("/api/cert/dns-persist")
|
@Controller("/api/cert/dns-persist")
|
||||||
@@ -15,10 +14,6 @@ export class DnsPersistRecordController extends CrudController<DnsPersistRecordS
|
|||||||
return this.service;
|
return this.service;
|
||||||
}
|
}
|
||||||
|
|
||||||
getAuditType(): string {
|
|
||||||
return AuditType.dnsPersist.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post("/page", { description: Constants.per.authOnly, summary: "查询DNS持久验证记录分页列表" })
|
@Post("/page", { description: Constants.per.authOnly, summary: "查询DNS持久验证记录分页列表" })
|
||||||
async page(@Body(ALL) body: any) {
|
async page(@Body(ALL) body: any) {
|
||||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||||
@@ -33,9 +28,7 @@ export class DnsPersistRecordController extends CrudController<DnsPersistRecordS
|
|||||||
const { projectId, userId } = await this.getProjectUserIdWrite();
|
const { projectId, userId } = await this.getProjectUserIdWrite();
|
||||||
bean.projectId = projectId;
|
bean.projectId = projectId;
|
||||||
bean.userId = userId;
|
bean.userId = userId;
|
||||||
const res = await this.getService().add(bean);
|
return super.add(bean);
|
||||||
this.auditLog({ content: `新增了DNS持久验证记录「${bean.domain}」(ID:${res.id})` });
|
|
||||||
return this.ok(res);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/update", { description: Constants.per.authOnly, summary: "更新DNS持久验证记录" })
|
@Post("/update", { description: Constants.per.authOnly, summary: "更新DNS持久验证记录" })
|
||||||
@@ -43,9 +36,7 @@ export class DnsPersistRecordController extends CrudController<DnsPersistRecordS
|
|||||||
await this.checkOwner(this.getService(), bean.id, "write");
|
await this.checkOwner(this.getService(), bean.id, "write");
|
||||||
delete bean.userId;
|
delete bean.userId;
|
||||||
delete bean.projectId;
|
delete bean.projectId;
|
||||||
const res = await super.update(bean);
|
return super.update(bean);
|
||||||
this.auditLog({ content: `修改了DNS持久验证记录(ID:${bean.id})` });
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/info", { description: Constants.per.authOnly, summary: "查询DNS持久验证记录详情" })
|
@Post("/info", { description: Constants.per.authOnly, summary: "查询DNS持久验证记录详情" })
|
||||||
@@ -58,7 +49,6 @@ export class DnsPersistRecordController extends CrudController<DnsPersistRecordS
|
|||||||
async delete(@Query("id") id: number) {
|
async delete(@Query("id") id: number) {
|
||||||
await this.checkOwner(this.getService(), id, "write");
|
await this.checkOwner(this.getService(), id, "write");
|
||||||
await this.service.delete(id as any);
|
await this.service.delete(id as any);
|
||||||
this.auditLog({ content: `删除了DNS持久验证记录(ID:${id})` });
|
|
||||||
return this.ok({
|
return this.ok({
|
||||||
message: this.service.lastDeleteMessage,
|
message: this.service.lastDeleteMessage,
|
||||||
});
|
});
|
||||||
@@ -90,16 +80,12 @@ export class DnsPersistRecordController extends CrudController<DnsPersistRecordS
|
|||||||
@Post("/triggerVerify", { description: Constants.per.authOnly, summary: "后台验证DNS持久验证记录" })
|
@Post("/triggerVerify", { description: Constants.per.authOnly, summary: "后台验证DNS持久验证记录" })
|
||||||
async triggerVerify(@Body(ALL) body: { id: number }) {
|
async triggerVerify(@Body(ALL) body: { id: number }) {
|
||||||
await this.checkOwner(this.getService(), body.id, "write");
|
await this.checkOwner(this.getService(), body.id, "write");
|
||||||
const res = await this.service.triggerVerify(body.id);
|
return this.ok(await this.service.triggerVerify(body.id));
|
||||||
this.auditLog({ content: `触发了DNS持久验证(ID:${body.id})` });
|
|
||||||
return this.ok(res);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/createTxt", { description: Constants.per.authOnly, summary: "一键创建DNS持久验证TXT记录" })
|
@Post("/createTxt", { description: Constants.per.authOnly, summary: "一键创建DNS持久验证TXT记录" })
|
||||||
async createTxt(@Body(ALL) body: { id: number; dnsProviderType?: string; dnsProviderAccess?: number }) {
|
async createTxt(@Body(ALL) body: { id: number; dnsProviderType?: string; dnsProviderAccess?: number }) {
|
||||||
await this.checkOwner(this.getService(), body.id, "write");
|
await this.checkOwner(this.getService(), body.id, "write");
|
||||||
const res = await this.service.createDnsTxt(body);
|
return this.ok(await this.service.createDnsTxt(body));
|
||||||
this.auditLog({ content: `一键创建了DNS持久验证TXT记录(ID:${body.id})` });
|
|
||||||
return this.ok(res);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import { DomainService } from "../../../modules/cert/service/domain-service.js";
|
|||||||
import { checkPlus } from "@certd/plus-core";
|
import { checkPlus } from "@certd/plus-core";
|
||||||
import { ApiTags } from "@midwayjs/swagger";
|
import { ApiTags } from "@midwayjs/swagger";
|
||||||
import { parseDomainByPsl } from "@certd/plugin-lib";
|
import { parseDomainByPsl } from "@certd/plugin-lib";
|
||||||
import { AuditType } from "../../../modules/sys/enterprise/service/audit-constants.js";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 授权
|
* 授权
|
||||||
@@ -20,10 +19,6 @@ export class DomainController extends CrudController<DomainService> {
|
|||||||
return this.service;
|
return this.service;
|
||||||
}
|
}
|
||||||
|
|
||||||
getAuditType(): string {
|
|
||||||
return AuditType.domain.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post("/page", { description: Constants.per.authOnly, summary: "查询域名分页列表" })
|
@Post("/page", { description: Constants.per.authOnly, summary: "查询域名分页列表" })
|
||||||
async page(@Body(ALL) body: any) {
|
async page(@Body(ALL) body: any) {
|
||||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||||
@@ -63,9 +58,7 @@ export class DomainController extends CrudController<DomainService> {
|
|||||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||||
bean.projectId = projectId;
|
bean.projectId = projectId;
|
||||||
bean.userId = userId;
|
bean.userId = userId;
|
||||||
const res = await super.add(bean);
|
return super.add(bean);
|
||||||
this.auditLog({ content: `新增了域名「${bean.domain}」` });
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/update", { description: Constants.per.authOnly, summary: "更新域名" })
|
@Post("/update", { description: Constants.per.authOnly, summary: "更新域名" })
|
||||||
@@ -73,9 +66,7 @@ export class DomainController extends CrudController<DomainService> {
|
|||||||
await this.checkOwner(this.getService(), bean.id, "write");
|
await this.checkOwner(this.getService(), bean.id, "write");
|
||||||
delete bean.userId;
|
delete bean.userId;
|
||||||
delete bean.projectId;
|
delete bean.projectId;
|
||||||
const res = await super.update(bean);
|
return super.update(bean);
|
||||||
this.auditLog({ content: `修改了域名「${bean.domain}」` });
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/info", { description: Constants.per.authOnly, summary: "查询域名详情" })
|
@Post("/info", { description: Constants.per.authOnly, summary: "查询域名详情" })
|
||||||
@@ -87,16 +78,13 @@ export class DomainController extends CrudController<DomainService> {
|
|||||||
@Post("/delete", { description: Constants.per.authOnly, summary: "删除域名" })
|
@Post("/delete", { description: Constants.per.authOnly, summary: "删除域名" })
|
||||||
async delete(@Query("id") id: number) {
|
async delete(@Query("id") id: number) {
|
||||||
await this.checkOwner(this.getService(), id, "write");
|
await this.checkOwner(this.getService(), id, "write");
|
||||||
const res = await super.delete(id);
|
return super.delete(id);
|
||||||
this.auditLog({ content: `删除了域名(ID:${id})` });
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/deleteByIds", { description: Constants.per.authOnly, summary: "批量删除域名" })
|
@Post("/deleteByIds", { description: Constants.per.authOnly, summary: "批量删除域名" })
|
||||||
async deleteByIds(@Body(ALL) body: any) {
|
async deleteByIds(@Body(ALL) body: any) {
|
||||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||||
await this.service.batchDelete(body.ids, userId, projectId);
|
await this.service.batchDelete(body.ids, userId, projectId);
|
||||||
this.auditLog({ content: `批量删除了${body.ids.length}条域名` });
|
|
||||||
return this.ok();
|
return this.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,7 +99,6 @@ export class DomainController extends CrudController<DomainService> {
|
|||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
};
|
};
|
||||||
await this.service.startDomainImportTask(req);
|
await this.service.startDomainImportTask(req);
|
||||||
this.auditLog({ content: "开始了域名导入任务" });
|
|
||||||
return this.ok();
|
return this.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,7 +123,6 @@ export class DomainController extends CrudController<DomainService> {
|
|||||||
key,
|
key,
|
||||||
};
|
};
|
||||||
await this.service.deleteDomainImportTask(req);
|
await this.service.deleteDomainImportTask(req);
|
||||||
this.auditLog({ content: "删除了域名导入任务" });
|
|
||||||
return this.ok();
|
return this.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,7 +139,6 @@ export class DomainController extends CrudController<DomainService> {
|
|||||||
key,
|
key,
|
||||||
};
|
};
|
||||||
const item = await this.service.saveDomainImportTask(req);
|
const item = await this.service.saveDomainImportTask(req);
|
||||||
this.auditLog({ content: "保存了域名导入任务" });
|
|
||||||
return this.ok(item);
|
return this.ok(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,7 +149,6 @@ export class DomainController extends CrudController<DomainService> {
|
|||||||
userId: userId,
|
userId: userId,
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
});
|
});
|
||||||
this.auditLog({ content: "开始了同步域名过期时间任务" });
|
|
||||||
return this.ok();
|
return this.ok();
|
||||||
}
|
}
|
||||||
@Post("/sync/expiration/status", { description: Constants.per.authOnly, summary: "查询同步域名过期时间任务状态" })
|
@Post("/sync/expiration/status", { description: Constants.per.authOnly, summary: "查询同步域名过期时间任务状态" })
|
||||||
@@ -185,7 +169,6 @@ export class DomainController extends CrudController<DomainService> {
|
|||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
setting: { ...body },
|
setting: { ...body },
|
||||||
});
|
});
|
||||||
this.auditLog({ content: "保存了域名监控设置" });
|
|
||||||
return this.ok();
|
return this.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { ALL, Body, Controller, Inject, Post, Provide, Query } from "@midwayjs/c
|
|||||||
import { Constants, CrudController } from "@certd/lib-server";
|
import { Constants, CrudController } from "@certd/lib-server";
|
||||||
import { CnameRecordService } from "../../../modules/cname/service/cname-record-service.js";
|
import { CnameRecordService } from "../../../modules/cname/service/cname-record-service.js";
|
||||||
import { ApiTags } from "@midwayjs/swagger";
|
import { ApiTags } from "@midwayjs/swagger";
|
||||||
import { AuditType } from "../../../modules/sys/enterprise/service/audit-constants.js";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 授权
|
* 授权
|
||||||
@@ -18,10 +17,6 @@ export class CnameRecordController extends CrudController<CnameRecordService> {
|
|||||||
return this.service;
|
return this.service;
|
||||||
}
|
}
|
||||||
|
|
||||||
getAuditType(): string {
|
|
||||||
return AuditType.cname.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post("/page", { description: Constants.per.authOnly, summary: "查询CNAME记录分页列表" })
|
@Post("/page", { description: Constants.per.authOnly, summary: "查询CNAME记录分页列表" })
|
||||||
async page(@Body(ALL) body: any) {
|
async page(@Body(ALL) body: any) {
|
||||||
const { userId, projectId } = await this.getProjectUserIdRead();
|
const { userId, projectId } = await this.getProjectUserIdRead();
|
||||||
@@ -61,9 +56,7 @@ export class CnameRecordController extends CrudController<CnameRecordService> {
|
|||||||
const { userId, projectId } = await this.getProjectUserIdWrite();
|
const { userId, projectId } = await this.getProjectUserIdWrite();
|
||||||
bean.userId = userId;
|
bean.userId = userId;
|
||||||
bean.projectId = projectId;
|
bean.projectId = projectId;
|
||||||
const res = await super.add(bean);
|
return super.add(bean);
|
||||||
this.auditLog({ content: `新增了CNAME记录「${bean.domain}」` });
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/update", { description: Constants.per.authOnly, summary: "更新CNAME记录" })
|
@Post("/update", { description: Constants.per.authOnly, summary: "更新CNAME记录" })
|
||||||
@@ -71,9 +64,7 @@ export class CnameRecordController extends CrudController<CnameRecordService> {
|
|||||||
await this.checkOwner(this.getService(), bean.id, "write");
|
await this.checkOwner(this.getService(), bean.id, "write");
|
||||||
delete bean.userId;
|
delete bean.userId;
|
||||||
delete bean.projectId;
|
delete bean.projectId;
|
||||||
const res = await super.update(bean);
|
return super.update(bean);
|
||||||
this.auditLog({ content: `修改了CNAME记录(ID:${bean.id})` });
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/info", { description: Constants.per.authOnly, summary: "查询CNAME记录详情" })
|
@Post("/info", { description: Constants.per.authOnly, summary: "查询CNAME记录详情" })
|
||||||
@@ -85,16 +76,13 @@ export class CnameRecordController extends CrudController<CnameRecordService> {
|
|||||||
@Post("/delete", { description: Constants.per.authOnly, summary: "删除CNAME记录" })
|
@Post("/delete", { description: Constants.per.authOnly, summary: "删除CNAME记录" })
|
||||||
async delete(@Query("id") id: number) {
|
async delete(@Query("id") id: number) {
|
||||||
await this.checkOwner(this.getService(), id, "write");
|
await this.checkOwner(this.getService(), id, "write");
|
||||||
const res = await super.delete(id);
|
return super.delete(id);
|
||||||
this.auditLog({ content: `删除了CNAME记录(ID:${id})` });
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/deleteByIds", { description: Constants.per.authOnly, summary: "批量删除CNAME记录" })
|
@Post("/deleteByIds", { description: Constants.per.authOnly, summary: "批量删除CNAME记录" })
|
||||||
async deleteByIds(@Body(ALL) body: any) {
|
async deleteByIds(@Body(ALL) body: any) {
|
||||||
const { userId, projectId } = await this.getProjectUserIdWrite();
|
const { userId, projectId } = await this.getProjectUserIdWrite();
|
||||||
await this.service.batchDelete(body.ids, userId, projectId);
|
await this.service.batchDelete(body.ids, userId, projectId);
|
||||||
this.auditLog({ content: `批量删除了${body.ids.length}条CNAME记录` });
|
|
||||||
return this.ok();
|
return this.ok();
|
||||||
}
|
}
|
||||||
@Post("/getByDomain", { description: Constants.per.authOnly, summary: "根据域名获取CNAME记录" })
|
@Post("/getByDomain", { description: Constants.per.authOnly, summary: "根据域名获取CNAME记录" })
|
||||||
@@ -115,7 +103,6 @@ export class CnameRecordController extends CrudController<CnameRecordService> {
|
|||||||
async resetStatus(@Body(ALL) body: { id: number }) {
|
async resetStatus(@Body(ALL) body: { id: number }) {
|
||||||
await this.checkOwner(this.getService(), body.id, "read");
|
await this.checkOwner(this.getService(), body.id, "read");
|
||||||
const res = await this.service.resetStatus(body.id);
|
const res = await this.service.resetStatus(body.id);
|
||||||
this.auditLog({ content: `重置了CNAME记录状态(ID:${body.id})` });
|
|
||||||
return this.ok(res);
|
return this.ok(res);
|
||||||
}
|
}
|
||||||
@Post("/import", { description: Constants.per.authOnly, summary: "导入CNAME记录" })
|
@Post("/import", { description: Constants.per.authOnly, summary: "导入CNAME记录" })
|
||||||
@@ -127,7 +114,6 @@ export class CnameRecordController extends CrudController<CnameRecordService> {
|
|||||||
domainList: body.domainList,
|
domainList: body.domainList,
|
||||||
cnameProviderId: body.cnameProviderId,
|
cnameProviderId: body.cnameProviderId,
|
||||||
});
|
});
|
||||||
this.auditLog({ append: `提交${res.count}条` });
|
|
||||||
return this.ok(res);
|
return this.ok(res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import { AuthService } from "../../../modules/sys/authority/service/auth-service
|
|||||||
import { ProjectService } from "../../../modules/sys/enterprise/service/project-service.js";
|
import { ProjectService } from "../../../modules/sys/enterprise/service/project-service.js";
|
||||||
import { ProjectMemberService } from "../../../modules/sys/enterprise/service/project-member-service.js";
|
import { ProjectMemberService } from "../../../modules/sys/enterprise/service/project-member-service.js";
|
||||||
import { ApiTags } from "@midwayjs/swagger";
|
import { ApiTags } from "@midwayjs/swagger";
|
||||||
import { AuditType } from "../../../modules/sys/enterprise/service/audit-constants.js";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
@@ -25,10 +24,6 @@ export class UserProjectController extends BaseController {
|
|||||||
return this.service;
|
return this.service;
|
||||||
}
|
}
|
||||||
|
|
||||||
getAuditType(): string {
|
|
||||||
return AuditType.enterprise.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param body
|
* @param body
|
||||||
* @returns
|
* @returns
|
||||||
@@ -68,7 +63,6 @@ export class UserProjectController extends BaseController {
|
|||||||
async applyJoin(@Body(ALL) body: any) {
|
async applyJoin(@Body(ALL) body: any) {
|
||||||
const userId = this.getUserId();
|
const userId = this.getUserId();
|
||||||
const res = await this.service.applyJoin({ userId, projectId: body.projectId });
|
const res = await this.service.applyJoin({ userId, projectId: body.projectId });
|
||||||
this.auditLog({ content: "申请了加入项目" });
|
|
||||||
return this.ok(res);
|
return this.ok(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +84,6 @@ export class UserProjectController extends BaseController {
|
|||||||
status,
|
status,
|
||||||
permission,
|
permission,
|
||||||
});
|
});
|
||||||
this.auditLog({ content: "更新了项目成员" });
|
|
||||||
return this.ok(res);
|
return this.ok(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,7 +92,6 @@ export class UserProjectController extends BaseController {
|
|||||||
const { projectId } = await this.getProjectUserIdAdmin();
|
const { projectId } = await this.getProjectUserIdAdmin();
|
||||||
const { status, permission, userId } = body;
|
const { status, permission, userId } = body;
|
||||||
const res = await this.service.approveJoin({ userId, projectId: projectId, status, permission });
|
const res = await this.service.approveJoin({ userId, projectId: projectId, status, permission });
|
||||||
this.auditLog({ content: "审批了加入项目申请" });
|
|
||||||
return this.ok(res);
|
return this.ok(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,9 +100,8 @@ export class UserProjectController extends BaseController {
|
|||||||
const { projectId } = await this.getProjectUserIdAdmin();
|
const { projectId } = await this.getProjectUserIdAdmin();
|
||||||
await this.projectMemberService.deleteWhere({
|
await this.projectMemberService.deleteWhere({
|
||||||
projectId,
|
projectId,
|
||||||
userId: body.userId,
|
userId: this.getUserId(),
|
||||||
});
|
});
|
||||||
this.auditLog({ content: "删除了项目成员" });
|
|
||||||
return this.ok();
|
return this.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,7 +113,6 @@ export class UserProjectController extends BaseController {
|
|||||||
projectId,
|
projectId,
|
||||||
userId,
|
userId,
|
||||||
});
|
});
|
||||||
this.auditLog({ content: "离开了项目" });
|
|
||||||
return this.ok();
|
return this.ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-13
@@ -5,7 +5,6 @@ import { ProjectMemberService } from "../../../modules/sys/enterprise/service/pr
|
|||||||
import { merge } from "lodash-es";
|
import { merge } from "lodash-es";
|
||||||
import { ProjectService } from "../../../modules/sys/enterprise/service/project-service.js";
|
import { ProjectService } from "../../../modules/sys/enterprise/service/project-service.js";
|
||||||
import { ApiTags } from "@midwayjs/swagger";
|
import { ApiTags } from "@midwayjs/swagger";
|
||||||
import { AuditType } from "../../../modules/sys/enterprise/service/audit-constants.js";
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
@Provide()
|
@Provide()
|
||||||
@@ -25,10 +24,6 @@ export class ProjectMemberController extends CrudController<ProjectMemberEntity>
|
|||||||
return this.service;
|
return this.service;
|
||||||
}
|
}
|
||||||
|
|
||||||
getAuditType(): string {
|
|
||||||
return AuditType.enterprise.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post("/page", { description: Constants.per.authOnly, summary: "查询项目成员分页列表" })
|
@Post("/page", { description: Constants.per.authOnly, summary: "查询项目成员分页列表" })
|
||||||
async page(@Body(ALL) body: any) {
|
async page(@Body(ALL) body: any) {
|
||||||
const { projectId } = await this.getProjectUserIdRead();
|
const { projectId } = await this.getProjectUserIdRead();
|
||||||
@@ -58,9 +53,7 @@ export class ProjectMemberController extends CrudController<ProjectMemberEntity>
|
|||||||
projectId: bean.projectId,
|
projectId: bean.projectId,
|
||||||
});
|
});
|
||||||
|
|
||||||
const res = await super.add(bean);
|
return super.add(bean);
|
||||||
this.auditLog({ content: `新增了项目成员(ID:${res.data})` });
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/update", { description: Constants.per.authOnly, summary: "更新项目成员" })
|
@Post("/update", { description: Constants.per.authOnly, summary: "更新项目成员" })
|
||||||
@@ -78,7 +71,7 @@ export class ProjectMemberController extends CrudController<ProjectMemberEntity>
|
|||||||
permission: bean.permission,
|
permission: bean.permission,
|
||||||
status: bean.status,
|
status: bean.status,
|
||||||
});
|
});
|
||||||
this.auditLog({ content: `修改了项目成员(ID:${bean.id})` });
|
|
||||||
return this.ok(res);
|
return this.ok(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,9 +98,7 @@ export class ProjectMemberController extends CrudController<ProjectMemberEntity>
|
|||||||
userId: this.getUserId(),
|
userId: this.getUserId(),
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
});
|
});
|
||||||
const res = await super.delete(id);
|
return super.delete(id);
|
||||||
this.auditLog({ content: `删除了项目成员(ID:${id})` });
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/deleteByIds", { description: Constants.per.authOnly, summary: "批量删除项目成员" })
|
@Post("/deleteByIds", { description: Constants.per.authOnly, summary: "批量删除项目成员" })
|
||||||
@@ -124,7 +115,6 @@ export class ProjectMemberController extends CrudController<ProjectMemberEntity>
|
|||||||
await this.service.delete(id as any);
|
await this.service.delete(id as any);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.auditLog({ content: `批量删除了${ids.length}条项目成员` });
|
|
||||||
return this.ok({});
|
return this.ok({});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { BaseController, Constants } from "@certd/lib-server";
|
|||||||
import { Controller, Inject, Post, Provide } from "@midwayjs/core";
|
import { Controller, Inject, Post, Provide } from "@midwayjs/core";
|
||||||
import { TransferService } from "../../../modules/sys/enterprise/service/transfer-service.js";
|
import { TransferService } from "../../../modules/sys/enterprise/service/transfer-service.js";
|
||||||
import { ApiTags } from "@midwayjs/swagger";
|
import { ApiTags } from "@midwayjs/swagger";
|
||||||
import { AuditType } from "../../../modules/sys/enterprise/service/audit-constants.js";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
@@ -17,10 +16,6 @@ export class TransferController extends BaseController {
|
|||||||
return this.service;
|
return this.service;
|
||||||
}
|
}
|
||||||
|
|
||||||
getAuditType(): string {
|
|
||||||
return AuditType.enterprise.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 我自己的资源
|
* 我自己的资源
|
||||||
* @param body
|
* @param body
|
||||||
@@ -43,7 +38,6 @@ export class TransferController extends BaseController {
|
|||||||
const { projectId } = await this.getProjectUserIdRead();
|
const { projectId } = await this.getProjectUserIdRead();
|
||||||
const userId = this.getUserId();
|
const userId = this.getUserId();
|
||||||
await this.service.transferAll(userId, projectId);
|
await this.service.transferAll(userId, projectId);
|
||||||
this.auditLog({ content: "迁移了项目资源" });
|
|
||||||
return this.ok();
|
return this.ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import { BaseController } from "@certd/lib-server";
|
|||||||
import { Constants } from "@certd/lib-server";
|
import { Constants } from "@certd/lib-server";
|
||||||
import { EmailService } from "../../../modules/basic/service/email-service.js";
|
import { EmailService } from "../../../modules/basic/service/email-service.js";
|
||||||
import { ApiTags } from "@midwayjs/swagger";
|
import { ApiTags } from "@midwayjs/swagger";
|
||||||
import { AuditType } from "../../../modules/sys/enterprise/service/audit-constants.js";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
@@ -14,15 +13,10 @@ export class EmailController extends BaseController {
|
|||||||
@Inject()
|
@Inject()
|
||||||
emailService: EmailService;
|
emailService: EmailService;
|
||||||
|
|
||||||
getAuditType(): string {
|
|
||||||
return AuditType.mine.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post("/test", { description: Constants.per.authOnly, summary: "测试邮件发送" })
|
@Post("/test", { description: Constants.per.authOnly, summary: "测试邮件发送" })
|
||||||
public async test(@Body("receiver") receiver) {
|
public async test(@Body("receiver") receiver) {
|
||||||
const userId = super.getUserId();
|
const userId = super.getUserId();
|
||||||
await this.emailService.test(userId, receiver);
|
await this.emailService.test(userId, receiver);
|
||||||
this.auditLog({ content: "测试了邮件发送" });
|
|
||||||
return this.ok({});
|
return this.ok({});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,7 +31,6 @@ export class EmailController extends BaseController {
|
|||||||
public async add(@Body("email") email) {
|
public async add(@Body("email") email) {
|
||||||
const userId = super.getUserId();
|
const userId = super.getUserId();
|
||||||
await this.emailService.add(userId, email);
|
await this.emailService.add(userId, email);
|
||||||
this.auditLog({ content: "添加了邮件" });
|
|
||||||
return this.ok({});
|
return this.ok({});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,7 +38,6 @@ export class EmailController extends BaseController {
|
|||||||
public async delete(@Body("email") email) {
|
public async delete(@Body("email") email) {
|
||||||
const userId = super.getUserId();
|
const userId = super.getUserId();
|
||||||
await this.emailService.delete(userId, email);
|
await this.emailService.delete(userId, email);
|
||||||
this.auditLog({ content: "删除了邮件" });
|
|
||||||
return this.ok({});
|
return this.ok({});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user