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: 数据同步前先判断网络连通性 Fix https://github.com/siyuan-note/siyuan/issues/7156
Liang Dingbdab8961b3b3
diff --git a/kernel/model/sync.go b/kernel/model/sync.goindex 54b47c358e..037e2e7fd3 100644--- a/kernel/model/sync.go+++ b/kernel/model/sync.go@@ -59,9 +59,7 @@ func AutoSync() {func BootSyncData() {defer logging.Recover()- if util.IsMutexLocked(&syncLock) {- logging.LogWarnf("sync is in progress")- planSyncAfter(30 * time.Second)+ if !checkSync(true, false, false) {return}@@ -70,27 +68,10 @@ func BootSyncData() {util.IncBootProgress(3, "Syncing data from the cloud...")BootSyncSucc = 0-- if !Conf.Sync.Enabled || !cloud.IsValidCloudDirName(Conf.Sync.CloudName) {- return- }-- if !IsSubscriber() && conf.ProviderSiYuan == Conf.Sync.Provider {- return- }-logging.LogInfof("sync before boot")- if 7 < syncDownloadErrCount {- logging.LogErrorf("sync download error too many times, cancel auto sync, try to sync by hand")- util.PushErrMsg(Conf.Language(125), 1000*60*60)- planSyncAfter(64 * time.Minute)- return- }-now := util.CurrentTimeMillis()Conf.Sync.Synced = now-util.BroadcastByType("main", "syncing", 0, Conf.Language(81), nil)err := bootSyncRepo()synced := util.Millisecond2Time(Conf.Sync.Synced).Format("2006-01-02 15:04:05") + "\n\n"@@ -102,7 +83,11 @@ func BootSyncData() {msg := fmt.Sprintf(Conf.Language(82), synced)Conf.Sync.Stat = msgConf.Save()- util.BroadcastByType("main", "syncing", 1, msg, nil)+ code := 1+ if nil != err {+ code = 2+ }+ util.BroadcastByType("main", "syncing", code, msg, nil)return}@@ -197,6 +182,11 @@ func checkSync(boot, exit, byHand bool) bool {planSyncAfter(64 * time.Minute)return false}++ if !util.IsOnline() {+ util.BroadcastByType("main", "syncing", 2, Conf.Language(28), nil)+ return false+ }return true}diff --git a/kernel/util/net.go b/kernel/util/net.goindex 59e5930ddc..3cf013cec7 100644--- a/kernel/util/net.go+++ b/kernel/util/net.go@@ -17,15 +17,29 @@package utilimport (+ "github.com/imroc/req/v3""github.com/siyuan-note/httpclient""net/http""strings"+ "time""github.com/88250/gulu""github.com/gin-gonic/gin""github.com/olahol/melody")+func IsOnline() bool {+ c := req.C().SetTimeout(1 * time.Second)+ resp, err := c.R().Get("https://icanhazip.com")+ if nil != err {+ resp, err = c.R().Get("https://api.ipify.org")+ if nil != err {+ resp, err = c.R().Get("https://www.baidu.com")+ }+ }+ return nil == err && nil != resp && 200 == resp.StatusCode+}+func GetRemoteAddr(session *melody.Session) string {ret := session.Request.Header.Get("X-forwarded-for")ret = strings.TrimSpace(ret)