Skip to content

Commit

Permalink
✨ 云端支持多个数据仓库目录 Fix #5335
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Jul 4, 2022
1 parent ce516e4 commit 114d854
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 15 deletions.
2 changes: 1 addition & 1 deletion kernel/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ require (
github.com/qiniu/go-sdk/v7 v7.13.0
github.com/radovskyb/watcher v1.0.7
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06
github.com/siyuan-note/dejavu v0.0.0-20220704130554-0dbba22cfd32
github.com/siyuan-note/dejavu v0.0.0-20220704162819-bf588aabc1e0
github.com/siyuan-note/encryption v0.0.0-20220612074546-f1dd94fe8676
github.com/siyuan-note/eventbus v0.0.0-20220624162334-ca7c06dc771f
github.com/siyuan-note/filelock v0.0.0-20220704090116-54dfb035283f
Expand Down
4 changes: 2 additions & 2 deletions kernel/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,8 @@ github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749/go.mod h1:ZY1cvUeJ
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546/go.mod h1:TrYk7fJVaAttu97ZZKrO9UbRa8izdowaMIZcxYMbVaw=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/siyuan-note/dejavu v0.0.0-20220704130554-0dbba22cfd32 h1:ZovFHkGpB/cbhO4XfoYUevesyrcXiZD55ixV5wOVxbw=
github.com/siyuan-note/dejavu v0.0.0-20220704130554-0dbba22cfd32/go.mod h1:ral+X0pNW6nSQVvIcxllUXSczCaY4UOCT2iGlO4YNg0=
github.com/siyuan-note/dejavu v0.0.0-20220704162819-bf588aabc1e0 h1:MW12dGaf0QgsNjIaBQicP3KYmBwrJPX26zp/CmurThY=
github.com/siyuan-note/dejavu v0.0.0-20220704162819-bf588aabc1e0/go.mod h1:ral+X0pNW6nSQVvIcxllUXSczCaY4UOCT2iGlO4YNg0=
github.com/siyuan-note/encryption v0.0.0-20220612074546-f1dd94fe8676 h1:QB9TjJQFhXhZ6dAtPpY02DlzHAQm1C+WqZq6OadG8mI=
github.com/siyuan-note/encryption v0.0.0-20220612074546-f1dd94fe8676/go.mod h1:H8fyqqAbp9XreANjeSbc72zEdFfKTXYN34tc1TjZwtw=
github.com/siyuan-note/eventbus v0.0.0-20220624162334-ca7c06dc771f h1:JMobMNZ7AqaKKyEK+WeWFhix/2TDQXgPZDajU00IybU=
Expand Down
27 changes: 20 additions & 7 deletions kernel/model/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,13 +272,9 @@ func syncRepo(boot, exit, byHand bool) {
}

start := time.Now()
cloudInfo := &dejavu.CloudInfo{
Dir: "main",
UserID: Conf.User.UserId,
Token: Conf.User.UserToken,
LimitSize: int64(Conf.User.UserSiYuanRepoSize - Conf.User.UserSiYuanAssetSize),
ProxyURL: Conf.System.NetworkProxy.String(),
Server: util.AliyunServer,
cloudInfo, err := buildCloudInfo()
if nil != err {
return
}
syncContext := map[string]interface{}{CtxPushMsg: CtxPushMsgToStatusBar}

Expand Down Expand Up @@ -471,3 +467,20 @@ func contextPushMsg(context map[string]interface{}, msg string) {
util.PushEndlessProgress(msg)
}
}

func buildCloudInfo() (ret *dejavu.CloudInfo, err error) {
if nil == Conf.User || "" == Conf.Sync.CloudName {
err = errors.New("invalid cloud info")
return
}

ret = &dejavu.CloudInfo{
Dir: Conf.Sync.CloudName,
UserID: Conf.User.UserId,
Token: Conf.User.UserToken,
LimitSize: int64(Conf.User.UserSiYuanRepoSize - Conf.User.UserSiYuanAssetSize),
ProxyURL: Conf.System.NetworkProxy.String(),
Server: util.AliyunServer,
}
return
}
44 changes: 39 additions & 5 deletions kernel/model/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/88250/gulu"
"github.com/dustin/go-humanize"
gitignore "github.com/sabhiram/go-gitignore"
"github.com/siyuan-note/dejavu"
"github.com/siyuan-note/encryption"
"github.com/siyuan-note/filelock"
"github.com/siyuan-note/siyuan/kernel/cache"
Expand Down Expand Up @@ -1150,9 +1151,16 @@ func CreateCloudSyncDir(name string) (err error) {
return errors.New(Conf.Language(37))
}

err = createCloudSyncDirOSS(name)
if nil != err {
return
if Conf.Sync.UseDataRepo {
var cloudInfo *dejavu.CloudInfo
cloudInfo, err = buildCloudInfo()
if nil != err {
return
}

err = dejavu.CreateCloudRepo(name, cloudInfo)
} else {
err = createCloudSyncDirOSS(name)
}
return
}
Expand All @@ -1165,7 +1173,18 @@ func RemoveCloudSyncDir(name string) (err error) {
return
}

err = removeCloudDirPath("sync/" + name)
if Conf.Sync.UseDataRepo {
var cloudInfo *dejavu.CloudInfo
cloudInfo, err = buildCloudInfo()
if nil != err {
return
}

err = dejavu.RemoveCloudRepo(name, cloudInfo)
} else {
err = removeCloudDirPath("sync/" + name)
}

if nil != err {
return
}
Expand All @@ -1179,8 +1198,23 @@ func RemoveCloudSyncDir(name string) (err error) {

func ListCloudSyncDir() (syncDirs []*Sync, hSize string, err error) {
syncDirs = []*Sync{}
var dirs []map[string]interface{}
var size int64
if Conf.Sync.UseDataRepo {
var cloudInfo *dejavu.CloudInfo
cloudInfo, err = buildCloudInfo()
if nil != err {
return
}

dirs, size, err = dejavu.GetCloudRepos(cloudInfo)
} else {
dirs, size, err = listCloudSyncDirOSS()
}
if nil != err {
return
}

dirs, size, err := listCloudSyncDirOSS()
for _, d := range dirs {
dirSize := int64(d["size"].(float64))
syncDirs = append(syncDirs, &Sync{
Expand Down

0 comments on commit 114d854

Please sign in to comment.