Skip to content

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

:art: 开源云端同步服务实现 https://github.com/siyuan-note/siyuan/issues/6445

Liang Ding11f67cab71c3
diff --git a/kernel/conf/sync.go b/kernel/conf/sync.go
index a5899e9cb3..adcae7861b 100644
--- a/kernel/conf/sync.go
+++ b/kernel/conf/sync.go
@@ -23,7 +23,7 @@ type Sync struct {
Synced int64 `json:"synced"` // 最近同步时间
Stat string `json:"stat"` // 最近同步统计信息
GenerateConflictDoc bool `json:"generateConflictDoc"` // 云端同步冲突时是否生成冲突文档
- Provider int `json:"provider"` // 云端存储服务提供者,0:思源官方,1:第三方对象存储服务
+ Provider int `json:"provider"` // 云端存储服务提供者,0:思源官方,1:第三方七牛云,2:S3 协议对象存储
OSS *OSS `json:"oss"` // 对象存储服务配置
}
@@ -33,7 +33,7 @@ func NewSync() *Sync {
Enabled: false,
Mode: 1,
GenerateConflictDoc: false,
- Provider: 0,
+ Provider: ProviderSiYuan,
}
}
@@ -44,3 +44,9 @@ type OSS struct {
Regin string `json:"regin"` // 存储区域
Bucket string `json:"bucket"` // 存储空间
}
+
+const (
+ ProviderSiYuan = 0
+ ProviderQiniu = 1
+ ProviderS3 = 2
+)
diff --git a/kernel/model/conf.go b/kernel/model/conf.go
index 669e643c20..6327a278a3 100644
--- a/kernel/model/conf.go
+++ b/kernel/model/conf.go
@@ -242,6 +242,9 @@ func InitConf() {
if 0 == Conf.Sync.Mode {
Conf.Sync.Mode = 1
}
+ if nil == Conf.Sync.OSS {
+ Conf.Sync.OSS = &conf.OSS{}
+ }
if nil == Conf.Api {
Conf.Api = conf.NewAPI()
diff --git a/kernel/model/repository.go b/kernel/model/repository.go
index a175177032..d40839bd34 100644
--- a/kernel/model/repository.go
+++ b/kernel/model/repository.go
@@ -41,6 +41,7 @@ import (
"github.com/siyuan-note/httpclient"
"github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/cache"
+ "github.com/siyuan-note/siyuan/kernel/conf"
"github.com/siyuan-note/siyuan/kernel/sql"
"github.com/siyuan-note/siyuan/kernel/treenode"
"github.com/siyuan-note/siyuan/kernel/util"
@@ -816,12 +817,20 @@ func newRepository() (ret *dejavu.Repo, err error) {
return
}
- // TODO: 数据同步支持接入第三方对象存储服务 https://github.com/siyuan-note/siyuan/issues/6426
- cloudSiYuan := &cloud.SiYuan{BaseCloud: &cloud.BaseCloud{Conf: cloudConf}}
+ var cloudRepo cloud.Cloud
+ switch Conf.Sync.Provider {
+ case conf.ProviderSiYuan:
+ cloudRepo = &cloud.SiYuan{BaseCloud: &cloud.BaseCloud{Conf: cloudConf}}
+ case conf.ProviderQiniu:
+ cloudRepo = &cloud.Qiniu{BaseCloud: &cloud.BaseCloud{Conf: cloudConf}}
+ default:
+ err = fmt.Errorf("unknown cloud provider [%d]", Conf.Sync.Provider)
+ return
+ }
ignoreLines := getIgnoreLines()
ignoreLines = append(ignoreLines, "/.siyuan/conf.json") // 忽略旧版同步配置
- ret, err = dejavu.NewRepo(util.DataDir, util.RepoDir, util.HistoryDir, util.TempDir, Conf.Repo.Key, ignoreLines, cloudSiYuan)
+ ret, err = dejavu.NewRepo(util.DataDir, util.RepoDir, util.HistoryDir, util.TempDir, Conf.Repo.Key, ignoreLines, cloudRepo)
if nil != err {
logging.LogErrorf("init data repo failed: %s", err)
}