From 07414dcdc8a69e03cc7662badbdefea9ab48af8f Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Wed, 29 Mar 2023 14:10:18 +0800 Subject: [PATCH 1/6] :art: Support configuration of cloud provider connectivity check URL https://github.com/siyuan-note/siyuan/issues/7805 --- app/src/config/repos.ts | 12 ++++++++++++ app/src/types/index.d.ts | 2 ++ kernel/conf/sync.go | 6 ++++++ kernel/model/conf.go | 8 +++++++- kernel/model/sync.go | 8 ++++++++ 5 files changed, 35 insertions(+), 1 deletion(-) diff --git a/app/src/config/repos.ts b/app/src/config/repos.ts index 26ae55ae5..da0384c74 100644 --- a/app/src/config/repos.ts +++ b/app/src/config/repos.ts @@ -93,6 +93,11 @@ const renderProvider = (provider: number) => { + +`; } else if (provider === 3) { const tip = `
@@ -133,6 +138,11 @@ const renderProvider = (provider: number) => { + +`; } return ""; @@ -217,6 +227,7 @@ 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; @@ -236,6 +247,7 @@ 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.ts index d038c73f3..3bdabd405 100644 --- a/app/src/types/index.d.ts +++ b/app/src/types/index.d.ts @@ -433,6 +433,7 @@ declare interface IConfig { region: string skipTlsVerify: boolean timeout: number + checkURL: string } webdav: { endpoint: string @@ -440,6 +441,7 @@ declare interface IConfig { password: string skipTlsVerify: boolean timeout: number + checkURL: string } }, lang: string diff --git a/kernel/conf/sync.go b/kernel/conf/sync.go index bf80edf79..da2899393 100644 --- a/kernel/conf/sync.go +++ b/kernel/conf/sync.go @@ -47,6 +47,7 @@ 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 { @@ -55,6 +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 } const ( @@ -62,3 +64,7 @@ const ( ProviderS3 = 2 // ProviderS3 为 S3 协议对象存储提供的云端存储服务 ProviderWebDAV = 3 // ProviderWebDAV 为 WebDAV 协议提供的云端存储服务 ) + +func NewSyncProviderCheckURL() string { + return "https://www.baidu.com https://icanhazip.com https://api.ipify.org" +} diff --git a/kernel/model/conf.go b/kernel/model/conf.go index f62182955..774787a8e 100644 --- a/kernel/model/conf.go +++ b/kernel/model/conf.go @@ -268,11 +268,17 @@ 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 = 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) + if "" == strings.TrimSpace(Conf.Sync.WebDAV.CheckURL) { + Conf.Sync.WebDAV.CheckURL = conf.NewSyncProviderCheckURL() + } if nil == Conf.Api { Conf.Api = conf.NewAPI() @@ -297,7 +303,7 @@ func InitConf() { if 0 > Conf.Editor.BacklinkExpandCount { Conf.Editor.BacklinkExpandCount = 0 } - if 0> Conf.Editor.BackmentionExpandCount { + if 0 > Conf.Editor.BackmentionExpandCount { Conf.Editor.BackmentionExpandCount = 0 } diff --git a/kernel/model/sync.go b/kernel/model/sync.go index 1d570c1aa..e1ae9ea39 100644 --- a/kernel/model/sync.go +++ b/kernel/model/sync.go @@ -365,6 +365,10 @@ 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 = s3 Conf.Save() @@ -384,6 +388,10 @@ 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 = webdav Conf.Save() From bdf621f8c552143f288675ad15e666080a53bf99 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Wed, 29 Mar 2023 14:20:19 +0800 Subject: [PATCH 2/6] :art: Support configuration of cloud provider connectivity check URL https://github.com/siyuan-note/siyuan/issues/7805 --- kernel/conf/sync.go | 4 ++-- kernel/model/conf.go | 6 ++++-- kernel/util/net.go | 6 ++++++ kernel/util/path.go | 14 ++++++++++++++ 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/kernel/conf/sync.go b/kernel/conf/sync.go index da2899393..952509143 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 774787a8e..4035198c0 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 377e01442..742c1c24f 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 106afd793..b6c2d679e 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 { From 05daece0d1abfe62abb0997aaa2f00187efcce50 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Wed, 29 Mar 2023 14:43:02 +0800 Subject: [PATCH 3/6] :art: Use `Endpoint` for network connectivity checks when syncing with third-party cloud providers https://github.com/siyuan-note/siyuan/issues/7805 --- app/src/config/repos.ts | 12 ------------ app/src/types/index.d.ts | 2 -- kernel/conf/sync.go | 2 -- kernel/model/conf.go | 8 -------- kernel/model/sync.go | 29 +++++++++++++++++------------ kernel/util/net.go | 37 ++++++++++++++++++++++++++----------- kernel/util/path.go | 14 -------------- 7 files changed, 43 insertions(+), 61 deletions(-) diff --git a/app/src/config/repos.ts b/app/src/config/repos.ts index da0384c74..26ae55ae5 100644 --- a/app/src/config/repos.ts +++ b/app/src/config/repos.ts @@ -93,11 +93,6 @@ const renderProvider = (provider: number) => { - -`; } else if (provider === 3) { const tip = `
@@ -138,11 +133,6 @@ const renderProvider = (provider: number) => { - -`; } 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.ts index 3bdabd405..d038c73f3 100644 --- a/app/src/types/index.d.ts +++ b/app/src/types/index.d.ts @@ -433,7 +433,6 @@ declare interface IConfig { region: string skipTlsVerify: boolean timeout: number - checkURL: string } webdav: { endpoint: string @@ -441,7 +440,6 @@ declare interface IConfig { password: string skipTlsVerify: boolean timeout: number - checkURL: string } }, lang: string diff --git a/kernel/conf/sync.go b/kernel/conf/sync.go index 952509143..910bb1721 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.go index 4035198c0..2b0c3956e 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.go index e1ae9ea39..cb82537fd 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 = 1 util.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 = s3 Conf.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 = webdav Conf.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.go index 742c1c24f..d742d1830 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.go index b6c2d679e..106afd793 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 { From c09c2a048ffd1651e7610a56217c22a541ab0e9a Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Wed, 29 Mar 2023 14:49:28 +0800 Subject: [PATCH 4/6] :art: Use `Endpoint` for network connectivity checks when syncing with third-party cloud providers https://github.com/siyuan-note/siyuan/issues/7805 --- app/electron/main.js | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/app/electron/main.js b/app/electron/main.js index 2e4b1b252..1ea464de7 100644 --- a/app/electron/main.js +++ b/app/electron/main.js @@ -945,23 +945,10 @@ powerMonitor.on("suspend", () => { powerMonitor.on("resume", async () => { // 桌面端系统休眠唤醒后判断网络连通性后再执行数据同步 https://github.com/siyuan-note/siyuan/issues/6687 writeLog("system resume"); + + const eNet = require("electron").net const isOnline = async () => { - try { - const result = await fetch("https://www.baidu.com", {timeout: 1000}); - return 200 === result.status; - } catch (e) { - try { - const result = await fetch("https://icanhazip.com", {timeout: 1000}); - return 200 === result.status; - } catch (e) { - try { - const result = await fetch("https://api.ipify.org", {timeout: 1000}); - return 200 === result.status; - } catch (e) { - return false; - } - } - } + return eNet.isOnline() }; let online = false; for (let i = 0; i < 7; i++) { From 011ad83b6a960b607694a770fdc2e13ceb4361c3 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Wed, 29 Mar 2023 15:04:58 +0800 Subject: [PATCH 5/6] :art: Use `Endpoint` for network connectivity checks when syncing with third-party cloud providers https://github.com/siyuan-note/siyuan/issues/7805 --- app/appearance/langs/en_US.json | 2 +- app/appearance/langs/es_ES.json | 2 +- app/appearance/langs/fr_FR.json | 2 +- app/appearance/langs/zh_CHT.json | 2 +- app/appearance/langs/zh_CN.json | 2 +- kernel/model/sync.go | 15 ++++++++++----- 6 files changed, 15 insertions(+), 10 deletions(-) diff --git a/app/appearance/langs/en_US.json b/app/appearance/langs/en_US.json index c5282c5a4..5900c18df 100644 --- a/app/appearance/langs/en_US.json +++ b/app/appearance/langs/en_US.json @@ -1026,7 +1026,7 @@ "73": "Importing, please wait...", "74": "The kernel has not been fully booted [%d%%], please try again later", "75": "Attempt to access file failed", - "76": "TODO", + "76": "The network connectivity verification of the cloud storage service provider is abnormal, please check the network configuration", "77": "Invalid dir path [%s]", "78": "The old and new paths are repeated", "79": "Only supports importing Markdown document", diff --git a/app/appearance/langs/es_ES.json b/app/appearance/langs/es_ES.json index 6db3e5b93..c384168ec 100644 --- a/app/appearance/langs/es_ES.json +++ b/app/appearance/langs/es_ES.json @@ -1026,7 +1026,7 @@ "73": "Importando, por favor espere...", "74": "El kernel no ha sido arrancado completamente [%d%%], por favor, inténtelo de nuevo más tarde", "75": "Error al intentar acceder al archivo", - "76": "TODO", + "76": "La verificaci\u00f3n de conectividad de red del proveedor de servicios de almacenamiento en la nube es anormal, verifique la configuraci\u00f3n de red", "77": "Ruta inválida [%s]", "78": "Los viejos y nuevos caminos se repiten", "79": "Sólo admite la importación de documentos Markdown", diff --git a/app/appearance/langs/fr_FR.json b/app/appearance/langs/fr_FR.json index 6867cd17c..63fc391a8 100644 --- a/app/appearance/langs/fr_FR.json +++ b/app/appearance/langs/fr_FR.json @@ -1026,7 +1026,7 @@ "73": "En cours d'importation, veuillez patienter...", "74": "Le kernel n'a pas été complètement démarré [%d%%], veuillez réessayer plus tard.", "75": "La tentative d'accès au fichier a échoué", - "76": "TODO", + "76": "La vérification de la connectivité réseau du fournisseur de service de stockage cloud est anormale, veuillez vérifier la configuration réseau", "77": "Chemin d'accès invalide [%s]", "78": "Les anciens et les nouveaux chemins sont répétés", "79": "Prise en charge de l'importation de documents Markdown uniquement", diff --git a/app/appearance/langs/zh_CHT.json b/app/appearance/langs/zh_CHT.json index 7c7e4861a..d7059338f 100644 --- a/app/appearance/langs/zh_CHT.json +++ b/app/appearance/langs/zh_CHT.json @@ -1026,7 +1026,7 @@ "73": "正在導入,請稍等...", "74": "kernel尚未完全啟動 [%d%%],請稍後再試", "75": "嘗試訪問資料檔失敗", - "76": "TODO", + "76": "雲端存儲服務提供商網絡連通性校驗異常,請檢查網絡配置", "77": "不可用的目錄路徑 [%s]", "78": "新老路徑重複", "79": "僅支援導入 Markdown 文檔", diff --git a/app/appearance/langs/zh_CN.json b/app/appearance/langs/zh_CN.json index ad611e7f7..577ab1cf7 100644 --- a/app/appearance/langs/zh_CN.json +++ b/app/appearance/langs/zh_CN.json @@ -1026,7 +1026,7 @@ "73": "正在导入,请稍等...", "74": "内核尚未完全启动 [%d%%],请稍后再试", "75": "尝试访问文件失败", - "76": "TODO", + "76": "云端存储服务提供商网络连通性校验异常,请检查网络配置", "77": "不可用的目录路径 [%s]", "78": "新老路径重复", "79": "仅支持导入 Markdown 文档", diff --git a/kernel/model/sync.go b/kernel/model/sync.go index cb82537fd..296fd3c56 100644 --- a/kernel/model/sync.go +++ b/kernel/model/sync.go @@ -566,15 +566,20 @@ func planSyncAfter(d time.Duration) { syncPlanTime = time.Now().Add(d) } -func isProviderOnline() bool { +func isProviderOnline() (ret bool) { switch Conf.Sync.Provider { case conf.ProviderSiYuan: - return util.IsOnline(util.SiYuanSyncServer) + ret = util.IsOnline(util.SiYuanSyncServer) case conf.ProviderS3: - return util.IsOnline(Conf.Sync.S3.Endpoint) + ret = util.IsOnline(Conf.Sync.S3.Endpoint) case conf.ProviderWebDAV: - return util.IsOnline(Conf.Sync.WebDAV.Endpoint) + ret = util.IsOnline(Conf.Sync.WebDAV.Endpoint) default: - return util.IsOnline("") + ret = util.IsOnline("") } + + if !ret { + util.PushErrMsg(Conf.Language(76), 5000) + } + return } From 7dd4a2db9eaadc2af64bcbb17e9b2cd9d7ec16f2 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Wed, 29 Mar 2023 15:07:13 +0800 Subject: [PATCH 6/6] :art: Use `Endpoint` for network connectivity checks when syncing with third-party cloud providers https://github.com/siyuan-note/siyuan/issues/7805 --- kernel/model/sync.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/kernel/model/sync.go b/kernel/model/sync.go index 296fd3c56..f1cde1ade 100644 --- a/kernel/model/sync.go +++ b/kernel/model/sync.go @@ -567,18 +567,19 @@ func planSyncAfter(d time.Duration) { } func isProviderOnline() (ret bool) { + checkURL := util.SiYuanSyncServer switch Conf.Sync.Provider { case conf.ProviderSiYuan: - ret = util.IsOnline(util.SiYuanSyncServer) case conf.ProviderS3: - ret = util.IsOnline(Conf.Sync.S3.Endpoint) + checkURL = Conf.Sync.S3.Endpoint case conf.ProviderWebDAV: - ret = util.IsOnline(Conf.Sync.WebDAV.Endpoint) + checkURL = Conf.Sync.WebDAV.Endpoint default: - ret = util.IsOnline("") + logging.LogWarnf("unknown provider: %d", Conf.Sync.Provider) + util.IsOnline("") } - if !ret { + if ret = util.IsOnline(checkURL); !ret { util.PushErrMsg(Conf.Language(76), 5000) } return