🎨 Improve network online check of data sync Fix https://github.com/siyuan-note/siyuan/issues/7890

This commit is contained in:
Liang Ding 2023-04-05 19:54:13 +08:00
parent d99e8cad9b
commit 635eb66da9
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
2 changed files with 13 additions and 6 deletions

View file

@ -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