mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-01 21:21:47 +01:00
🎨 Use Endpoint for network connectivity checks when syncing with third-party cloud providers https://github.com/siyuan-note/siyuan/issues/7805
This commit is contained in:
parent
bdf621f8c5
commit
05daece0d1
7 changed files with 43 additions and 61 deletions
|
|
@ -31,21 +31,36 @@ import (
|
|||
"github.com/siyuan-note/logging"
|
||||
)
|
||||
|
||||
func IsOnline() (ret bool) {
|
||||
c := req.C().SetTimeout(1 * time.Second)
|
||||
resp, err := c.R().Head("https://www.baidu.com")
|
||||
if nil != err {
|
||||
resp, err = c.R().Head("https://icanhazip.com")
|
||||
if nil != err {
|
||||
resp, err = c.R().Head("https://api.ipify.org")
|
||||
func IsOnline(checkURL string) bool {
|
||||
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
|
||||
}
|
||||
|
||||
ret = nil == err && nil != resp && nil != resp.Response
|
||||
if !ret {
|
||||
logging.LogWarnf("network is offline: %v", err)
|
||||
if isOnline(checkURL) {
|
||||
return true
|
||||
}
|
||||
return
|
||||
|
||||
logging.LogWarnf("network is offline [checkURL=%s]", checkURL)
|
||||
return false
|
||||
}
|
||||
|
||||
func isOnline(checkURL string) bool {
|
||||
c := req.C().SetTimeout(1 * time.Second)
|
||||
_, err := c.R().Head("https://www.baidu.com")
|
||||
return nil == err
|
||||
}
|
||||
|
||||
func GetRemoteAddr(session *melody.Session) string {
|
||||
|
|
|
|||
|
|
@ -156,20 +156,6 @@ func NormalizeEndpoint(endpoint string) string {
|
|||
return endpoint
|
||||
}
|
||||
|
||||
func NormalizeCheckURL(checkURL string) string {
|
||||
checkURL = strings.TrimSpace(checkURL)
|
||||
if "" == checkURL {
|
||||
return ""
|
||||
}
|
||||
if !strings.HasPrefix(checkURL, "http://") && !strings.HasPrefix(checkURL, "https://") {
|
||||
checkURL = "http://" + checkURL
|
||||
}
|
||||
if !IsValidURL(checkURL) {
|
||||
return ""
|
||||
}
|
||||
return checkURL
|
||||
}
|
||||
|
||||
func FilterMoveDocFromPaths(fromPaths []string, toPath string) (ret []string) {
|
||||
tmp := FilterSelfChildDocs(fromPaths)
|
||||
for _, fromPath := range tmp {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue