mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 07:00:12 +01:00
🎨 数据同步前先判断网络连通性 Fix https://github.com/siyuan-note/siyuan/issues/7156
This commit is contained in:
parent
1a00b75192
commit
bdab8961b3
2 changed files with 25 additions and 21 deletions
|
|
@ -17,15 +17,29 @@
|
|||
package util
|
||||
|
||||
import (
|
||||
"github.com/imroc/req/v3"
|
||||
"github.com/siyuan-note/httpclient"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/88250/gulu"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/olahol/melody"
|
||||
)
|
||||
|
||||
func IsOnline() bool {
|
||||
c := req.C().SetTimeout(1 * time.Second)
|
||||
resp, err := c.R().Get("https://icanhazip.com")
|
||||
if nil != err {
|
||||
resp, err = c.R().Get("https://api.ipify.org")
|
||||
if nil != err {
|
||||
resp, err = c.R().Get("https://www.baidu.com")
|
||||
}
|
||||
}
|
||||
return nil == err && nil != resp && 200 == resp.StatusCode
|
||||
}
|
||||
|
||||
func GetRemoteAddr(session *melody.Session) string {
|
||||
ret := session.Request.Header.Get("X-forwarded-for")
|
||||
ret = strings.TrimSpace(ret)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue