@tachybase/module-cloud-component 1.6.1 → 1.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/README.md +1 -1
  2. package/client.d.ts +2 -2
  3. package/client.js +1 -1
  4. package/dist/externalVersion.js +3 -3
  5. package/dist/locale/en-US.json +64 -64
  6. package/dist/locale/zh-CN.json +65 -65
  7. package/dist/node_modules/@babel/core/lib/index.js +8 -8
  8. package/dist/node_modules/@babel/core/node_modules/.bin/json5 +2 -2
  9. package/dist/node_modules/@babel/core/node_modules/.bin/json5.CMD +12 -0
  10. package/dist/node_modules/@babel/core/node_modules/.bin/json5.ps1 +41 -0
  11. package/dist/node_modules/@babel/core/node_modules/.bin/parser +2 -2
  12. package/dist/node_modules/@babel/core/node_modules/.bin/parser.CMD +12 -0
  13. package/dist/node_modules/@babel/core/node_modules/.bin/parser.ps1 +41 -0
  14. package/dist/node_modules/@babel/core/node_modules/.bin/semver +2 -2
  15. package/dist/node_modules/@babel/core/node_modules/.bin/semver.CMD +12 -0
  16. package/dist/node_modules/@babel/core/node_modules/.bin/semver.ps1 +41 -0
  17. package/dist/node_modules/@babel/core/package.json +1 -1
  18. package/dist/node_modules/@babel/parser/package.json +1 -1
  19. package/dist/node_modules/@babel/preset-env/lib/index.js +22 -22
  20. package/dist/node_modules/@babel/preset-env/node_modules/.bin/semver +2 -2
  21. package/dist/node_modules/@babel/preset-env/node_modules/.bin/semver.CMD +12 -0
  22. package/dist/node_modules/@babel/preset-env/node_modules/.bin/semver.ps1 +41 -0
  23. package/dist/node_modules/@babel/preset-env/package.json +1 -1
  24. package/dist/node_modules/@babel/preset-react/lib/index.js +10 -10
  25. package/dist/node_modules/@babel/preset-react/package.json +1 -1
  26. package/dist/node_modules/@babel/preset-typescript/lib/index.js +8 -8
  27. package/dist/node_modules/@babel/preset-typescript/package.json +1 -1
  28. package/dist/node_modules/@babel/traverse/node_modules/.bin/parser +2 -2
  29. package/dist/node_modules/@babel/traverse/node_modules/.bin/parser.CMD +12 -0
  30. package/dist/node_modules/@babel/traverse/node_modules/.bin/parser.ps1 +41 -0
  31. package/dist/node_modules/@babel/traverse/package.json +1 -1
  32. package/dist/node_modules/@hapi/topo/package.json +1 -1
  33. package/docs/CODE_BRANCH_PATH_LOGIC.md +140 -140
  34. package/docs/OPTIMIZATION_PLAN.md +109 -109
  35. package/docs/README.md +21 -21
  36. package/docs/REMOTE_CODE_GUIDE.md +183 -183
  37. package/docs/TESTING_AUTHENTICATION.md +128 -128
  38. package/package.json +6 -6
  39. package/server.d.ts +2 -2
  40. package/server.js +1 -1
package/docs/README.md CHANGED
@@ -1,21 +1,21 @@
1
- # 云组件插件文档 / Cloud Component Plugin Documentation
2
-
3
- ## 文档索引 / Documentation Index
4
-
5
- ### 📋 [优化计划](./OPTIMIZATION_PLAN.md)
6
- 云组件插件的优化计划和实施进度 / Optimization plan and implementation progress for the cloud component plugin
7
-
8
- ### 📖 [远程代码获取指南](./REMOTE_CODE_GUIDE.md)
9
- 远程代码获取功能的使用指南(支持 CDN 和 Git 仓库) / Guide for remote code fetching feature (supports CDN and Git repositories)
10
-
11
- ### 🔍 [代码分支和路径逻辑分析](./CODE_BRANCH_PATH_LOGIC.md)
12
- codeBranch 和 codePath 字段的获取逻辑分析和改进建议 / Analysis of codeBranch and codePath field retrieval logic and improvement suggestions
13
-
14
- ---
15
-
16
- ## 快速导航 / Quick Navigation
17
-
18
- - **开发指南**: 查看 [优化计划](./OPTIMIZATION_PLAN.md) 了解开发进度
19
- - **使用指南**: 查看 [远程代码获取指南](./REMOTE_CODE_GUIDE.md) 了解如何使用远程代码功能
20
- - **技术分析**: 查看 [代码分支和路径逻辑分析](./CODE_BRANCH_PATH_LOGIC.md) 了解实现细节
21
-
1
+ # 云组件插件文档 / Cloud Component Plugin Documentation
2
+
3
+ ## 文档索引 / Documentation Index
4
+
5
+ ### 📋 [优化计划](./OPTIMIZATION_PLAN.md)
6
+ 云组件插件的优化计划和实施进度 / Optimization plan and implementation progress for the cloud component plugin
7
+
8
+ ### 📖 [远程代码获取指南](./REMOTE_CODE_GUIDE.md)
9
+ 远程代码获取功能的使用指南(支持 CDN 和 Git 仓库) / Guide for remote code fetching feature (supports CDN and Git repositories)
10
+
11
+ ### 🔍 [代码分支和路径逻辑分析](./CODE_BRANCH_PATH_LOGIC.md)
12
+ codeBranch 和 codePath 字段的获取逻辑分析和改进建议 / Analysis of codeBranch and codePath field retrieval logic and improvement suggestions
13
+
14
+ ---
15
+
16
+ ## 快速导航 / Quick Navigation
17
+
18
+ - **开发指南**: 查看 [优化计划](./OPTIMIZATION_PLAN.md) 了解开发进度
19
+ - **使用指南**: 查看 [远程代码获取指南](./REMOTE_CODE_GUIDE.md) 了解如何使用远程代码功能
20
+ - **技术分析**: 查看 [代码分支和路径逻辑分析](./CODE_BRANCH_PATH_LOGIC.md) 了解实现细节
21
+
@@ -1,183 +1,183 @@
1
- # 远程代码获取功能使用指南 / Remote Code Fetching Guide
2
-
3
- ## 功能概述 / Overview
4
-
5
- 云组件插件现在支持从远程地址获取代码,包括:
6
- - **CDN 地址**:直接从 CDN 获取编译后的代码文件
7
- - **Git 仓库**:从 GitHub/GitLab 等 Git 仓库获取源代码
8
-
9
- The Cloud Component plugin now supports fetching code from remote sources, including:
10
- - **CDN URLs**: Fetch compiled code files directly from CDN
11
- - **Git Repositories**: Fetch source code from GitHub/GitLab repositories
12
-
13
- ## 配置方式 / Configuration
14
-
15
- ### 1. 代码来源选择 / Code Source Selection
16
-
17
- 在创建或编辑云组件时,可以选择代码来源:
18
- - **本地代码 (Local code)**: 在编辑器中直接编写代码
19
- - **远程代码 (Remote code)**: 从远程地址获取代码
20
-
21
- When creating or editing a cloud component, you can choose the code source:
22
- - **Local code**: Write code directly in the editor
23
- - **Remote code**: Fetch code from a remote URL
24
-
25
- ### 2. CDN 配置 / CDN Configuration
26
-
27
- 如果选择远程代码并配置 CDN 地址:
28
-
29
- If you choose remote code and configure a CDN URL:
30
-
31
- ```
32
- 代码来源: 远程代码
33
- 代码类型: CDN
34
- 代码地址: https://cdn.example.com/components/MyComponent.tsx
35
- ```
36
-
37
- **示例 / Example:**
38
- - `https://unpkg.com/@myorg/components@latest/dist/MyComponent.js`
39
- - `https://cdn.jsdelivr.net/npm/@myorg/components@1.0.0/dist/MyComponent.js`
40
-
41
- ### 3. Git 仓库配置 / Git Repository Configuration
42
-
43
- 如果选择远程代码并配置 Git 仓库地址:
44
-
45
- If you choose remote code and configure a Git repository URL:
46
-
47
- ```
48
- 代码来源: 远程代码
49
- 代码类型: Git
50
- 代码地址: https://github.com/owner/repo
51
- 代码分支: main (可选,默认为 main)
52
- 代码路径: src/components/MyComponent.tsx (可选)
53
- ```
54
-
55
- **支持的 Git 平台 / Supported Git Platforms:**
56
- - GitHub: `https://github.com/owner/repo`
57
- - GitLab: `https://gitlab.com/owner/repo`
58
-
59
- **示例 / Examples:**
60
-
61
- 1. **GitHub 示例 / GitHub Example:**
62
- ```
63
- 代码地址: https://github.com/myorg/cloud-components
64
- 代码分支: main
65
- 代码路径: src/components/Button.tsx
66
- ```
67
- 实际获取地址: `https://raw.githubusercontent.com/myorg/cloud-components/main/src/components/Button.tsx`
68
-
69
- 2. **GitLab 示例 / GitLab Example:**
70
- ```
71
- 代码地址: https://gitlab.com/myorg/cloud-components
72
- 代码分支: develop
73
- 代码路径: components/Button.tsx
74
- ```
75
- 实际获取地址: `https://gitlab.com/myorg/cloud-components/-/raw/develop/components/Button.tsx`
76
-
77
- ## 缓存机制 / Caching Mechanism
78
-
79
- 为了提升性能和减少网络请求,系统实现了代码缓存机制:
80
-
81
- To improve performance and reduce network requests, the system implements a code caching mechanism:
82
-
83
- - **缓存存储 / Cache Storage**: 代码缓存在数据库中,持久化保存
84
- - **缓存使用 / Cache Usage**: 如果缓存存在,直接使用缓存中的代码
85
- - **缓存更新 / Cache Update**: 首次获取或手动刷新时,从远程获取最新代码并更新缓存
86
- - **缓存失效 / Cache Fallback**: 如果远程获取失败,会使用缓存的代码作为后备
87
-
88
- - **Cache Storage**: Code cache is stored in database, persisted across restarts
89
- - **Cache Usage**: If cache exists, directly use cached code
90
- - **Cache Update**: On first fetch or manual refresh, fetch latest code from remote and update cache
91
- - **Cache Fallback**: Uses cached code if remote fetch fails
92
-
93
- ## 使用场景 / Use Cases
94
-
95
- ### 场景 1: 共享组件库 / Scenario 1: Shared Component Library
96
-
97
- 多个项目共享同一套组件,可以将组件代码存储在 Git 仓库中,各个项目通过远程地址引用:
98
-
99
- Multiple projects share the same set of components. Store component code in a Git repository and reference it via remote URLs:
100
-
101
- ```
102
- 代码地址: https://github.com/myorg/shared-components
103
- 代码分支: main
104
- 代码路径: src/components/DataTable.tsx
105
- ```
106
-
107
- ### 场景 2: CDN 分发 / Scenario 2: CDN Distribution
108
-
109
- 将组件代码发布到 CDN,通过 CDN 地址快速加载:
110
-
111
- Publish component code to CDN for fast loading:
112
-
113
- ```
114
- 代码地址: https://cdn.myorg.com/components/v1.0.0/Chart.js
115
- ```
116
-
117
- ### 场景 3: 版本管理 / Scenario 3: Version Management
118
-
119
- 通过 Git 分支管理不同版本的组件:
120
-
121
- Manage different versions of components through Git branches:
122
-
123
- ```
124
- 代码地址: https://github.com/myorg/components
125
- 代码分支: v1.0.0 (稳定版本)
126
- 代码分支: develop (开发版本)
127
- ```
128
-
129
- ## 注意事项 / Notes
130
-
131
- 1. **网络访问 / Network Access**: 确保服务器可以访问配置的远程地址
132
- 2. **代码格式 / Code Format**: 远程代码应该是有效的 TypeScript/React 代码
133
- 3. **安全性 / Security**: 只从可信的远程地址获取代码
134
- 4. **缓存策略 / Cache Strategy**: 如果需要立即获取最新代码,可以通过 `syncRemoteCode` API 手动刷新缓存
135
-
136
- 1. **Network Access**: Ensure the server can access the configured remote URL
137
- 2. **Code Format**: Remote code should be valid TypeScript/React code
138
- 3. **Security**: Only fetch code from trusted remote sources
139
- 4. **Cache Strategy**: To get the latest code immediately, manually refresh cache via `syncRemoteCode` API
140
-
141
- ## 故障排查 / Troubleshooting
142
-
143
- ### 问题: 无法获取远程代码 / Issue: Cannot fetch remote code
144
-
145
- **可能原因 / Possible Causes:**
146
- - 网络连接问题 / Network connectivity issues
147
- - URL 格式错误 / Incorrect URL format
148
- - 远程服务器不可访问 / Remote server unavailable
149
-
150
- **解决方案 / Solutions:**
151
- - 检查网络连接 / Check network connection
152
- - 验证 URL 格式 / Verify URL format
153
- - 检查远程服务器状态 / Check remote server status
154
- - 查看服务器日志 / Check server logs
155
-
156
- ### 问题: Git 仓库路径错误 / Issue: Incorrect Git repository path
157
-
158
- **解决方案 / Solutions:**
159
- - 确保代码路径相对于仓库根目录 / Ensure code path is relative to repository root
160
- - 检查文件是否存在于指定分支 / Verify file exists in specified branch
161
- - 使用正确的文件扩展名 / Use correct file extension
162
-
163
- ## API 参考 / API Reference
164
-
165
- ### RemoteCodeFetcher Service
166
-
167
- ```typescript
168
- // 获取远程代码
169
- fetchCode(
170
- codeUrl: string,
171
- codeType: 'cdn' | 'git', // 由前端指定类型
172
- codeBranch?: string, // Git 分支名称(仅 Git 类型需要)
173
- codePath?: string // Git 文件路径(仅 Git 类型需要)
174
- ): Promise<string>
175
-
176
- // 检查缓存是否有效(已废弃,不再使用时间戳验证)
177
- // 现在直接使用数据库中的缓存,不检查时间戳
178
- isCacheValid(
179
- cache: { content: string; timestamp: number } | null,
180
- maxAge?: number
181
- ): boolean // @deprecated 不再使用时间戳验证,直接使用缓存内容
182
- ```
183
-
1
+ # 远程代码获取功能使用指南 / Remote Code Fetching Guide
2
+
3
+ ## 功能概述 / Overview
4
+
5
+ 云组件插件现在支持从远程地址获取代码,包括:
6
+ - **CDN 地址**:直接从 CDN 获取编译后的代码文件
7
+ - **Git 仓库**:从 GitHub/GitLab 等 Git 仓库获取源代码
8
+
9
+ The Cloud Component plugin now supports fetching code from remote sources, including:
10
+ - **CDN URLs**: Fetch compiled code files directly from CDN
11
+ - **Git Repositories**: Fetch source code from GitHub/GitLab repositories
12
+
13
+ ## 配置方式 / Configuration
14
+
15
+ ### 1. 代码来源选择 / Code Source Selection
16
+
17
+ 在创建或编辑云组件时,可以选择代码来源:
18
+ - **本地代码 (Local code)**: 在编辑器中直接编写代码
19
+ - **远程代码 (Remote code)**: 从远程地址获取代码
20
+
21
+ When creating or editing a cloud component, you can choose the code source:
22
+ - **Local code**: Write code directly in the editor
23
+ - **Remote code**: Fetch code from a remote URL
24
+
25
+ ### 2. CDN 配置 / CDN Configuration
26
+
27
+ 如果选择远程代码并配置 CDN 地址:
28
+
29
+ If you choose remote code and configure a CDN URL:
30
+
31
+ ```
32
+ 代码来源: 远程代码
33
+ 代码类型: CDN
34
+ 代码地址: https://cdn.example.com/components/MyComponent.tsx
35
+ ```
36
+
37
+ **示例 / Example:**
38
+ - `https://unpkg.com/@myorg/components@latest/dist/MyComponent.js`
39
+ - `https://cdn.jsdelivr.net/npm/@myorg/components@1.0.0/dist/MyComponent.js`
40
+
41
+ ### 3. Git 仓库配置 / Git Repository Configuration
42
+
43
+ 如果选择远程代码并配置 Git 仓库地址:
44
+
45
+ If you choose remote code and configure a Git repository URL:
46
+
47
+ ```
48
+ 代码来源: 远程代码
49
+ 代码类型: Git
50
+ 代码地址: https://github.com/owner/repo
51
+ 代码分支: main (可选,默认为 main)
52
+ 代码路径: src/components/MyComponent.tsx (可选)
53
+ ```
54
+
55
+ **支持的 Git 平台 / Supported Git Platforms:**
56
+ - GitHub: `https://github.com/owner/repo`
57
+ - GitLab: `https://gitlab.com/owner/repo`
58
+
59
+ **示例 / Examples:**
60
+
61
+ 1. **GitHub 示例 / GitHub Example:**
62
+ ```
63
+ 代码地址: https://github.com/myorg/cloud-components
64
+ 代码分支: main
65
+ 代码路径: src/components/Button.tsx
66
+ ```
67
+ 实际获取地址: `https://raw.githubusercontent.com/myorg/cloud-components/main/src/components/Button.tsx`
68
+
69
+ 2. **GitLab 示例 / GitLab Example:**
70
+ ```
71
+ 代码地址: https://gitlab.com/myorg/cloud-components
72
+ 代码分支: develop
73
+ 代码路径: components/Button.tsx
74
+ ```
75
+ 实际获取地址: `https://gitlab.com/myorg/cloud-components/-/raw/develop/components/Button.tsx`
76
+
77
+ ## 缓存机制 / Caching Mechanism
78
+
79
+ 为了提升性能和减少网络请求,系统实现了代码缓存机制:
80
+
81
+ To improve performance and reduce network requests, the system implements a code caching mechanism:
82
+
83
+ - **缓存存储 / Cache Storage**: 代码缓存在数据库中,持久化保存
84
+ - **缓存使用 / Cache Usage**: 如果缓存存在,直接使用缓存中的代码
85
+ - **缓存更新 / Cache Update**: 首次获取或手动刷新时,从远程获取最新代码并更新缓存
86
+ - **缓存失效 / Cache Fallback**: 如果远程获取失败,会使用缓存的代码作为后备
87
+
88
+ - **Cache Storage**: Code cache is stored in database, persisted across restarts
89
+ - **Cache Usage**: If cache exists, directly use cached code
90
+ - **Cache Update**: On first fetch or manual refresh, fetch latest code from remote and update cache
91
+ - **Cache Fallback**: Uses cached code if remote fetch fails
92
+
93
+ ## 使用场景 / Use Cases
94
+
95
+ ### 场景 1: 共享组件库 / Scenario 1: Shared Component Library
96
+
97
+ 多个项目共享同一套组件,可以将组件代码存储在 Git 仓库中,各个项目通过远程地址引用:
98
+
99
+ Multiple projects share the same set of components. Store component code in a Git repository and reference it via remote URLs:
100
+
101
+ ```
102
+ 代码地址: https://github.com/myorg/shared-components
103
+ 代码分支: main
104
+ 代码路径: src/components/DataTable.tsx
105
+ ```
106
+
107
+ ### 场景 2: CDN 分发 / Scenario 2: CDN Distribution
108
+
109
+ 将组件代码发布到 CDN,通过 CDN 地址快速加载:
110
+
111
+ Publish component code to CDN for fast loading:
112
+
113
+ ```
114
+ 代码地址: https://cdn.myorg.com/components/v1.0.0/Chart.js
115
+ ```
116
+
117
+ ### 场景 3: 版本管理 / Scenario 3: Version Management
118
+
119
+ 通过 Git 分支管理不同版本的组件:
120
+
121
+ Manage different versions of components through Git branches:
122
+
123
+ ```
124
+ 代码地址: https://github.com/myorg/components
125
+ 代码分支: v1.0.0 (稳定版本)
126
+ 代码分支: develop (开发版本)
127
+ ```
128
+
129
+ ## 注意事项 / Notes
130
+
131
+ 1. **网络访问 / Network Access**: 确保服务器可以访问配置的远程地址
132
+ 2. **代码格式 / Code Format**: 远程代码应该是有效的 TypeScript/React 代码
133
+ 3. **安全性 / Security**: 只从可信的远程地址获取代码
134
+ 4. **缓存策略 / Cache Strategy**: 如果需要立即获取最新代码,可以通过 `syncRemoteCode` API 手动刷新缓存
135
+
136
+ 1. **Network Access**: Ensure the server can access the configured remote URL
137
+ 2. **Code Format**: Remote code should be valid TypeScript/React code
138
+ 3. **Security**: Only fetch code from trusted remote sources
139
+ 4. **Cache Strategy**: To get the latest code immediately, manually refresh cache via `syncRemoteCode` API
140
+
141
+ ## 故障排查 / Troubleshooting
142
+
143
+ ### 问题: 无法获取远程代码 / Issue: Cannot fetch remote code
144
+
145
+ **可能原因 / Possible Causes:**
146
+ - 网络连接问题 / Network connectivity issues
147
+ - URL 格式错误 / Incorrect URL format
148
+ - 远程服务器不可访问 / Remote server unavailable
149
+
150
+ **解决方案 / Solutions:**
151
+ - 检查网络连接 / Check network connection
152
+ - 验证 URL 格式 / Verify URL format
153
+ - 检查远程服务器状态 / Check remote server status
154
+ - 查看服务器日志 / Check server logs
155
+
156
+ ### 问题: Git 仓库路径错误 / Issue: Incorrect Git repository path
157
+
158
+ **解决方案 / Solutions:**
159
+ - 确保代码路径相对于仓库根目录 / Ensure code path is relative to repository root
160
+ - 检查文件是否存在于指定分支 / Verify file exists in specified branch
161
+ - 使用正确的文件扩展名 / Use correct file extension
162
+
163
+ ## API 参考 / API Reference
164
+
165
+ ### RemoteCodeFetcher Service
166
+
167
+ ```typescript
168
+ // 获取远程代码
169
+ fetchCode(
170
+ codeUrl: string,
171
+ codeType: 'cdn' | 'git', // 由前端指定类型
172
+ codeBranch?: string, // Git 分支名称(仅 Git 类型需要)
173
+ codePath?: string // Git 文件路径(仅 Git 类型需要)
174
+ ): Promise<string>
175
+
176
+ // 检查缓存是否有效(已废弃,不再使用时间戳验证)
177
+ // 现在直接使用数据库中的缓存,不检查时间戳
178
+ isCacheValid(
179
+ cache: { content: string; timestamp: number } | null,
180
+ maxAge?: number
181
+ ): boolean // @deprecated 不再使用时间戳验证,直接使用缓存内容
182
+ ```
183
+
@@ -1,128 +1,128 @@
1
- # 测试认证功能 / Testing Authentication
2
-
3
- ## 使用 curl 测试认证
4
-
5
- ### 测试 Bearer Token
6
-
7
- ```bash
8
- # 替换以下变量:
9
- # - YOUR_URL: 你的 Git 服务器 URL
10
- # - YOUR_TOKEN: 你的 Bearer Token
11
-
12
- curl -H "Authorization: Bearer YOUR_TOKEN" \
13
- -H "User-Agent: TegoCloudComponent/1.0" \
14
- "YOUR_URL"
15
- ```
16
-
17
- **示例:**
18
- ```bash
19
- curl -H "Authorization: Bearer glpat-xxxxxxxxxxxxxxxxxxxx" \
20
- -H "User-Agent: TegoCloudComponent/1.0" \
21
- "https://git.daoyoucloud.com/daoyoucloud/hera-rental/src/branch/main/src/add-check.tsx"
22
- ```
23
-
24
- ### 测试 Basic Auth
25
-
26
- ```bash
27
- # 替换以下变量:
28
- # - YOUR_URL: 你的 Git 服务器 URL
29
- # - YOUR_USERNAME: 你的用户名
30
- # - YOUR_PASSWORD: 你的密码
31
-
32
- curl -u "YOUR_USERNAME:YOUR_PASSWORD" \
33
- -H "User-Agent: TegoCloudComponent/1.0" \
34
- "YOUR_URL"
35
- ```
36
-
37
- **示例:**
38
- ```bash
39
- curl -u "username:password" \
40
- -H "User-Agent: TegoCloudComponent/1.0" \
41
- "https://git.daoyoucloud.com/daoyoucloud/hera-rental/src/branch/main/src/add-check.tsx"
42
- ```
43
-
44
- ### 测试无认证(对比)
45
-
46
- ```bash
47
- # 不添加认证头,测试是否会返回 401/403
48
- curl -H "User-Agent: TegoCloudComponent/1.0" \
49
- "YOUR_URL"
50
- ```
51
-
52
- ## 检查服务器日志
53
-
54
- 在服务器日志中查找以下信息:
55
-
56
- 1. **认证类型确认**:
57
- ```
58
- Fetching from URL: https://... (with token auth)
59
- Using Bearer Token authentication (token length: XX)
60
- ```
61
-
62
- 2. **请求头信息**(调试模式):
63
- ```
64
- Request headers: {"User-Agent":"TegoCloudComponent/1.0","Authorization":"Bearer xxxx..."}
65
- ```
66
-
67
- 3. **错误信息**:
68
- - `HTTP 401`: 认证失败(token 无效或过期)
69
- - `HTTP 403`: 权限不足(token 有效但无访问权限)
70
- - `HTTP 404`: URL 不存在或路径错误
71
-
72
- ## 常见问题排查
73
-
74
- ### 1. Token 格式问题
75
-
76
- 确保 token 格式正确:
77
- - **Bearer Token**: 不应该包含 "Bearer " 前缀,系统会自动添加
78
- - **Basic Auth**: 用户名和密码都不应该包含特殊字符,如果有需要 URL 编码
79
-
80
- ### 2. Token 权限问题
81
-
82
- 检查 token 是否有以下权限:
83
- - 读取仓库内容
84
- - 访问 raw 文件
85
- - 访问指定分支
86
-
87
- ### 3. URL 格式问题
88
-
89
- 确保 URL 格式正确:
90
- - 对于 GitLab 风格的服务器,URL 应该是 raw 文件 URL
91
- - 格式:`https://host/owner/repo/src/branch/branch-name/path/to/file.tsx`
92
- - 或:`https://host/owner/repo/-/raw/branch-name/path/to/file.tsx`
93
-
94
- ### 4. 检查实际发送的请求
95
-
96
- 在代码中添加临时日志,查看实际发送的请求:
97
-
98
- ```typescript
99
- // 在 remote-code-fetcher.ts 的 fetchFromCDN 方法中
100
- console.log('Actual request:', {
101
- url,
102
- headers: {
103
- ...headers,
104
- Authorization: headers.Authorization ? '[REDACTED]' : undefined
105
- }
106
- });
107
- ```
108
-
109
- ## 使用浏览器开发者工具测试
110
-
111
- 1. 打开浏览器开发者工具(F12)
112
- 2. 切换到 Network 标签
113
- 3. 在前端点击"同步远程代码"按钮
114
- 4. 查看发送的请求:
115
- - 检查请求 URL
116
- - 检查请求头中的 `Authorization` 字段
117
- - 查看响应状态码和错误信息
118
-
119
- ## 使用 Postman 或类似工具测试
120
-
121
- 1. 创建新请求
122
- 2. 设置请求方法为 GET
123
- 3. 输入 URL
124
- 4. 在 Headers 中添加:
125
- - `Authorization: Bearer YOUR_TOKEN` (Bearer Token)
126
- - 或使用 Basic Auth 标签页输入用户名和密码
127
- 5. 发送请求并查看响应
128
-
1
+ # 测试认证功能 / Testing Authentication
2
+
3
+ ## 使用 curl 测试认证
4
+
5
+ ### 测试 Bearer Token
6
+
7
+ ```bash
8
+ # 替换以下变量:
9
+ # - YOUR_URL: 你的 Git 服务器 URL
10
+ # - YOUR_TOKEN: 你的 Bearer Token
11
+
12
+ curl -H "Authorization: Bearer YOUR_TOKEN" \
13
+ -H "User-Agent: TegoCloudComponent/1.0" \
14
+ "YOUR_URL"
15
+ ```
16
+
17
+ **示例:**
18
+ ```bash
19
+ curl -H "Authorization: Bearer glpat-xxxxxxxxxxxxxxxxxxxx" \
20
+ -H "User-Agent: TegoCloudComponent/1.0" \
21
+ "https://git.daoyoucloud.com/daoyoucloud/hera-rental/src/branch/main/src/add-check.tsx"
22
+ ```
23
+
24
+ ### 测试 Basic Auth
25
+
26
+ ```bash
27
+ # 替换以下变量:
28
+ # - YOUR_URL: 你的 Git 服务器 URL
29
+ # - YOUR_USERNAME: 你的用户名
30
+ # - YOUR_PASSWORD: 你的密码
31
+
32
+ curl -u "YOUR_USERNAME:YOUR_PASSWORD" \
33
+ -H "User-Agent: TegoCloudComponent/1.0" \
34
+ "YOUR_URL"
35
+ ```
36
+
37
+ **示例:**
38
+ ```bash
39
+ curl -u "username:password" \
40
+ -H "User-Agent: TegoCloudComponent/1.0" \
41
+ "https://git.daoyoucloud.com/daoyoucloud/hera-rental/src/branch/main/src/add-check.tsx"
42
+ ```
43
+
44
+ ### 测试无认证(对比)
45
+
46
+ ```bash
47
+ # 不添加认证头,测试是否会返回 401/403
48
+ curl -H "User-Agent: TegoCloudComponent/1.0" \
49
+ "YOUR_URL"
50
+ ```
51
+
52
+ ## 检查服务器日志
53
+
54
+ 在服务器日志中查找以下信息:
55
+
56
+ 1. **认证类型确认**:
57
+ ```
58
+ Fetching from URL: https://... (with token auth)
59
+ Using Bearer Token authentication (token length: XX)
60
+ ```
61
+
62
+ 2. **请求头信息**(调试模式):
63
+ ```
64
+ Request headers: {"User-Agent":"TegoCloudComponent/1.0","Authorization":"Bearer xxxx..."}
65
+ ```
66
+
67
+ 3. **错误信息**:
68
+ - `HTTP 401`: 认证失败(token 无效或过期)
69
+ - `HTTP 403`: 权限不足(token 有效但无访问权限)
70
+ - `HTTP 404`: URL 不存在或路径错误
71
+
72
+ ## 常见问题排查
73
+
74
+ ### 1. Token 格式问题
75
+
76
+ 确保 token 格式正确:
77
+ - **Bearer Token**: 不应该包含 "Bearer " 前缀,系统会自动添加
78
+ - **Basic Auth**: 用户名和密码都不应该包含特殊字符,如果有需要 URL 编码
79
+
80
+ ### 2. Token 权限问题
81
+
82
+ 检查 token 是否有以下权限:
83
+ - 读取仓库内容
84
+ - 访问 raw 文件
85
+ - 访问指定分支
86
+
87
+ ### 3. URL 格式问题
88
+
89
+ 确保 URL 格式正确:
90
+ - 对于 GitLab 风格的服务器,URL 应该是 raw 文件 URL
91
+ - 格式:`https://host/owner/repo/src/branch/branch-name/path/to/file.tsx`
92
+ - 或:`https://host/owner/repo/-/raw/branch-name/path/to/file.tsx`
93
+
94
+ ### 4. 检查实际发送的请求
95
+
96
+ 在代码中添加临时日志,查看实际发送的请求:
97
+
98
+ ```typescript
99
+ // 在 remote-code-fetcher.ts 的 fetchFromCDN 方法中
100
+ console.log('Actual request:', {
101
+ url,
102
+ headers: {
103
+ ...headers,
104
+ Authorization: headers.Authorization ? '[REDACTED]' : undefined
105
+ }
106
+ });
107
+ ```
108
+
109
+ ## 使用浏览器开发者工具测试
110
+
111
+ 1. 打开浏览器开发者工具(F12)
112
+ 2. 切换到 Network 标签
113
+ 3. 在前端点击"同步远程代码"按钮
114
+ 4. 查看发送的请求:
115
+ - 检查请求 URL
116
+ - 检查请求头中的 `Authorization` 字段
117
+ - 查看响应状态码和错误信息
118
+
119
+ ## 使用 Postman 或类似工具测试
120
+
121
+ 1. 创建新请求
122
+ 2. 设置请求方法为 GET
123
+ 3. 输入 URL
124
+ 4. 在 Headers 中添加:
125
+ - `Authorization: Bearer YOUR_TOKEN` (Bearer Token)
126
+ - 或使用 Basic Auth 标签页输入用户名和密码
127
+ 5. 发送请求并查看响应
128
+