mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-02 23:29:27 +08:00
✨ 数据仓库支持云端备份 https://github.com/siyuan-note/siyuan/issues/5336
This commit is contained in:
parent
313074414a
commit
e693f3c3e8
@ -919,9 +919,9 @@
|
||||
"147": "創建了一個新的數據快照,耗時 %.2fs",
|
||||
"148": "檢查數據快照,沒有發現任何變化,耗時 %.2fs",
|
||||
"149": "已經同步數據快照,耗時 %.2fs",
|
||||
"150": "上傳/下載文件數 %d/%d\n上傳/下載分塊數 %d/%d\n發送/接受字節數 %s/%s",
|
||||
"150": "上傳/下載文件數 %d/%d\n上傳/下載分塊數 %d/%d\n發送/接收字節數 %s/%s",
|
||||
"151": "請勿包含符號 \\ / : * ? " ' < > |",
|
||||
"152": "上傳文件數 %d 上傳分塊數 %d 發送字節數 %s",
|
||||
"153": "下載文件數 %d 下載分塊數 %d 接受字節數 %s"
|
||||
"153": "下載文件數 %d 下載分塊數 %d 接收字節數 %s"
|
||||
}
|
||||
}
|
||||
|
@ -921,9 +921,9 @@
|
||||
"147": "创建了一个新的数据快照,耗时 %.2fs",
|
||||
"148": "检查数据快照,没有发现任何变化,耗时 %.2fs",
|
||||
"149": "已经同步数据快照,耗时 %.2fs",
|
||||
"150": "上传/下载文件数 %d/%d\n上传/下载分块数 %d/%d\n发送/接受字节数 %s/%s",
|
||||
"150": "上传/下载文件数 %d/%d\n上传/下载分块数 %d/%d\n发送/接收字节数 %s/%s",
|
||||
"151": "请勿包含符号 \\ / : * ? " ' < > |",
|
||||
"152": "上传文件数 %d 上传分块数 %d 发送字节数 %s",
|
||||
"153": "下载文件数 %d 下载分块数 %d 接受字节数 %s"
|
||||
"153": "下载文件数 %d 下载分块数 %d 接收字节数 %s"
|
||||
}
|
||||
}
|
||||
|
@ -56,7 +56,6 @@ const renderCloudBackup = () => {
|
||||
<ul class="b3-list">
|
||||
<li class="b3-list-item" style="cursor: auto;">${window.siyuan.languages.sync}<span class="b3-list-item__meta">${response.data.sync ? response.data.sync.hSize : "0B"}</span></li>
|
||||
<li class="b3-list-item" style="cursor: auto;">${window.siyuan.languages.backup}<span class="b3-list-item__meta">${response.data.backup ? response.data.backup.hSize : "0B"}</span></li>
|
||||
<li class="b3-list-item" style="cursor: auto;">${window.siyuan.languages.dataRepo}<span class="b3-list-item__meta">${response.data.hRepoSize}</span></li>
|
||||
<li class="b3-list-item" style="cursor: auto;"><a href="https://ld246.com/settings/file?type=3" target="_blank">${window.siyuan.languages.cdn}</a><span class="b3-list-item__meta">${response.data.hAssetSize}</span></li>
|
||||
<li class="b3-list-item" style="cursor: auto;">${window.siyuan.languages.total}<span class="b3-list-item__meta">${response.data.hSize}</span></li>
|
||||
<li class="b3-list-item" style="cursor: auto;">${window.siyuan.languages.sizeLimit}<span class="b3-list-item__meta">${response.data.hTotalSize}</span></li>
|
||||
|
@ -106,7 +106,7 @@ func getCloudSpace(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
||||
sync, backup, size, assetSize, repoSize, totalSize, err := model.GetCloudSpace()
|
||||
sync, backup, size, assetSize, totalSize, err := model.GetCloudSpace()
|
||||
if nil != err {
|
||||
ret.Code = 1
|
||||
ret.Msg = err.Error()
|
||||
@ -121,7 +121,6 @@ func getCloudSpace(c *gin.Context) {
|
||||
"sync": sync,
|
||||
"backup": backup,
|
||||
"hAssetSize": assetSize,
|
||||
"hRepoSize": repoSize,
|
||||
"hSize": size,
|
||||
"hTotalSize": totalSize,
|
||||
"hTrafficUploadSize": hTrafficUploadSize,
|
||||
|
@ -118,6 +118,24 @@ func getCloudRepoTagSnapshots(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
func removeCloudRepoTagSnapshot(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
||||
arg, ok := util.JsonArg(c, ret)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
tag := arg["tag"].(string)
|
||||
err := model.RemoveCloudRepoTag(tag)
|
||||
if nil != err {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func getRepoTagSnapshots(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
@ -134,6 +152,24 @@ func getRepoTagSnapshots(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
func removeRepoTagSnapshot(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
||||
arg, ok := util.JsonArg(c, ret)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
tag := arg["tag"].(string)
|
||||
err := model.RemoveTagSnapshot(tag)
|
||||
if nil != err {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func createSnapshot(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
@ -259,7 +259,9 @@ func ServeAPI(ginServer *gin.Engine) {
|
||||
ginServer.Handle("POST", "/api/repo/checkoutRepo", model.CheckAuth, checkoutRepo)
|
||||
ginServer.Handle("POST", "/api/repo/getRepoSnapshots", model.CheckAuth, getRepoSnapshots)
|
||||
ginServer.Handle("POST", "/api/repo/getRepoTagSnapshots", model.CheckAuth, getRepoTagSnapshots)
|
||||
ginServer.Handle("POST", "/api/repo/removeRepoTagSnapshot", model.CheckAuth, removeRepoTagSnapshot)
|
||||
ginServer.Handle("POST", "/api/repo/getCloudRepoTagSnapshots", model.CheckAuth, getCloudRepoTagSnapshots)
|
||||
ginServer.Handle("POST", "/api/repo/removeCloudRepoTagSnapshot", model.CheckAuth, removeCloudRepoTagSnapshot)
|
||||
ginServer.Handle("POST", "/api/repo/uploadCloudSnapshot", model.CheckAuth, uploadCloudSnapshot)
|
||||
ginServer.Handle("POST", "/api/repo/downloadCloudSnapshot", model.CheckAuth, downloadCloudSnapshot)
|
||||
|
||||
|
@ -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-20220705162638-58c67df5a0ca
|
||||
github.com/siyuan-note/dejavu v0.0.0-20220706020527-a7a0d661f81b
|
||||
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
|
||||
@ -112,7 +112,7 @@ require (
|
||||
|
||||
replace github.com/mattn/go-sqlite3 => github.com/88250/go-sqlite3 v1.14.13-0.20220412041952-88c3aaa8595e
|
||||
|
||||
//replace github.com/siyuan-note/dejavu => D:\88250\dejavu
|
||||
replace github.com/siyuan-note/dejavu => D:\88250\dejavu
|
||||
//replace github.com/siyuan-note/httpclient => D:\88250\httpclient
|
||||
//replace github.com/siyuan-note/filelock => D:\88250\filelock
|
||||
//replace github.com/88250/lute => D:\gogogo\src\github.com\88250\lute
|
||||
|
@ -423,6 +423,8 @@ github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546/go.mod h1:TrYk7fJV
|
||||
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
||||
github.com/siyuan-note/dejavu v0.0.0-20220705162638-58c67df5a0ca h1:2CxMRaQjDv101Ez/Iwt972rEvLZqNc+BZ6W9EGFTNgg=
|
||||
github.com/siyuan-note/dejavu v0.0.0-20220705162638-58c67df5a0ca/go.mod h1:ral+X0pNW6nSQVvIcxllUXSczCaY4UOCT2iGlO4YNg0=
|
||||
github.com/siyuan-note/dejavu v0.0.0-20220706020527-a7a0d661f81b h1:V3FWL5q6JLv8evvnoAOrqo5cxDipYILcuq/jJxOpHO8=
|
||||
github.com/siyuan-note/dejavu v0.0.0-20220706020527-a7a0d661f81b/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=
|
||||
|
@ -59,7 +59,7 @@ func RemoveCloudBackup() (err error) {
|
||||
}
|
||||
|
||||
func getCloudAvailableBackupSize() (size int64, err error) {
|
||||
sync, _, assetSize, repoSize, err := getCloudSpaceOSS()
|
||||
sync, _, assetSize, err := getCloudSpaceOSS()
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
@ -68,12 +68,12 @@ func getCloudAvailableBackupSize() (size int64, err error) {
|
||||
if nil != sync {
|
||||
syncSize = int64(sync["size"].(float64))
|
||||
}
|
||||
size = int64(Conf.User.UserSiYuanRepoSize) - syncSize - assetSize - repoSize
|
||||
size = int64(Conf.User.UserSiYuanRepoSize) - syncSize - assetSize
|
||||
return
|
||||
}
|
||||
|
||||
func GetCloudSpace() (s *Sync, b *Backup, hSize, hAssetSize, hRepoSize, hTotalSize string, err error) {
|
||||
sync, backup, assetSize, repoSize, err := getCloudSpaceOSS()
|
||||
func GetCloudSpace() (s *Sync, b *Backup, hSize, hAssetSize, hTotalSize string, err error) {
|
||||
sync, backup, assetSize, err := getCloudSpaceOSS()
|
||||
if nil != err {
|
||||
err = errors.New(Conf.Language(30) + " " + err.Error())
|
||||
return
|
||||
@ -100,9 +100,8 @@ func GetCloudSpace() (s *Sync, b *Backup, hSize, hAssetSize, hRepoSize, hTotalSi
|
||||
HSize: humanize.Bytes(uint64(backupSize)),
|
||||
Updated: backupUpdated,
|
||||
}
|
||||
totalSize = syncSize + backupSize + assetSize + repoSize
|
||||
totalSize = syncSize + backupSize + assetSize
|
||||
hAssetSize = humanize.Bytes(uint64(assetSize))
|
||||
hRepoSize = humanize.Bytes(uint64(repoSize))
|
||||
hSize = humanize.Bytes(uint64(totalSize))
|
||||
hTotalSize = byteCountSI(int64(Conf.User.UserSiYuanRepoSize))
|
||||
return
|
||||
|
@ -32,19 +32,29 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/88250/gulu"
|
||||
"github.com/imroc/req/v3"
|
||||
"github.com/panjf2000/ants/v2"
|
||||
"github.com/qiniu/go-sdk/v7/storage"
|
||||
"github.com/siyuan-note/httpclient"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
||||
func getCloudSpaceOSS() (sync, backup map[string]interface{}, assetSize, repoSize int64, err error) {
|
||||
func getCloudSpaceOSS() (sync, backup map[string]interface{}, assetSize int64, err error) {
|
||||
result := map[string]interface{}{}
|
||||
request := httpclient.NewCloudRequest(Conf.System.NetworkProxy.String())
|
||||
resp, err := request.
|
||||
SetResult(&result).
|
||||
SetBody(map[string]string{"token": Conf.User.UserToken}).
|
||||
Post(util.AliyunServer + "/apis/siyuan/data/getSiYuanWorkspace?uid=" + Conf.User.UserId)
|
||||
|
||||
var resp *req.Response
|
||||
if Conf.Sync.UseDataRepo {
|
||||
resp, err = request.
|
||||
SetResult(&result).
|
||||
SetBody(map[string]string{"token": Conf.User.UserToken}).
|
||||
Post(util.AliyunServer + "/apis/siyuan/dejavu/getRepoStat?uid=" + Conf.User.UserId)
|
||||
} else {
|
||||
resp, err = request.
|
||||
SetResult(&result).
|
||||
SetBody(map[string]string{"token": Conf.User.UserToken}).
|
||||
Post(util.AliyunServer + "/apis/siyuan/data/getSiYuanWorkspace?uid=" + Conf.User.UserId)
|
||||
}
|
||||
if nil != err {
|
||||
util.LogErrorf("get cloud space failed: %s", err)
|
||||
err = ErrFailedToConnectCloudServer
|
||||
@ -67,7 +77,6 @@ func getCloudSpaceOSS() (sync, backup map[string]interface{}, assetSize, repoSiz
|
||||
sync = data["sync"].(map[string]interface{})
|
||||
backup = data["backup"].(map[string]interface{})
|
||||
assetSize = int64(data["assetSize"].(float64))
|
||||
repoSize = int64(data["repoSize"].(float64))
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -245,6 +245,34 @@ func UploadCloudSnapshot(tag, id string) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func RemoveCloudRepoTag(tag string) (err error) {
|
||||
if 1 > len(Conf.Repo.Key) {
|
||||
err = errors.New(Conf.Language(26))
|
||||
return
|
||||
}
|
||||
|
||||
if "" == tag {
|
||||
err = errors.New("tag is empty")
|
||||
return
|
||||
}
|
||||
|
||||
repo, err := newRepository()
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
cloudInfo, err := buildCloudInfo()
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
err = repo.RemoveCloudRepoTag(tag, cloudInfo, map[string]interface{}{CtxPushMsg: CtxPushMsgToStatusBar})
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func GetCloudRepoTagSnapshots() (ret []*dejavu.Log, err error) {
|
||||
if 1 > len(Conf.Repo.Key) {
|
||||
err = errors.New(Conf.Language(26))
|
||||
@ -285,6 +313,21 @@ func GetTagSnapshots() (ret []*dejavu.Log, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func RemoveTagSnapshot(tag string) (err error) {
|
||||
if 1 > len(Conf.Repo.Key) {
|
||||
err = errors.New(Conf.Language(26))
|
||||
return
|
||||
}
|
||||
|
||||
repo, err := newRepository()
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
err = repo.RemoveTag(tag)
|
||||
return
|
||||
}
|
||||
|
||||
func TagSnapshot(id, name string) (err error) {
|
||||
if 1 > len(Conf.Repo.Key) {
|
||||
err = errors.New(Conf.Language(26))
|
||||
|
Loading…
Reference in New Issue
Block a user