feat(instance): refactor modify endpoint to support config types
- Change modify endpoint from `/modify/{field}` to `/modify` with POST
- Add support for two modification types: configFile and systemConfig
- Implement config file parsing using ini package for configFile type
- Update database schema to include name in update query
- Add comprehensive input validation and error handling
- Update documentation to reflect new API changes
This commit is contained in:
@@ -261,12 +261,12 @@ X-Timestamp: 1704067200000
|
||||
|
||||
### 5. Modify frpc Instance
|
||||
|
||||
**Endpoint:** `/frpcAct/instanceMgr/modify/{field}`
|
||||
**Endpoint:** `/frpcAct/instanceMgr/modify`
|
||||
**Method:** POST
|
||||
**Content-Type:** application/json
|
||||
**Auth Required:** Yes (token)
|
||||
|
||||
You can modify multiple fields at once:
|
||||
Modify instance configuration. Supports two modification types: `configFile` (modify frpc config file) and `systemConfig` (modify system-level settings).
|
||||
|
||||
**Request Headers:**
|
||||
```
|
||||
@@ -274,27 +274,83 @@ X-Token: your_token
|
||||
X-Timestamp: 1704067200000
|
||||
```
|
||||
|
||||
#### Type 1: Modify Config File (configFile)
|
||||
|
||||
Modify fields in the `[common]` section of the frpc configuration file. Only `[common]` section fields can be modified, `[[proxies]]` sections will not be affected.
|
||||
|
||||
**Request Body:**
|
||||
```json
|
||||
{
|
||||
"instanceName": "my_frpc",
|
||||
"name": "new_name",
|
||||
"serverAddr": "192.168.1.1",
|
||||
"serverPort": "7000",
|
||||
"auth_method": "token",
|
||||
"runUser": "www-data",
|
||||
"bootAtStart": false
|
||||
"instanceID": "1",
|
||||
"type": "configFile",
|
||||
"modifiedData": {
|
||||
"server_addr": "192.168.1.1",
|
||||
"server_port": "7000",
|
||||
"auth_method": "token",
|
||||
"auth_token": "my_secret_token"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
|-------|------|----------|-------------|
|
||||
| instanceName | string | Yes | Current instance name |
|
||||
| instanceID | string | Yes | Instance ID |
|
||||
| type | string | Yes | Modification type: `configFile` or `systemConfig` |
|
||||
| modifiedData | object | Yes | Key-value pairs of fields to modify in `[common]` section |
|
||||
|
||||
**Response:**
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "instance modified successfully",
|
||||
"message": "Config file modified successfully",
|
||||
"data": {
|
||||
"name": "new_name",
|
||||
"configPath": "./configs/superfrpc_user_new_name.toml"
|
||||
"instanceName": "my_frpc",
|
||||
"instanceID": 1,
|
||||
"configPath": "./configs/superfrpc_user_my_frpc.toml"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### Type 2: Modify System Config (systemConfig)
|
||||
|
||||
Modify system-level settings such as instance name, boot-at-start configuration, and run user. These changes will also update the operating system service configuration.
|
||||
|
||||
**Request Body:**
|
||||
```json
|
||||
{
|
||||
"instanceName": "my_frpc",
|
||||
"instanceID": "1",
|
||||
"type": "systemConfig",
|
||||
"modifiedData": {
|
||||
"name": "new_frpc_name",
|
||||
"bootAtStart": true,
|
||||
"runUser": "www-data"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
|-------|------|----------|-------------|
|
||||
| instanceName | string | Yes | Current instance name |
|
||||
| instanceID | string | Yes | Instance ID |
|
||||
| type | string | Yes | Modification type: `configFile` or `systemConfig` |
|
||||
| modifiedData.name | string | No | New instance name (renames config file if changed) |
|
||||
| modifiedData.bootAtStart | bool | No | Auto-start on system boot |
|
||||
| modifiedData.runUser | string | No | User to run the frpc instance as |
|
||||
|
||||
**Response:**
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "System config modified successfully",
|
||||
"data": {
|
||||
"instanceName": "new_frpc_name",
|
||||
"instanceID": 1,
|
||||
"configPath": "./configs/superfrpc_user_new_frpc_name.toml",
|
||||
"bootAtStart": true,
|
||||
"runUser": "www-data"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user