Skip to content

Commit 84ded9e

Browse files
committed
```
feat(build): 添加可视化配置工具到构建流程 - 在 build.ps1 中新增步骤10,将配置工具从 resources/config-web/index.html 复制到 output/config-web.html - 在 release.yml 中添加兜底机制,确保配置工具正确进入输出目录 - 新增 docs/config-web.md 详细文档,说明配置工具的使用方式、 配置结构覆盖范围、导入导出行为和实时校验规则 - 配置工具支持完整的配置字段编辑,包括元信息、核心配置和路由规则 ```
1 parent be11dc7 commit 84ded9e

File tree

8 files changed

+3715
-3736
lines changed

8 files changed

+3715
-3736
lines changed

.github/workflows/release.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,18 @@ jobs:
8989
$zipName = "antigravity-proxy-${{ steps.prepare_version.outputs.release_tag }}-win-${{ matrix.arch }}.zip"
9090
$zipPath = Join-Path $env:RUNNER_TEMP $zipName
9191
if (Test-Path $zipPath) { Remove-Item -Force $zipPath }
92+
93+
# 兜底:确保配置工具已进入 output(build.ps1 已复制,这里再校验一次避免遗漏)
94+
$configWebSrc = Join-Path $env:GITHUB_WORKSPACE "resources\config-web\index.html"
95+
$configWebDst = Join-Path $env:GITHUB_WORKSPACE "output\config-web.html"
96+
if (Test-Path $configWebSrc) {
97+
Copy-Item $configWebSrc -Destination $configWebDst -Force
98+
Write-Host "已复制配置工具到 output: $configWebDst"
99+
} else {
100+
Write-Error "配置工具源文件不存在: $configWebSrc"
101+
exit 1
102+
}
103+
92104
Compress-Archive -Path "output/*" -DestinationPath $zipPath -Force
93105
"zip_path=$zipPath" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8
94106

build.ps1

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,19 @@ $usagePath = Join-Path $OutputDir "使用说明.md"
499499
$usageDoc | Out-File -FilePath $usagePath -Encoding UTF8
500500
Write-Success "使用说明已生成: $usagePath"
501501

502+
# ============================================================
503+
# 步骤 10: 复制配置工具
504+
# ============================================================
505+
506+
Write-Step "复制配置工具..."
507+
$configWebSrc = Join-Path $PSScriptRoot "resources\config-web\index.html"
508+
if (Test-Path $configWebSrc) {
509+
Copy-Item $configWebSrc -Destination (Join-Path $OutputDir "config-web.html") -Force
510+
Write-Success "配置工具已复制到 output 目录"
511+
} else {
512+
Write-Warning "配置工具源文件不存在: $configWebSrc"
513+
}
514+
502515
# ============================================================
503516
# 完成
504517
# ============================================================

docs/config-web.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Antigravity-Proxy 可视化配置工具(Config Web)
2+
3+
## 文件位置与构建产物
4+
5+
- **源码(开发态)**`resources/config-web/index.html`
6+
- **构建输出(用户可直接打开)**`output/config-web.html`
7+
-`build.ps1` 在生成 `使用说明.md` 后复制得到(见 `build.ps1` L502-L513)
8+
- **Release 资产**:Release workflow 打包的是 `output/*`,因此 zip 内会包含 `config-web.html`
9+
- `.github/workflows/release.yml``Compress-Archive` 前做了兜底复制与校验(见 `.github/workflows/release.yml` L84-L105)
10+
11+
## 使用方式(无需服务端)
12+
13+
1. 直接用浏览器打开:
14+
- 仓库内:`resources/config-web/index.html`
15+
- 或构建后:`output/config-web.html`
16+
2. **导入**:拖拽或点击「导入」选择 `config.json`
17+
3. **编辑**:按左侧导航分组修改字段(支持数组增删与拖拽排序)
18+
4. **导出**:点击「导出」生成新的 `config.json`
19+
20+
> 安全说明:全程仅在浏览器本地处理文件,不进行网络上传。
21+
22+
## 配置结构覆盖范围(与后端解析一致)
23+
24+
本工具覆盖后端实际读取的全部配置字段(见 `src/core/Config.hpp``Core::Config::Load()`),并额外包含 `build.ps1` 生成的元信息字段 `_comment/_version/_build`
25+
26+
### 顶层字段
27+
28+
- **元信息(导出时写入)**
29+
- `_comment`:说明字符串(`build.ps1` 会写入默认值,见 `build.ps1` L246-L253)
30+
- `_version`:版本号(来自 `build.ps1``$Version`
31+
- `_build``{ date, config, arch }`(构建/导出时间与构建参数)
32+
- **核心配置**
33+
- `log_level``debug/info/warn/error`
34+
- `proxy``{ host, port, type }`
35+
- `fake_ip``{ enabled, cidr }`
36+
- `timeout``{ connect, send, recv }`(毫秒)
37+
- `traffic_logging`:布尔
38+
- `child_injection`:布尔
39+
- `child_injection_mode``filtered/inherit`
40+
- `child_injection_exclude`:字符串数组
41+
- `target_processes`:字符串数组
42+
- `proxy_rules`
43+
- `allowed_ports`:端口白名单数组(空数组=全部端口)
44+
- `dns_mode``direct/proxy`
45+
- `ipv6_mode``proxy/direct/block`
46+
- `udp_mode``block/direct`
47+
- `routing`
48+
- `enabled`
49+
- `priority_mode``order/number`
50+
- `default_action``proxy/direct`
51+
- `use_default_private`
52+
- `rules`:RoutingRule 数组
53+
54+
### RoutingRule(`proxy_rules.routing.rules[]`
55+
56+
- `name`:规则名
57+
- `enabled`:是否启用
58+
- `action``proxy/direct`
59+
- `priority`:优先级(仅 `priority_mode=number` 时生效)
60+
- `ip_cidrs_v4`:IPv4 CIDR 字符串数组
61+
- `ip_cidrs_v6`:IPv6 CIDR 字符串数组
62+
- `domains`:域名模式数组(支持通配符、`.example.com` 语义)
63+
- `ports`:端口/端口范围字符串数组(如 `443` / `10000-20000`
64+
- `protocols`:协议数组(当前主要使用 `tcp`
65+
66+
## 导入/导出行为
67+
68+
- **导入**:读取 JSON → 归一化(枚举小写、缺省字段补齐、数值范围防御性回退)
69+
- 对应实现:`resources/config-web/index.html``normalizeForm()`(见 L1314-L1428)
70+
- **导出**:以导入的原始 JSON 为底(保留未知字段),再“对象级覆盖”已知字段,最后 `JSON.stringify(..., null, 2)` 导出
71+
- 对应实现:`exportObject()`(见 `resources/config-web/index.html` L1445-L1502)
72+
73+
## 实时校验规则(前端)
74+
75+
校验集中在 `validateAll()`(见 `resources/config-web/index.html` L1505-L1677),重点包括:
76+
77+
- **端口**
78+
- `proxy.port`:允许 `0-65535`,其中 `0` 表示禁用代理(后端确有该语义)
79+
- `proxy_rules.allowed_ports[]`:必须为 `1-65535` 且不能为 `0`
80+
- `RoutingRule.ports[]`:支持 `80``10000-20000`,且端口必须 `1-65535`
81+
- **CIDR**
82+
- `fake_ip.cidr`:要求 IPv4 CIDR
83+
- `RoutingRule.ip_cidrs_v4/ip_cidrs_v6`:分别校验 v4/v6 CIDR
84+
- **枚举值**`log_level``proxy.type``child_injection_mode``dns_mode/ipv6_mode/udp_mode``priority_mode/default_action`
85+
86+
## 构建/发布集成说明
87+
88+
- `build.ps1`:新增 Step 10 复制配置工具到 `output/config-web.html``build.ps1` L502-L513)
89+
- `release.yml`:在打包前兜底复制并在缺失时失败(`.github/workflows/release.yml` L84-L105)
90+
91+
## 已知限制/注意事项
92+
93+
- **联网依赖**:Tailwind 与 Font Awesome 通过 CDN 加载;离线环境下 UI 可能无样式/无图标。
94+
- **剪贴板**`file://` 场景下浏览器可能限制 `navigator.clipboard`,复制按钮失败会提示。
95+
96+
## 维护建议(当 Config.hpp 变更时)
97+
98+
`src/core/Config.hpp` 新增/调整字段时,优先同步以下 3 处以避免遗漏:
99+
100+
1. `defaultForm()`:新增字段默认值
101+
2. `normalizeForm()`:导入归一化策略(小写/回退/类型修正)
102+
3. `validateAll()`:新增字段校验与错误提示
103+

0 commit comments

Comments
 (0)