🎨 Support configuration of cloud provider connectivity check URL https://github.com/siyuan-note/siyuan/issues/7805

This commit is contained in:
Liang Ding 2023-03-29 14:20:19 +08:00
parent 07414dcdc8
commit bdf621f8c5
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
4 changed files with 26 additions and 4 deletions

View file

@ -56,7 +56,7 @@ type WebDAV struct {
Password string `json:"password"` // 密码 Password string `json:"password"` // 密码
SkipTlsVerify bool `json:"skipTlsVerify"` // 是否跳过 TLS 验证 SkipTlsVerify bool `json:"skipTlsVerify"` // 是否跳过 TLS 验证
Timeout int `json:"timeout"` // 超时时间,单位:秒 Timeout int `json:"timeout"` // 超时时间,单位:秒
CheckURL string `json:"checkUrl"` // 连通性检查 URL // https://github.com/siyuan-note/siyuan/issues/7805 CheckURL string `json:"checkURL"` // 连通性检查 URL // https://github.com/siyuan-note/siyuan/issues/7805
} }
const ( const (
@ -66,5 +66,5 @@ const (
) )
func NewSyncProviderCheckURL() string { func NewSyncProviderCheckURL() string {
return "https://www.baidu.com https://icanhazip.com https://api.ipify.org" return "https://www.baidu.com"
} }

View file

@ -268,7 +268,8 @@ func InitConf() {
} }
Conf.Sync.S3.Endpoint = util.NormalizeEndpoint(Conf.Sync.S3.Endpoint) Conf.Sync.S3.Endpoint = util.NormalizeEndpoint(Conf.Sync.S3.Endpoint)
Conf.Sync.S3.Timeout = util.NormalizeTimeout(Conf.Sync.S3.Timeout) Conf.Sync.S3.Timeout = util.NormalizeTimeout(Conf.Sync.S3.Timeout)
if "" == strings.TrimSpace(Conf.Sync.S3.CheckURL) { Conf.Sync.S3.CheckURL = util.NormalizeCheckURL(Conf.Sync.S3.CheckURL)
if "" == Conf.Sync.S3.CheckURL {
Conf.Sync.S3.CheckURL = conf.NewSyncProviderCheckURL() Conf.Sync.S3.CheckURL = conf.NewSyncProviderCheckURL()
} }
if nil == Conf.Sync.WebDAV { if nil == Conf.Sync.WebDAV {
@ -276,7 +277,8 @@ func InitConf() {
} }
Conf.Sync.WebDAV.Endpoint = util.NormalizeEndpoint(Conf.Sync.WebDAV.Endpoint) Conf.Sync.WebDAV.Endpoint = util.NormalizeEndpoint(Conf.Sync.WebDAV.Endpoint)
Conf.Sync.WebDAV.Timeout = util.NormalizeTimeout(Conf.Sync.WebDAV.Timeout) Conf.Sync.WebDAV.Timeout = util.NormalizeTimeout(Conf.Sync.WebDAV.Timeout)
if "" == strings.TrimSpace(Conf.Sync.WebDAV.CheckURL) { Conf.Sync.WebDAV.CheckURL = util.NormalizeCheckURL(Conf.Sync.WebDAV.CheckURL)
if "" == Conf.Sync.WebDAV.CheckURL {
Conf.Sync.WebDAV.CheckURL = conf.NewSyncProviderCheckURL() Conf.Sync.WebDAV.CheckURL = conf.NewSyncProviderCheckURL()
} }

View file

@ -18,6 +18,7 @@ package util
import ( import (
"net/http" "net/http"
"net/url"
"strings" "strings"
"time" "time"
@ -82,6 +83,11 @@ func InvalidIDPattern(idArg string, result *gulu.Result) bool {
return true return true
} }
func IsValidURL(str string) bool {
_, err := url.Parse(str)
return nil == err
}
func initHttpClient() { func initHttpClient() {
http.DefaultClient = httpclient.GetCloudFileClient2Min() http.DefaultClient = httpclient.GetCloudFileClient2Min()
http.DefaultTransport = httpclient.NewTransport(false) http.DefaultTransport = httpclient.NewTransport(false)

View file

@ -156,6 +156,20 @@ func NormalizeEndpoint(endpoint string) string {
return endpoint 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) { func FilterMoveDocFromPaths(fromPaths []string, toPath string) (ret []string) {
tmp := FilterSelfChildDocs(fromPaths) tmp := FilterSelfChildDocs(fromPaths)
for _, fromPath := range tmp { for _, fromPath := range tmp {