Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Vanessa 2022-11-02 18:09:06 +08:00
commit ba8d07b3d0
5 changed files with 34 additions and 10 deletions

View file

@ -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第三方七牛云2S3 协议对象存储
OSS *OSS `json:"oss"` // 对象存储服务配置
}
@ -33,7 +33,7 @@ func NewSync() *Sync {
Enabled: false,
Mode: 1,
GenerateConflictDoc: false,
Provider: 0,
Provider: ProviderSiYuan,
}
}
@ -41,6 +41,12 @@ type OSS struct {
Endpoint string `json:"endpoint"` // 服务端点
AccessKey string `json:"accessKey"` // Access Key
SecretKey string `json:"secretKey"` // Secret Key
Regin string `json:"regin"` // 存储区域
Bucket string `json:"bucket"` // 存储空间
Region string `json:"region"` // 存储区域
}
const (
ProviderSiYuan = 0
ProviderQiniu = 1
ProviderS3 = 2
)

View file

@ -36,7 +36,7 @@ require (
github.com/panjf2000/ants/v2 v2.6.0
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/radovskyb/watcher v1.0.7
github.com/siyuan-note/dejavu v0.0.0-20221102025652-e55edc4ad90c
github.com/siyuan-note/dejavu v0.0.0-20221102075801-148594bd43e2
github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75
github.com/siyuan-note/eventbus v0.0.0-20220916025349-3ac6e75522da
github.com/siyuan-note/filelock v0.0.0-20221007163134-7e64809023ef

View file

@ -353,8 +353,8 @@ github.com/shurcooL/reactions v0.0.0-20181006231557-f2e0b4ca5b82/go.mod h1:TCR1l
github.com/shurcooL/sanitized_anchor_name v0.0.0-20170918181015-86672fcb3f95/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/shurcooL/users v0.0.0-20180125191416-49c67e49c537/go.mod h1:QJTqeLYEDaXHZDBsXlPCDqdhQuJkuw4NOtaxYe3xii4=
github.com/shurcooL/webdavfs v0.0.0-20170829043945-18c3829fa133/go.mod h1:hKmq5kWdCj2z2KEozexVbfEZIWiTjhE0+UjmZgPqehw=
github.com/siyuan-note/dejavu v0.0.0-20221102025652-e55edc4ad90c h1:E+vDe5m9l3VD+Id7p3ELDSHjk/BH6u7woCILIdXEEJ0=
github.com/siyuan-note/dejavu v0.0.0-20221102025652-e55edc4ad90c/go.mod h1:+U86jfsvpacZBThE3Ouf/ZQ4EsB4jGPJsMO2iuRv0LQ=
github.com/siyuan-note/dejavu v0.0.0-20221102075801-148594bd43e2 h1:EjflBUJdr+vE56QHL/CaDGIiMmXl6AJLc0Ged9yVDL8=
github.com/siyuan-note/dejavu v0.0.0-20221102075801-148594bd43e2/go.mod h1:+U86jfsvpacZBThE3Ouf/ZQ4EsB4jGPJsMO2iuRv0LQ=
github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75 h1:Bi7/7f29LW+Fm0cHc0J1NO1cZqyJwljSWVmfOqVZgaE=
github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75/go.mod h1:H8fyqqAbp9XreANjeSbc72zEdFfKTXYN34tc1TjZwtw=
github.com/siyuan-note/eventbus v0.0.0-20220916025349-3ac6e75522da h1:/jNhl7LC+9BhkWvNxuJDdsNfA/2wvfuj9mqWx4CbV90=

View file

@ -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()

View file

@ -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)
}
@ -1008,7 +1017,7 @@ func buildCloudConf() (ret *cloud.Conf, err error) {
}
userId, token, availableSize := "0", "", int64(1024*1024*1024*1024*2)
if nil != Conf.User {
if nil != Conf.User && conf.ProviderSiYuan == Conf.Sync.Provider {
userId = Conf.User.UserId
token = Conf.User.UserToken
availableSize = Conf.User.GetCloudRepoAvailableSize()
@ -1020,6 +1029,12 @@ func buildCloudConf() (ret *cloud.Conf, err error) {
Token: token,
AvailableSize: availableSize,
Server: util.AliyunServer,
Endpoint: Conf.Sync.OSS.Endpoint,
AccessKey: Conf.Sync.OSS.AccessKey,
SecretKey: Conf.Sync.OSS.SecretKey,
Bucket: Conf.Sync.OSS.Bucket,
Region: Conf.Sync.OSS.Region,
}
return
}