An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: Use `Endpoint` for network connectivity checks when syncing with third-party cloud providers https://github.com/siyuan-note/siyuan/issues/7805
Liang Ding05daece0d1ab
diff --git a/app/src/config/repos.ts b/app/src/config/repos.tsindex da0384c74f..26ae55ae56 100644--- a/app/src/config/repos.ts+++ b/app/src/config/repos.ts@@ -93,11 +93,6 @@ const renderProvider = (provider: number) => {<option ${window.siyuan.config.sync.s3.skipTlsVerify ? "" : "selected"} value="false">Verify</option><option ${window.siyuan.config.sync.s3.skipTlsVerify ? "selected" : ""} value="true">Skip</option></select>-</label>-<label class="b3-label b3-label--noborder fn__flex config__item">- <div class="fn__flex-center fn__size200">Connectivity Check URL</div>- <div class="fn__space"></div>- <input id="checkURL" class="b3-text-field fn__block" value="${window.siyuan.config.sync.s3.checkURL}"></label>`;} else if (provider === 3) {const tip = `<div class="b3-label b3-label--inner">@@ -138,11 +133,6 @@ const renderProvider = (provider: number) => {<option ${window.siyuan.config.sync.webdav.skipTlsVerify ? "" : "selected"} value="false">Verify</option><option ${window.siyuan.config.sync.webdav.skipTlsVerify ? "selected" : ""} value="true">Skip</option></select>-</label>-<label class="b3-label b3-label--noborder fn__flex config__item">- <div class="fn__flex-center fn__size200">Connectivity Check URL</div>- <div class="fn__space"></div>- <input id="checkURL" class="b3-text-field fn__block" value="${window.siyuan.config.sync.webdav.checkURL}"></label>`;}return "";@@ -227,7 +217,6 @@ const bindProviderEvent = () => {region: (providerPanelElement.querySelector("#region") as HTMLInputElement).value,skipTlsVerify: (providerPanelElement.querySelector("#s3SkipTlsVerify") as HTMLInputElement).value === "true",timeout: timeout,- checkURL: (providerPanelElement.querySelector("#checkURL") as HTMLInputElement).value,};fetchPost("/api/sync/setSyncProviderS3", {s3}, () => {window.siyuan.config.sync.s3 = s3;@@ -247,7 +236,6 @@ const bindProviderEvent = () => {password: (providerPanelElement.querySelector("#password") as HTMLInputElement).value,skipTlsVerify: (providerPanelElement.querySelector("#webdavSkipTlsVerify") as HTMLInputElement).value === "true",timeout: timeout,- checkURL: (providerPanelElement.querySelector("#checkURL") as HTMLInputElement).value,};fetchPost("/api/sync/setSyncProviderWebDAV", {webdav}, () => {window.siyuan.config.sync.webdav = webdav;diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.tsindex 3bdabd4054..d038c73f32 100644--- a/app/src/types/index.d.ts+++ b/app/src/types/index.d.ts@@ -433,7 +433,6 @@ declare interface IConfig {region: stringskipTlsVerify: booleantimeout: number- checkURL: string}webdav: {endpoint: string@@ -441,7 +440,6 @@ declare interface IConfig {password: stringskipTlsVerify: booleantimeout: number- checkURL: string}},lang: stringdiff --git a/kernel/conf/sync.go b/kernel/conf/sync.goindex 952509143a..910bb1721b 100644--- a/kernel/conf/sync.go+++ b/kernel/conf/sync.go@@ -47,7 +47,6 @@ type S3 struct {PathStyle bool `json:"pathStyle"` // 是否使用路径风格SkipTlsVerify bool `json:"skipTlsVerify"` // 是否跳过 TLS 验证Timeout int `json:"timeout"` // 超时时间,单位:秒- CheckURL string `json:"checkURL"` // 连通性检查 URL // https://github.com/siyuan-note/siyuan/issues/7805}type WebDAV struct {@@ -56,7 +55,6 @@ 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}const (diff --git a/kernel/model/conf.go b/kernel/model/conf.goindex 4035198c0b..2b0c3956e1 100644--- a/kernel/model/conf.go+++ b/kernel/model/conf.go@@ -268,19 +268,11 @@ func InitConf() {}Conf.Sync.S3.Endpoint = util.NormalizeEndpoint(Conf.Sync.S3.Endpoint)Conf.Sync.S3.Timeout = util.NormalizeTimeout(Conf.Sync.S3.Timeout)- 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 {Conf.Sync.WebDAV = &conf.WebDAV{}}Conf.Sync.WebDAV.Endpoint = util.NormalizeEndpoint(Conf.Sync.WebDAV.Endpoint)Conf.Sync.WebDAV.Timeout = util.NormalizeTimeout(Conf.Sync.WebDAV.Timeout)- Conf.Sync.WebDAV.CheckURL = util.NormalizeCheckURL(Conf.Sync.WebDAV.CheckURL)- if "" == Conf.Sync.WebDAV.CheckURL {- Conf.Sync.WebDAV.CheckURL = conf.NewSyncProviderCheckURL()- }if nil == Conf.Api {Conf.Api = conf.NewAPI()diff --git a/kernel/model/sync.go b/kernel/model/sync.goindex e1ae9ea39b..cb82537fde 100644--- a/kernel/model/sync.go+++ b/kernel/model/sync.go@@ -46,7 +46,7 @@ func SyncDataDownload() {}util.BroadcastByType("main", "syncing", 0, Conf.Language(81), nil)- if !util.IsOnline() { // 这个操作比较耗时,所以要先推送 syncing 事件后再判断网络,这样才能给用户更即时的反馈+ if !isProviderOnline() { // 这个操作比较耗时,所以要先推送 syncing 事件后再判断网络,这样才能给用户更即时的反馈util.BroadcastByType("main", "syncing", 2, Conf.Language(28), nil)return}@@ -82,7 +82,7 @@ func SyncDataUpload() {}util.BroadcastByType("main", "syncing", 0, Conf.Language(81), nil)- if !util.IsOnline() { // 这个操作比较耗时,所以要先推送 syncing 事件后再判断网络,这样才能给用户更即时的反馈+ if !isProviderOnline() { // 这个操作比较耗时,所以要先推送 syncing 事件后再判断网络,这样才能给用户更即时的反馈util.BroadcastByType("main", "syncing", 2, Conf.Language(28), nil)return}@@ -136,7 +136,7 @@ func BootSyncData() {return}- if !util.IsOnline() {+ if !isProviderOnline() {BootSyncSucc = 1util.PushErrMsg(Conf.Language(28), 7000)return@@ -182,7 +182,7 @@ func syncData(boot, exit, byHand bool) {}util.BroadcastByType("main", "syncing", 0, Conf.Language(81), nil)- if !util.IsOnline() { // 这个操作比较耗时,所以要先推送 syncing 事件后再判断网络,这样才能给用户更即时的反馈+ if !isProviderOnline() { // 这个操作比较耗时,所以要先推送 syncing 事件后再判断网络,这样才能给用户更即时的反馈util.BroadcastByType("main", "syncing", 2, Conf.Language(28), nil)return}@@ -365,10 +365,6 @@ func SetSyncProviderS3(s3 *conf.S3) (err error) {s3.Bucket = strings.TrimSpace(s3.Bucket)s3.Region = strings.TrimSpace(s3.Region)s3.Timeout = util.NormalizeTimeout(s3.Timeout)- s3.CheckURL = strings.TrimSpace(s3.CheckURL)- if "" == s3.CheckURL {- s3.CheckURL = conf.NewSyncProviderCheckURL()- }Conf.Sync.S3 = s3Conf.Save()@@ -388,10 +384,6 @@ func SetSyncProviderWebDAV(webdav *conf.WebDAV) (err error) {webdav.Username = strings.TrimSpace(webdav.Username)webdav.Password = strings.TrimSpace(webdav.Password)webdav.Timeout = util.NormalizeTimeout(webdav.Timeout)- webdav.CheckURL = strings.TrimSpace(webdav.CheckURL)- if "" == webdav.CheckURL {- webdav.CheckURL = conf.NewSyncProviderCheckURL()- }Conf.Sync.WebDAV = webdavConf.Save()@@ -573,3 +565,16 @@ func IncSync() {func planSyncAfter(d time.Duration) {syncPlanTime = time.Now().Add(d)}++func isProviderOnline() bool {+ switch Conf.Sync.Provider {+ case conf.ProviderSiYuan:+ return util.IsOnline(util.SiYuanSyncServer)+ case conf.ProviderS3:+ return util.IsOnline(Conf.Sync.S3.Endpoint)+ case conf.ProviderWebDAV:+ return util.IsOnline(Conf.Sync.WebDAV.Endpoint)+ default:+ return util.IsOnline("")+ }+}diff --git a/kernel/util/net.go b/kernel/util/net.goindex 742c1c24fb..d742d18303 100644--- a/kernel/util/net.go+++ b/kernel/util/net.go@@ -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 {diff --git a/kernel/util/path.go b/kernel/util/path.goindex b6c2d679ea..106afd7933 100644--- a/kernel/util/path.go+++ b/kernel/util/path.go@@ -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 {