Skip to content

Commit 995b39e

Browse files
author
githubnull
committed
docs(api): 添加完整API参考文档
- 新增包含认证、配置管理、请求头管理、扫描配置预设等模块的完整API文档 - 详细说明各接口的HTTP方法、路径、请求参数和响应格式 - 介绍登录、令牌刷新、认证检查等认证相关API - 说明临时文件目录配置的获取、设置与重置接口 - 详细描述持久化请求头规则和会话性请求头的管理操作 - 包含请求头处理预览及系统统计信息获取接口 - 支持扫描配置预设的列表获取、创建、更新和删除操作 - 提供接口调用的示例代码和错误处理指南 - 规范接口返回的状态码及统一响应格式
1 parent 8130d09 commit 995b39e

220 files changed

Lines changed: 55417 additions & 21797 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.qoder/repowiki/zh/content/API参考/API参考.md

Lines changed: 2156 additions & 0 deletions
Large diffs are not rendered by default.

.qoder/repowiki/zh/content/API参考/Web任务API.md

Lines changed: 370 additions & 0 deletions
Large diffs are not rendered by default.

.qoder/repowiki/zh/content/API参考/扫描预设API.md

Lines changed: 566 additions & 0 deletions
Large diffs are not rendered by default.

.qoder/repowiki/zh/content/API参考/认证API.md

Lines changed: 410 additions & 0 deletions
Large diffs are not rendered by default.

.qoder/repowiki/zh/content/API参考/请求头API.md

Lines changed: 347 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
1+
# 配置API
2+
3+
<cite>
4+
**本文档引用的文件**
5+
- [configController.py](file://src/backEnd/api/commonApi/configController.py)
6+
- [Task.py](file://src/backEnd/model/Task.py)
7+
- [BaseResponseMsg.py](file://src/backEnd/model/BaseResponseMsg.py)
8+
- [auth.py](file://src/backEnd/utils/auth.py)
9+
- [config.ts](file://src/frontEnd/src/stores/config.ts)
10+
- [request.ts](file://src/frontEnd/src/api/request.ts)
11+
- [index.vue](file://src/frontEnd/src/views/Config/index.vue)
12+
- [app.py](file://src/backEnd/app.py)
13+
</cite>
14+
15+
## 目录
16+
1. [简介](#简介)
17+
2. [项目结构](#项目结构)
18+
3. [核心组件](#核心组件)
19+
4. [架构概述](#架构概述)
20+
5. [详细组件分析](#详细组件分析)
21+
6. [依赖分析](#依赖分析)
22+
7. [性能考虑](#性能考虑)
23+
8. [故障排除指南](#故障排除指南)
24+
9. [结论](#结论)
25+
10. [附录](#附录)(如有必要)
26+
27+
## 简介
28+
本文档详细介绍了SQLMapWebUI系统中的配置管理API,重点分析了`configController.py`中提供的所有配置管理接口。文档涵盖了系统配置的读取、更新操作,包括HTTP请求临时文件目录等参数的API调用方式。详细说明了配置数据的持久化机制、默认值处理逻辑、配置变更后的热加载机制以及对现有任务的影响。提供了完整的请求/响应示例、配置验证规则和错误处理策略,确保开发者能够正确地远程管理系统配置。
29+
30+
## 项目结构
31+
本项目采用分层架构,前端和后端分离。后端API位于`src/backEnd/api/commonApi/`目录下,其中`configController.py`文件专门负责配置管理相关的API接口。配置数据的持久化和业务逻辑处理由`src/backEnd/model/Task.py`中的函数实现。前端通过`src/frontEnd/src/views/Config/`目录下的Vue组件与这些API进行交互。
32+
33+
```mermaid
34+
graph TB
35+
subgraph "前端"
36+
ConfigView[配置页面]
37+
ConfigStore[配置状态管理]
38+
end
39+
subgraph "后端"
40+
ConfigController[configController.py]
41+
TaskModel[Task.py]
42+
BaseResponse[BaseResponseMsg.py]
43+
end
44+
ConfigView --> ConfigStore
45+
ConfigStore --> ConfigController
46+
ConfigController --> TaskModel
47+
ConfigController --> BaseResponse
48+
```
49+
50+
**Diagram sources**
51+
- [configController.py](file://src/backEnd/api/commonApi/configController.py)
52+
- [Task.py](file://src/backEnd/model/Task.py)
53+
- [config.ts](file://src/frontEnd/src/stores/config.ts)
54+
- [index.vue](file://src/frontEnd/src/views/Config/index.vue)
55+
56+
**Section sources**
57+
- [configController.py](file://src/backEnd/api/commonApi/configController.py)
58+
- [Task.py](file://src/backEnd/model/Task.py)
59+
- [app.py](file://src/backEnd/app.py)
60+
61+
## 核心组件
62+
`configController.py`是配置管理的核心组件,提供了获取、设置和重置HTTP请求临时文件目录的API接口。该组件依赖于`Task.py`中的全局变量来存储和管理配置状态,通过`BaseResponseMsg`类统一API响应格式,并使用`auth.py`中的认证机制确保接口安全。
63+
64+
**Section sources**
65+
- [configController.py](file://src/backEnd/api/commonApi/configController.py)
66+
- [Task.py](file://src/backEnd/model/Task.py)
67+
- [BaseResponseMsg.py](file://src/backEnd/model/BaseResponseMsg.py)
68+
69+
## 架构概述
70+
系统配置API采用典型的RESTful架构,通过HTTP方法(GET、POST)对配置资源进行操作。前端通过Axios库发送请求,后端FastAPI框架处理请求并返回JSON格式的响应。配置数据存储在内存中的全局变量里,实现了配置的热加载,无需重启服务即可生效。
71+
72+
```mermaid
73+
sequenceDiagram
74+
participant 前端 as 前端应用
75+
participant 后端 as 后端API
76+
participant 模型 as Task模型
77+
前端->>后端 : GET /api/config/temp-dir
78+
后端->>模型 : get_http_request_temp_dir()
79+
模型-->>后端 : 返回当前目录
80+
后端-->>前端 : {currentTempDir, defaultTempDir, isCustom}
81+
前端->>后端 : POST /api/config/temp-dir
82+
后端->>模型 : set_http_request_temp_dir(path)
83+
模型-->>后端 : 配置更新
84+
后端-->>前端 : {currentTempDir, defaultTempDir, isCustom}
85+
```
86+
87+
**Diagram sources**
88+
- [configController.py](file://src/backEnd/api/commonApi/configController.py)
89+
- [Task.py](file://src/backEnd/model/Task.py)
90+
- [request.ts](file://src/frontEnd/src/api/request.ts)
91+
92+
## 详细组件分析
93+
94+
### 配置控制器分析
95+
`configController.py`文件实现了三个主要的API端点,用于管理HTTP请求的临时文件目录。
96+
97+
#### API端点
98+
- `GET /config/temp-dir`: 获取当前的临时文件目录配置。
99+
- `POST /config/temp-dir`: 设置临时文件目录,支持自定义路径或恢复默认值。
100+
- `POST /config/temp-dir/reset`: 重置临时文件目录为默认值。
101+
102+
#### 请求/响应示例
103+
**获取配置请求**
104+
```http
105+
GET /api/config/temp-dir HTTP/1.1
106+
Authorization: Bearer secret-token
107+
```
108+
109+
**获取配置响应**
110+
```json
111+
{
112+
"code": 200,
113+
"success": true,
114+
"message": "success",
115+
"data": {
116+
"currentTempDir": "/path/to/custom/temp",
117+
"defaultTempDir": "/path/to/backend/temp/http_requests",
118+
"isCustom": true
119+
}
120+
}
121+
```
122+
123+
**设置配置请求**
124+
```http
125+
POST /api/config/temp-dir HTTP/1.1
126+
Authorization: Bearer secret-token
127+
Content-Type: application/json
128+
129+
{
130+
"tempDir": "/new/custom/path"
131+
}
132+
```
133+
134+
**设置配置响应**
135+
```json
136+
{
137+
"code": 200,
138+
"success": true,
139+
"message": "Temp directory set to /new/custom/path",
140+
"data": {
141+
"currentTempDir": "/new/custom/path",
142+
"defaultTempDir": "/path/to/backend/temp/http_requests",
143+
"isCustom": true
144+
}
145+
}
146+
```
147+
148+
#### 配置验证规则
149+
- **路径存在性**: 如果提供的路径不存在,系统会尝试自动创建。
150+
- **可写性**: 系统会检查目录是否可写,如果不可写则返回400错误。
151+
- **空值处理**: 如果`tempDir`字段为空或null,系统会将其视为恢复默认值的请求。
152+
153+
#### 错误处理策略
154+
- **500内部服务器错误**: 当发生未预期的异常时返回,如文件系统操作失败。
155+
- **400错误请求**: 当目录不可写或创建失败时返回。
156+
- **401未授权**: 当请求缺少有效认证令牌时返回。
157+
158+
```mermaid
159+
flowchart TD
160+
Start([开始]) --> ValidateInput["验证输入参数"]
161+
ValidateInput --> InputValid{"路径为空?"}
162+
InputValid --> |是| SetToDefault["设置为默认值"]
163+
InputValid --> |否| CheckPath["检查路径是否存在"]
164+
CheckPath --> PathExists{"路径存在?"}
165+
PathExists --> |否| CreatePath["尝试创建路径"]
166+
CreatePath --> CreateSuccess{"创建成功?"}
167+
CreateSuccess --> |否| ReturnError400["返回400错误"]
168+
CreateSuccess --> |是| CheckWritable["检查目录可写性"]
169+
PathExists --> |是| CheckWritable
170+
CheckWritable --> Writable{"可写?"}
171+
Writable --> |否| ReturnError400
172+
Writable --> |是| UpdateConfig["更新配置"]
173+
UpdateConfig --> ReturnSuccess["返回200成功"]
174+
ReturnError400 --> End([结束])
175+
ReturnSuccess --> End
176+
```
177+
178+
**Diagram sources**
179+
- [configController.py](file://src/backEnd/api/commonApi/configController.py#L67-L137)
180+
- [Task.py](file://src/backEnd/model/Task.py#L35-L46)
181+
182+
**Section sources**
183+
- [configController.py](file://src/backEnd/api/commonApi/configController.py)
184+
- [Task.py](file://src/backEnd/model/Task.py)
185+
186+
### 配置数据模型分析
187+
`Task.py`文件中的全局变量`_custom_temp_dir``_DEFAULT_TEMP_DIR`构成了配置数据的核心。`_DEFAULT_TEMP_DIR`在服务启动时基于当前工作目录确定,而`_custom_temp_dir`则用于存储用户自定义的配置。
188+
189+
#### 配置持久化机制
190+
配置数据通过内存中的全局变量实现持久化。`set_http_request_temp_dir`函数负责更新`_custom_temp_dir`的值,而`get_http_request_temp_dir`函数则根据`_custom_temp_dir`是否为`None`来决定返回自定义路径还是默认路径。
191+
192+
#### 默认值处理逻辑
193+
默认的临时文件目录为后端服务启动目录下的`temp/http_requests`子目录。当用户未设置自定义路径或执行重置操作时,系统将使用此默认路径。
194+
195+
#### 热加载机制
196+
由于配置存储在内存变量中,任何通过API进行的配置更改都会立即生效,无需重启服务。这种热加载机制确保了配置变更的即时性,对现有任务的影响仅限于新创建的任务将使用新的临时文件目录。
197+
198+
**Section sources**
199+
- [Task.py](file://src/backEnd/model/Task.py#L22-L46)
200+
201+
## 依赖分析
202+
配置API依赖于多个核心组件,形成了清晰的依赖链。
203+
204+
```mermaid
205+
graph LR
206+
configController --> Task
207+
configController --> BaseResponseMsg
208+
configController --> auth
209+
Task --> BaseResponseMsg
210+
index.vue --> configController
211+
request.ts --> configController
212+
```
213+
214+
**Diagram sources**
215+
- [configController.py](file://src/backEnd/api/commonApi/configController.py)
216+
- [Task.py](file://src/backEnd/model/Task.py)
217+
- [BaseResponseMsg.py](file://src/backEnd/model/BaseResponseMsg.py)
218+
- [auth.py](file://src/backEnd/utils/auth.py)
219+
- [request.ts](file://src/frontEnd/src/api/request.ts)
220+
- [index.vue](file://src/frontEnd/src/views/Config/index.vue)
221+
222+
**Section sources**
223+
- [configController.py](file://src/backEnd/api/commonApi/configController.py)
224+
- [Task.py](file://src/backEnd/model/Task.py)
225+
- [BaseResponseMsg.py](file://src/backEnd/model/BaseResponseMsg.py)
226+
- [auth.py](file://src/backEnd/utils/auth.py)
227+
228+
## 性能考虑
229+
配置API的性能主要受文件系统操作的影响。在设置自定义目录时,系统会进行路径创建和可写性检查,这些操作在大多数情况下都非常快速。由于配置数据存储在内存中,读取操作几乎没有性能开销。建议避免频繁更改配置,以减少不必要的文件系统调用。
230+
231+
## 故障排除指南
232+
当配置API出现问题时,可以按照以下步骤进行排查:
233+
234+
1. **检查认证**: 确保请求头中包含有效的`Authorization`令牌。
235+
2. **验证路径**: 确认提供的路径格式正确,且应用有权限访问该目录。
236+
3. **查看日志**: 检查后端日志文件,查找与配置操作相关的错误信息。
237+
4. **权限问题**: 确保目标目录具有适当的读写权限。
238+
5. **磁盘空间**: 检查目标磁盘是否有足够的可用空间。
239+
240+
**Section sources**
241+
- [configController.py](file://src/backEnd/api/commonApi/configController.py)
242+
- [Task.py](file://src/backEnd/model/Task.py)
243+
244+
## 结论
245+
本文档全面介绍了SQLMapWebUI的配置管理API,涵盖了从接口定义到内部实现的各个方面。通过`configController.py`提供的API,开发者可以灵活地管理系统的临时文件目录配置。配置的热加载机制和内存持久化确保了高效率和即时生效。结合详细的错误处理和验证规则,该API为系统的稳定运行提供了有力保障。

0 commit comments

Comments
 (0)