mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 15:10:12 +01:00
🎨 Improve network online check of data sync Fix https://github.com/siyuan-note/siyuan/issues/7890
This commit is contained in:
parent
d99e8cad9b
commit
635eb66da9
2 changed files with 13 additions and 6 deletions
|
|
@ -563,18 +563,21 @@ func planSyncAfter(d time.Duration) {
|
|||
|
||||
func isProviderOnline() (ret bool) {
|
||||
checkURL := util.SiYuanSyncServer
|
||||
skipTlsVerify := false
|
||||
switch Conf.Sync.Provider {
|
||||
case conf.ProviderSiYuan:
|
||||
case conf.ProviderS3:
|
||||
checkURL = Conf.Sync.S3.Endpoint
|
||||
skipTlsVerify = Conf.Sync.S3.SkipTlsVerify
|
||||
case conf.ProviderWebDAV:
|
||||
checkURL = Conf.Sync.WebDAV.Endpoint
|
||||
skipTlsVerify = Conf.Sync.WebDAV.SkipTlsVerify
|
||||
default:
|
||||
logging.LogWarnf("unknown provider: %d", Conf.Sync.Provider)
|
||||
return false
|
||||
}
|
||||
|
||||
if ret = util.IsOnline(checkURL); !ret {
|
||||
if ret = util.IsOnline(checkURL, skipTlsVerify); !ret {
|
||||
util.PushErrMsg(Conf.Language(76), 5000)
|
||||
}
|
||||
return
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ import (
|
|||
"github.com/siyuan-note/logging"
|
||||
)
|
||||
|
||||
func IsOnline(checkURL string) bool {
|
||||
func IsOnline(checkURL string, skipTlsVerify bool) bool {
|
||||
_, err := url.Parse(checkURL)
|
||||
if nil != err {
|
||||
logging.LogWarnf("invalid check URL [%s]", checkURL)
|
||||
|
|
@ -42,7 +42,7 @@ func IsOnline(checkURL string) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
if isOnline(checkURL) {
|
||||
if isOnline(checkURL, skipTlsVerify) {
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
@ -50,10 +50,14 @@ func IsOnline(checkURL string) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func isOnline(checkURL string) (ret bool) {
|
||||
func isOnline(checkURL string, skipTlsVerify bool) (ret bool) {
|
||||
c := req.C().SetTimeout(3 * time.Second)
|
||||
if skipTlsVerify {
|
||||
c.EnableInsecureSkipVerify()
|
||||
}
|
||||
|
||||
for i := 0; i < 3; i++ {
|
||||
c := req.C().SetTimeout(3 * time.Second)
|
||||
_, err := c.R().Head(checkURL)
|
||||
_, err := c.R().Get(checkURL)
|
||||
ret = nil == err
|
||||
if ret {
|
||||
break
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue