mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 23:20:13 +01:00
✨ 数据仓库支持云端备份 https://github.com/siyuan-note/siyuan/issues/5336
This commit is contained in:
parent
4388d8dee7
commit
3e5e0376a3
5 changed files with 92 additions and 6 deletions
|
|
@ -43,6 +43,42 @@ func checkoutRepo(c *gin.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func downloadCloudSnapshot(c *gin.Context) {
|
||||||
|
ret := gulu.Ret.NewResult()
|
||||||
|
defer c.JSON(http.StatusOK, ret)
|
||||||
|
|
||||||
|
arg, ok := util.JsonArg(c, ret)
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
id := arg["id"].(string)
|
||||||
|
tag := arg["tag"].(string)
|
||||||
|
if err := model.DownloadCloudSnapshot(tag, id); nil != err {
|
||||||
|
ret.Code = -1
|
||||||
|
ret.Msg = err.Error()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func uploadCloudSnapshot(c *gin.Context) {
|
||||||
|
ret := gulu.Ret.NewResult()
|
||||||
|
defer c.JSON(http.StatusOK, ret)
|
||||||
|
|
||||||
|
arg, ok := util.JsonArg(c, ret)
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
id := arg["id"].(string)
|
||||||
|
tag := arg["tag"].(string)
|
||||||
|
if err := model.UploadCloudSnapshot(tag, id); nil != err {
|
||||||
|
ret.Code = -1
|
||||||
|
ret.Msg = err.Error()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func getRepoSnapshots(c *gin.Context) {
|
func getRepoSnapshots(c *gin.Context) {
|
||||||
ret := gulu.Ret.NewResult()
|
ret := gulu.Ret.NewResult()
|
||||||
defer c.JSON(http.StatusOK, ret)
|
defer c.JSON(http.StatusOK, ret)
|
||||||
|
|
|
||||||
|
|
@ -260,6 +260,8 @@ func ServeAPI(ginServer *gin.Engine) {
|
||||||
ginServer.Handle("POST", "/api/repo/getRepoSnapshots", model.CheckAuth, getRepoSnapshots)
|
ginServer.Handle("POST", "/api/repo/getRepoSnapshots", model.CheckAuth, getRepoSnapshots)
|
||||||
ginServer.Handle("POST", "/api/repo/getRepoTagSnapshots", model.CheckAuth, getRepoTagSnapshots)
|
ginServer.Handle("POST", "/api/repo/getRepoTagSnapshots", model.CheckAuth, getRepoTagSnapshots)
|
||||||
ginServer.Handle("POST", "/api/repo/getCloudRepoTagSnapshots", model.CheckAuth, getCloudRepoTagSnapshots)
|
ginServer.Handle("POST", "/api/repo/getCloudRepoTagSnapshots", model.CheckAuth, getCloudRepoTagSnapshots)
|
||||||
|
ginServer.Handle("POST", "/api/repo/uploadCloudSnapshot", model.CheckAuth, uploadCloudSnapshot)
|
||||||
|
ginServer.Handle("POST", "/api/repo/downloadCloudSnapshot", model.CheckAuth, downloadCloudSnapshot)
|
||||||
|
|
||||||
ginServer.Handle("POST", "/api/notification/pushMsg", model.CheckAuth, pushMsg)
|
ginServer.Handle("POST", "/api/notification/pushMsg", model.CheckAuth, pushMsg)
|
||||||
ginServer.Handle("POST", "/api/notification/pushErrMsg", model.CheckAuth, pushErrMsg)
|
ginServer.Handle("POST", "/api/notification/pushErrMsg", model.CheckAuth, pushErrMsg)
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ require (
|
||||||
github.com/qiniu/go-sdk/v7 v7.13.0
|
github.com/qiniu/go-sdk/v7 v7.13.0
|
||||||
github.com/radovskyb/watcher v1.0.7
|
github.com/radovskyb/watcher v1.0.7
|
||||||
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06
|
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06
|
||||||
github.com/siyuan-note/dejavu v0.0.0-20220705134218-88ed5d571f17
|
github.com/siyuan-note/dejavu v0.0.0-20220705135659-781eeee791d6
|
||||||
github.com/siyuan-note/encryption v0.0.0-20220612074546-f1dd94fe8676
|
github.com/siyuan-note/encryption v0.0.0-20220612074546-f1dd94fe8676
|
||||||
github.com/siyuan-note/eventbus v0.0.0-20220624162334-ca7c06dc771f
|
github.com/siyuan-note/eventbus v0.0.0-20220624162334-ca7c06dc771f
|
||||||
github.com/siyuan-note/filelock v0.0.0-20220704090116-54dfb035283f
|
github.com/siyuan-note/filelock v0.0.0-20220704090116-54dfb035283f
|
||||||
|
|
|
||||||
|
|
@ -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/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/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546/go.mod h1:TrYk7fJVaAttu97ZZKrO9UbRa8izdowaMIZcxYMbVaw=
|
||||||
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
||||||
github.com/siyuan-note/dejavu v0.0.0-20220705134218-88ed5d571f17 h1:jGNRM0wvFekdVPOM2+IYpuAE2NLf1QNuxz4yKrJ9jMw=
|
github.com/siyuan-note/dejavu v0.0.0-20220705135659-781eeee791d6 h1:N94kPO6BOsB4eDZ73hlugU6qLajULI4OhkU/yOX4hno=
|
||||||
github.com/siyuan-note/dejavu v0.0.0-20220705134218-88ed5d571f17/go.mod h1:ral+X0pNW6nSQVvIcxllUXSczCaY4UOCT2iGlO4YNg0=
|
github.com/siyuan-note/dejavu v0.0.0-20220705135659-781eeee791d6/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 h1:QB9TjJQFhXhZ6dAtPpY02DlzHAQm1C+WqZq6OadG8mI=
|
||||||
github.com/siyuan-note/encryption v0.0.0-20220612074546-f1dd94fe8676/go.mod h1:H8fyqqAbp9XreANjeSbc72zEdFfKTXYN34tc1TjZwtw=
|
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=
|
github.com/siyuan-note/eventbus v0.0.0-20220624162334-ca7c06dc771f h1:JMobMNZ7AqaKKyEK+WeWFhix/2TDQXgPZDajU00IybU=
|
||||||
|
|
|
||||||
|
|
@ -175,9 +175,7 @@ func CheckoutRepo(id string) (err error) {
|
||||||
Conf.Sync.Enabled = false
|
Conf.Sync.Enabled = false
|
||||||
Conf.Save()
|
Conf.Save()
|
||||||
|
|
||||||
_, _, err = repo.Checkout(id, map[string]interface{}{
|
_, _, err = repo.Checkout(id, map[string]interface{}{CtxPushMsg: CtxPushMsgToStatusBarAndProgress})
|
||||||
CtxPushMsg: CtxPushMsgToStatusBarAndProgress,
|
|
||||||
})
|
|
||||||
if nil != err {
|
if nil != err {
|
||||||
util.PushClearProgress()
|
util.PushClearProgress()
|
||||||
return
|
return
|
||||||
|
|
@ -193,6 +191,56 @@ func CheckoutRepo(id string) (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DownloadCloudSnapshot(tag, id string) (err error) {
|
||||||
|
if 1 > len(Conf.Repo.Key) {
|
||||||
|
err = errors.New(Conf.Language(26))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
repo, err := newRepository()
|
||||||
|
if nil != err {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
cloudInfo, err := buildCloudInfo()
|
||||||
|
if nil != err {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
downloadFileCount, downloadChunkCount, downloadBytes, err := repo.DownloadTagIndex(tag, id, cloudInfo, map[string]interface{}{CtxPushMsg: CtxPushMsgToStatusBarAndProgress})
|
||||||
|
if nil != err {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
util.LogInfof("downloaded snapshot [%s], files [%d] chunks [%d], received bytes [%d]", tag, downloadFileCount, downloadChunkCount, downloadBytes)
|
||||||
|
util.PushClearProgress()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func UploadCloudSnapshot(tag, id string) (err error) {
|
||||||
|
if 1 > len(Conf.Repo.Key) {
|
||||||
|
err = errors.New(Conf.Language(26))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
repo, err := newRepository()
|
||||||
|
if nil != err {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
cloudInfo, err := buildCloudInfo()
|
||||||
|
if nil != err {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
uploadFileCount, uploadChunkCount, uploadBytes, err := repo.UploadTagIndex(tag, id, cloudInfo, map[string]interface{}{CtxPushMsg: CtxPushMsgToStatusBarAndProgress})
|
||||||
|
if nil != err {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
util.LogInfof("uploaded snapshot [%s], files [%d] chunks [%d], sent bytes [%d]", tag, uploadFileCount, uploadChunkCount, uploadBytes)
|
||||||
|
util.PushClearProgress()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func GetCloudRepoTagSnapshots() (tags []*dejavu.Log, err error) {
|
func GetCloudRepoTagSnapshots() (tags []*dejavu.Log, err error) {
|
||||||
if 1 > len(Conf.Repo.Key) {
|
if 1 > len(Conf.Repo.Key) {
|
||||||
err = errors.New(Conf.Language(26))
|
err = errors.New(Conf.Language(26))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue