mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-03 15:22:31 +08:00
🎨 Add kernel API /api/network/forwardProxy
https://github.com/siyuan-note/siyuan/issues/8724
This commit is contained in:
parent
c78cbe067d
commit
5d7c6d47bf
48
API.md
48
API.md
@ -52,6 +52,8 @@
|
|||||||
* [Notification](#Notification)
|
* [Notification](#Notification)
|
||||||
* [Push message](#Push-message)
|
* [Push message](#Push-message)
|
||||||
* [Push error message](#Push-error-message)
|
* [Push error message](#Push-error-message)
|
||||||
|
* [Network](#Network)
|
||||||
|
* [Forward proxy](#Forward-proxy)
|
||||||
* [System](#System)
|
* [System](#System)
|
||||||
* [Get boot progress](#Get-boot-progress)
|
* [Get boot progress](#Get-boot-progress)
|
||||||
* [Get system version](#Get-system-version)
|
* [Get system version](#Get-system-version)
|
||||||
@ -1207,6 +1209,52 @@ View API token in <kbd>Settings - About</kbd>, request header: `Authorization: T
|
|||||||
```
|
```
|
||||||
* `id`: Message ID
|
* `id`: Message ID
|
||||||
|
|
||||||
|
## Network
|
||||||
|
|
||||||
|
### Forward proxy
|
||||||
|
|
||||||
|
* `/api/network/forkProxy`
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"url": "https://b3log.org/siyuan/",
|
||||||
|
"method": "GET",
|
||||||
|
"timeout": 7000,
|
||||||
|
"contentType": "text/html",
|
||||||
|
"headers": [
|
||||||
|
{
|
||||||
|
"Cookie": ""
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"payload": {}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
* `url`: URL to forward
|
||||||
|
* `method`: HTTP method, default is `POST`
|
||||||
|
* `timeout`: timeout in milliseconds, default is `7000`
|
||||||
|
* `contentType`: Content-Type, default is `application/json`
|
||||||
|
* `headers`: HTTP headers
|
||||||
|
* `payload`: HTTP payload, object or string
|
||||||
|
* Return value
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"code": 0,
|
||||||
|
"msg": "",
|
||||||
|
"data": {
|
||||||
|
"body": "",
|
||||||
|
"contentType": "text/html",
|
||||||
|
"elapsed": 1976,
|
||||||
|
"headers": {
|
||||||
|
},
|
||||||
|
"status": 200,
|
||||||
|
"url": "https://b3log.org/siyuan"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## System
|
## System
|
||||||
|
|
||||||
### Get boot progress
|
### Get boot progress
|
||||||
|
48
API_zh_CN.md
48
API_zh_CN.md
@ -52,6 +52,8 @@
|
|||||||
* [通知](#通知)
|
* [通知](#通知)
|
||||||
* [推送消息](#推送消息)
|
* [推送消息](#推送消息)
|
||||||
* [推送报错消息](#推送报错消息)
|
* [推送报错消息](#推送报错消息)
|
||||||
|
* [网络](#网络)
|
||||||
|
* [正向代理](#正向代理)
|
||||||
* [系统](#系统)
|
* [系统](#系统)
|
||||||
* [获取启动进度](#获取启动进度)
|
* [获取启动进度](#获取启动进度)
|
||||||
* [获取系统版本](#获取系统版本)
|
* [获取系统版本](#获取系统版本)
|
||||||
@ -1197,6 +1199,52 @@
|
|||||||
```
|
```
|
||||||
* `id`:消息 ID
|
* `id`:消息 ID
|
||||||
|
|
||||||
|
## 网络
|
||||||
|
|
||||||
|
### 正向代理
|
||||||
|
|
||||||
|
* `/api/network/forkProxy`
|
||||||
|
* 参数
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"url": "https://b3log.org/siyuan/",
|
||||||
|
"method": "GET",
|
||||||
|
"timeout": 7000,
|
||||||
|
"contentType": "text/html",
|
||||||
|
"headers": [
|
||||||
|
{
|
||||||
|
"Cookie": ""
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"payload": {}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
* `url`:转发的 URL
|
||||||
|
* `method`:HTTP 方法,默认为 `GET`
|
||||||
|
* `timeout`:超时时间,单位为毫秒,默认为 `7000` 毫秒
|
||||||
|
* `contentType`:HTTP Content-Type,默认为 `application/json`
|
||||||
|
* `headers`:HTTP 请求标头
|
||||||
|
* `payload`:HTTP 请求体,对象或者是字符串
|
||||||
|
* 返回值
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"code": 0,
|
||||||
|
"msg": "",
|
||||||
|
"data": {
|
||||||
|
"body": "",
|
||||||
|
"contentType": "text/html",
|
||||||
|
"elapsed": 1976,
|
||||||
|
"headers": {
|
||||||
|
},
|
||||||
|
"status": 200,
|
||||||
|
"url": "https://b3log.org/siyuan"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## 系统
|
## 系统
|
||||||
|
|
||||||
### 获取启动进度
|
### 获取启动进度
|
||||||
|
@ -46,10 +46,12 @@ func forwardProxy(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
method := strings.ToUpper(arg["method"].(string))
|
method := "POST"
|
||||||
timeoutArg := arg["timeout"]
|
if methodArg := arg["method"]; nil != methodArg {
|
||||||
|
method = strings.ToUpper(methodArg.(string))
|
||||||
|
}
|
||||||
timeout := 7 * 1000
|
timeout := 7 * 1000
|
||||||
if nil != timeoutArg {
|
if timeoutArg := arg["timeout"]; nil != timeoutArg {
|
||||||
timeout = int(timeoutArg.(float64))
|
timeout = int(timeoutArg.(float64))
|
||||||
if 1 > timeout {
|
if 1 > timeout {
|
||||||
timeout = 7 * 1000
|
timeout = 7 * 1000
|
||||||
@ -66,14 +68,13 @@ func forwardProxy(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
contentType := arg["contentType"]
|
contentType := "application/json"
|
||||||
if nil != contentType && "" != contentType {
|
if contentTypeArg := arg["contentType"]; nil != contentTypeArg {
|
||||||
request.SetHeader("Content-Type", contentType.(string))
|
contentType = contentTypeArg.(string)
|
||||||
}
|
}
|
||||||
|
request.SetHeader("Content-Type", contentType)
|
||||||
|
|
||||||
if "POST" == method {
|
|
||||||
request.SetBody(arg["payload"])
|
request.SetBody(arg["payload"])
|
||||||
}
|
|
||||||
|
|
||||||
started := time.Now()
|
started := time.Now()
|
||||||
resp, err := request.Send(method, destURL)
|
resp, err := request.Send(method, destURL)
|
||||||
|
Loading…
Reference in New Issue
Block a user