mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-19 02:21:38 +08:00
🎨 Add retry to improve network check
This commit is contained in:
parent
5ad353f238
commit
de1c01a2e8
@ -576,7 +576,7 @@ func isProviderOnline() (ret bool) {
|
|||||||
checkURL = Conf.Sync.WebDAV.Endpoint
|
checkURL = Conf.Sync.WebDAV.Endpoint
|
||||||
default:
|
default:
|
||||||
logging.LogWarnf("unknown provider: %d", Conf.Sync.Provider)
|
logging.LogWarnf("unknown provider: %d", Conf.Sync.Provider)
|
||||||
util.IsOnline("")
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if ret = util.IsOnline(checkURL); !ret {
|
if ret = util.IsOnline(checkURL); !ret {
|
||||||
|
@ -33,19 +33,6 @@ import (
|
|||||||
|
|
||||||
func IsOnline(checkURL string) bool {
|
func IsOnline(checkURL string) bool {
|
||||||
if "" == checkURL {
|
if "" == checkURL {
|
||||||
if isOnline("https://www.baidu.com") {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
if isOnline("https://icanhazip.com") {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
if isOnline("https://api.ipify.org") {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
logging.LogWarnf("network is offline")
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,10 +44,16 @@ func IsOnline(checkURL string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func isOnline(checkURL string) bool {
|
func isOnline(checkURL string) (ret bool) {
|
||||||
c := req.C().SetTimeout(1 * time.Second)
|
for i := 0; i < 3; i++ {
|
||||||
|
c := req.C().SetTimeout(3 * time.Second)
|
||||||
_, err := c.R().Head(checkURL)
|
_, err := c.R().Head(checkURL)
|
||||||
return nil == err
|
ret = nil == err
|
||||||
|
if ret {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetRemoteAddr(session *melody.Session) string {
|
func GetRemoteAddr(session *melody.Session) string {
|
||||||
|
Loading…
Reference in New Issue
Block a user