Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

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

Liang Dingbdf621f8c552
diff --git a/kernel/conf/sync.go b/kernel/conf/sync.go
index da28993935..952509143a 100644
--- a/kernel/conf/sync.go
+++ b/kernel/conf/sync.go
@@ -56,7 +56,7 @@ type WebDAV struct {
Password string `json:"password"` // 密码
SkipTlsVerify bool `json:"skipTlsVerify"` // 是否跳过 TLS 验证
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 (
@@ -66,5 +66,5 @@ const (
)
func NewSyncProviderCheckURL() string {
- return "https://www.baidu.com https://icanhazip.com https://api.ipify.org"
+ return "https://www.baidu.com"
}
diff --git a/kernel/model/conf.go b/kernel/model/conf.go
index 774787a8e2..4035198c0b 100644
--- a/kernel/model/conf.go
+++ b/kernel/model/conf.go
@@ -268,7 +268,8 @@ func InitConf() {
}
Conf.Sync.S3.Endpoint = util.NormalizeEndpoint(Conf.Sync.S3.Endpoint)
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()
}
if nil == Conf.Sync.WebDAV {
@@ -276,7 +277,8 @@ func InitConf() {
}
Conf.Sync.WebDAV.Endpoint = util.NormalizeEndpoint(Conf.Sync.WebDAV.Endpoint)
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()
}
diff --git a/kernel/util/net.go b/kernel/util/net.go
index 377e014425..742c1c24fb 100644
--- a/kernel/util/net.go
+++ b/kernel/util/net.go
@@ -18,6 +18,7 @@ package util
import (
"net/http"
+ "net/url"
"strings"
"time"
@@ -82,6 +83,11 @@ func InvalidIDPattern(idArg string, result *gulu.Result) bool {
return true
}
+func IsValidURL(str string) bool {
+ _, err := url.Parse(str)
+ return nil == err
+}
+
func initHttpClient() {
http.DefaultClient = httpclient.GetCloudFileClient2Min()
http.DefaultTransport = httpclient.NewTransport(false)
diff --git a/kernel/util/path.go b/kernel/util/path.go
index 106afd7933..b6c2d679ea 100644
--- a/kernel/util/path.go
+++ b/kernel/util/path.go
@@ -156,6 +156,20 @@ 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 {