Skip to content
Draft
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2627114
refactor(config): 拆分config文件
MoeSnowyFox Mar 29, 2026
83747cb
refactor(config): 拆分config文件
MoeSnowyFox Mar 29, 2026
3373359
feat(config): 使用pydantic验证字段
MoeSnowyFox Mar 29, 2026
1c2dac6
fix(config):补充提交
MoeSnowyFox Mar 29, 2026
884ac05
refactor(config): 使用toml格式配置, 修改代码结构
MoeSnowyFox Mar 30, 2026
95c132d
chore(project): 修改检查器至python312
MoeSnowyFox Mar 30, 2026
6551bc4
fix(config): 更正类型错误
MoeSnowyFox Mar 30, 2026
6bf402b
fix(config): 清理文件
MoeSnowyFox Mar 30, 2026
9b094ab
refactor(config): 完善config模块
MoeSnowyFox Mar 30, 2026
6782e9c
refactor(config): 重构模型导入,优化异常处理和数据转换
MoeSnowyFox Apr 4, 2026
d0af1c7
refactor(api): 重构api声明格式, 修改部分api
MoeSnowyFox Apr 4, 2026
40891c6
refactor(api): 整理api config
MoeSnowyFox Apr 4, 2026
01ec1d8
refactor(api): 重构API装饰器,优化路由注册和模型解析
MoeSnowyFox Apr 5, 2026
716f3e0
refactor(config): 迁移contracts至app/contracts
MoeSnowyFox Apr 5, 2026
6e6cdd5
refactor(config): 优化异常处理,使用库代替部分功能
MoeSnowyFox Apr 5, 2026
af6c846
revert(config): 回退api装饰器 修改config注册方法
MoeSnowyFox Apr 6, 2026
6b0ad36
refactor(api): 移除冗余异常处理,简化API逻辑
MoeSnowyFox Apr 6, 2026
4959d7d
feat(config): 提供多种语法糖
MoeSnowyFox Apr 6, 2026
5fd043c
refactor(config): 使用迭代器生成星期字段定义,简化代码
MoeSnowyFox Apr 6, 2026
39e38fb
refactor(config): 增加skip_virtual参数以优化toDict方法,改进异常处理和建议功能
MoeSnowyFox Apr 6, 2026
da57cda
refactor(api): 生成API相关文件并优化类型定义
MoeSnowyFox Apr 16, 2026
a0b7c95
feat(plugin): migrate plugin system to new config
MoeSnowyFox Apr 16, 2026
388fb86
merge: integrate feat/PluginSystem into refactor/config
MoeSnowyFox Apr 16, 2026
f5c1a0b
fix(type): 补充类型定义
MoeSnowyFox Apr 18, 2026
98fda81
fix(type): 补充类型定义
MoeSnowyFox Apr 18, 2026
6156aeb
feat(config): 加入基于 config 模块的 PluginConfigBase
MoeSnowyFox Apr 19, 2026
c2034a6
fix(config): 使用全局封装logger
MoeSnowyFox Apr 19, 2026
203589c
fix(config): 修正错误的文本
MoeSnowyFox Apr 20, 2026
648af1e
feat(config): 添加 WebSocket 支持以处理多连接和消息广播
MoeSnowyFox Apr 26, 2026
e26724f
refactor(config): 优化日志处理和配置管理,重构相关函数以提高可读性和性能
MoeSnowyFox Apr 26, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
270 changes: 270 additions & 0 deletions API_CONFIG_REFACTOR.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,270 @@
# 配置重构 API 迁移说明

本文档记录 2026-04 配置重构相关 API 的破坏性变更,供前端组统一适配。

## 总体规则

1. 旧的 `/get`、`/add`、`/update`、`/delete`、`/time/*`、`/item/*` 兼容路由已移除,只保留新的 REST 风格路径。
2. 创建接口的返回字段统一为 `id`,不再返回 `emulatorId`、`queueId`、`timeSetId`、`queueItemId`、`webhookId` 这类资源专属字段。
3. 单资源查询统一返回:

```json
{
"code": 200,
"status": "success",
"message": "操作成功",
"data": {}
}
```

4. 集合查询统一返回:

```json
{
"code": 200,
"status": "success",
"message": "操作成功",
"index": [],
"data": {}
}
```

5. 创建接口统一返回:

```json
{
"code": 200,
"status": "success",
"message": "操作成功",
"id": "资源ID",
"data": {}
}
```

6. 更新接口的请求体直接传 `Patch` 数据,不再包一层 `{ "data": ... }`。
7. 排序接口统一为 `PATCH .../order`,请求体统一为:

```json
{
"indexList": ["id1", "id2"]
}
```

## 模拟器 API

旧接口:
`POST /api/emulator/get`
`POST /api/emulator/add`
`POST /api/emulator/update`
`POST /api/emulator/delete`
`POST /api/emulator/order`
`POST /api/emulator/operate`
`POST /api/emulator/status`
`POST /api/emulator/emulator/search`

新接口:
`GET /api/emulator`
`POST /api/emulator`
`PATCH /api/emulator/order`
`GET /api/emulator/detected`
`GET /api/emulator/status`
`GET /api/emulator/{emulator_id}`
`PATCH /api/emulator/{emulator_id}`
`DELETE /api/emulator/{emulator_id}`
`GET /api/emulator/{emulator_id}/status`
`POST /api/emulator/{emulator_id}/actions/{action}`

动作接口说明:
`action` 取值为 `open`、`close`、`show`
请求体只保留:

```json
{
"index": "0"
}
```

## 调度队列 API

旧接口:
`POST /api/queue/add`
`POST /api/queue/get`
`POST /api/queue/update`
`POST /api/queue/delete`
`POST /api/queue/order`
`POST /api/queue/time/get`
`POST /api/queue/time/add`
`POST /api/queue/time/update`
`POST /api/queue/time/delete`
`POST /api/queue/time/order`
`POST /api/queue/item/get`
`POST /api/queue/item/add`
`POST /api/queue/item/update`
`POST /api/queue/item/delete`
`POST /api/queue/item/order`

新接口:
`GET /api/queue`
`POST /api/queue`
`PATCH /api/queue/order`
`GET /api/queue/{queue_id}`
`PATCH /api/queue/{queue_id}`
`DELETE /api/queue/{queue_id}`
`GET /api/queue/{queue_id}/times`
`POST /api/queue/{queue_id}/times`
`PATCH /api/queue/{queue_id}/times/order`
`GET /api/queue/{queue_id}/times/{time_set_id}`
`PATCH /api/queue/{queue_id}/times/{time_set_id}`
`DELETE /api/queue/{queue_id}/times/{time_set_id}`
`GET /api/queue/{queue_id}/items`
`POST /api/queue/{queue_id}/items`
`PATCH /api/queue/{queue_id}/items/order`
`GET /api/queue/{queue_id}/items/{queue_item_id}`
`PATCH /api/queue/{queue_id}/items/{queue_item_id}`
`DELETE /api/queue/{queue_id}/items/{queue_item_id}`

关键变化:
单个队列、单个定时项、单个队列项不再返回 `index + data map`,只返回单个 `data`。
嵌套资源更新和删除不再在 body 中重复传 `queueId`、`timeSetId`、`queueItemId`。
WebSocket 命令 `queue.get` 现在只对应“查询单个队列”,如果需要拉取全部队列,请改走 `GET /api/queue`。

## 全局设置 API

旧接口:
`POST /api/setting/get`
`POST /api/setting/update`
`POST /api/setting/test_notify`
`POST /api/setting/webhook/get`
`POST /api/setting/webhook/add`
`POST /api/setting/webhook/update`
`POST /api/setting/webhook/delete`
`POST /api/setting/webhook/order`
`POST /api/setting/webhook/test`

新接口:
`GET /api/setting`
`PATCH /api/setting`
`POST /api/setting/actions/test-notify`
`GET /api/setting/webhooks`
`POST /api/setting/webhooks`
`PATCH /api/setting/webhooks/order`
`POST /api/setting/webhooks/test`
`GET /api/setting/webhooks/{webhook_id}`
`PATCH /api/setting/webhooks/{webhook_id}`
`DELETE /api/setting/webhooks/{webhook_id}`

关键变化:
`PATCH /api/setting` 请求体直接传 `GlobalConfigPatch`。
Webhook 单项查询返回单个 `data`,不再返回 `index + data map`。
Webhook 测试接口请求体直接传 `WebhookPatch`。

## 工具设置 API

旧接口:
`POST /api/tools/get`
`POST /api/tools/update`

新接口:
`GET /api/tools`
`PATCH /api/tools`

关键变化:
`PATCH /api/tools` 请求体直接传 `ToolsConfigPatch`。

## 脚本管理 API

旧接口:
`POST /api/scripts/add`
`POST /api/scripts/get`
`POST /api/scripts/update`
`POST /api/scripts/delete`
`POST /api/scripts/order`
`POST /api/scripts/import/file`
`POST /api/scripts/export/file`
`POST /api/scripts/import/web`
`POST /api/scripts/Upload/web`
`POST /api/scripts/user/get`
`POST /api/scripts/user/add`
`POST /api/scripts/user/update`
`POST /api/scripts/user/delete`
`POST /api/scripts/user/order`
`POST /api/scripts/user/infrastructure`
`POST /api/scripts/user/combox/infrastructure`
`POST /api/scripts/webhook/get`
`POST /api/scripts/webhook/add`
`POST /api/scripts/webhook/update`
`POST /api/scripts/webhook/delete`
`POST /api/scripts/webhook/order`

新接口:
`GET /api/scripts`
`POST /api/scripts`
`PATCH /api/scripts/order`
`GET /api/scripts/{script_id}`
`PATCH /api/scripts/{script_id}`
`DELETE /api/scripts/{script_id}`
`POST /api/scripts/{script_id}/actions/import-file`
`POST /api/scripts/{script_id}/actions/export-file`
`POST /api/scripts/{script_id}/actions/import-web`
`POST /api/scripts/{script_id}/actions/upload-web`
`GET /api/scripts/{script_id}/users`
`POST /api/scripts/{script_id}/users`
`PATCH /api/scripts/{script_id}/users/order`
`GET /api/scripts/{script_id}/users/{user_id}`
`PATCH /api/scripts/{script_id}/users/{user_id}`
`DELETE /api/scripts/{script_id}/users/{user_id}`
`POST /api/scripts/{script_id}/users/{user_id}/actions/import-infrastructure`
`GET /api/scripts/{script_id}/users/{user_id}/infrastructure-options`
`GET /api/scripts/{script_id}/users/{user_id}/webhooks`
`POST /api/scripts/{script_id}/users/{user_id}/webhooks`
`PATCH /api/scripts/{script_id}/users/{user_id}/webhooks/order`
`GET /api/scripts/{script_id}/users/{user_id}/webhooks/{webhook_id}`
`PATCH /api/scripts/{script_id}/users/{user_id}/webhooks/{webhook_id}`
`DELETE /api/scripts/{script_id}/users/{user_id}/webhooks/{webhook_id}`

关键变化:
脚本创建请求中的复制来源字段从 `scriptId` 改为 `copyFromId`。
脚本、用户、脚本用户下的 Webhook 都已经切到单资源 REST 返回,不再混用旧的 body 包装。
脚本级和用户级 patch 校验不再手写维护,而是基于运行期配置模型直接派生。

## 共享 Contract 变更

新增通用响应模型:
`ResourceCollectionOut[Index, Data]`
`ResourceItemOut[Data]`
`ResourceCreateOut[Data]`
`IndexOrderPatch`

这意味着后续新增配置资源时,应优先复用通用响应模型,不要再重复定义新的 `XXXGetOut`、`XXXCreateOut`、`XXXReorderIn` 壳子。

## Contract 生成规则

配置相关 `Read/Patch` contract 现在优先通过运行期 `PydanticConfigBase` 模型派生生成。

当前已经接入:
`EmulatorConfig`
`QueueConfig`
`TimeSet`
`QueueItem`
`Webhook`
`GlobalConfig`
`ToolsConfig`
`GeneralConfig`
`GeneralUserConfig`
`MaaConfig`
`MaaUserConfig`
`MaaPlanConfig`
`SrcConfig`
`SrcUserConfig`
`MaaEndConfig`
`MaaEndUserConfig`

规则说明:
读模型保留运行期模型字段和虚拟字段。
补丁模型自动把字段转为可选,并跳过虚拟字段。
脚本类读模型额外保留静态 `type` 字段,用于前端按 discriminator 分发。

## 额外说明

脚本相关创建接口和 Webhook 创建接口的返回字段都已统一为 `id`。
如果前端依赖旧的 `scriptId`、`userId`、`webhookId` 返回字段,需要同步调整读取逻辑。
Loading
Loading