Skip to content

Commit

Permalink
🎨 Proxy setting sometimes cancel requests #9725
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Nov 24, 2023
1 parent 1bab542 commit b1985ea
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,10 @@ const boot = () => {
currentWindow.webContents.userAgent = "SiYuan/" + appVer + " https://b3log.org/siyuan Electron " + currentWindow.webContents.userAgent;

// set proxy
net.fetch(getServer() + "/api/system/getConf", {method: "POST"}).then((response) => {
net.fetch(getServer() + "/api/system/getNetwork", {method: "POST"}).then((response) => {
return response.json();
}).then((response) => {
setProxy(`${response.data.conf.system.networkProxy.scheme}://${response.data.conf.system.networkProxy.host}:${response.data.conf.system.networkProxy.port}`, currentWindow.webContents).then(() => {
setProxy(`${response.data.proxy.scheme}://${response.data.proxy.host}:${response.data.proxy.port}`, currentWindow.webContents).then(() => {
// 加载主界面
currentWindow.loadURL(getServer() + "/stage/build/app/index.html?v=" + new Date().getTime());
});
Expand Down
2 changes: 1 addition & 1 deletion kernel/api/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func ServeAPI(ginServer *gin.Engine) {
ginServer.Handle("POST", "/api/system/logoutAuth", model.LogoutAuth)
ginServer.Handle("GET", "/api/system/getCaptcha", model.GetCaptcha)
ginServer.Handle("POST", "/api/system/setUILayout", setUILayout) // 这里不加鉴权 After modifying the access authentication code on the browser side, the other side does not refresh https://github.com/siyuan-note/siyuan/issues/8028

ginServer.Handle("POST", "/api/system/getNetwork", getNetwork) // 启动时获取网络设置,不能加鉴权
ginServer.Handle("GET", "/snippets/*filepath", serveSnippets)

// 需要鉴权
Expand Down
16 changes: 16 additions & 0 deletions kernel/api/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,22 @@ import (
"github.com/siyuan-note/siyuan/kernel/util"
)

func getNetwork(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)

maskedConf, err := model.GetMaskedConf()
if nil != err {
ret.Code = -1
ret.Msg = "get conf failed: " + err.Error()
return
}

ret.Data = map[string]interface{}{
"proxy": maskedConf.System.NetworkProxy,
}
}

func getChangelog(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)
Expand Down

0 comments on commit b1985ea

Please sign in to comment.