Skip to content

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

:fire: 移除旧版云端同步和备份功能入口 https://github.com/siyuan-note/siyuan/issues/5405

Liang Dinge936b9cf0b26
diff --git a/kernel/api/router.go b/kernel/api/router.go
index 2ef8f34fa0..8c9a32ef95 100644
--- a/kernel/api/router.go
+++ b/kernel/api/router.go
@@ -167,7 +167,6 @@ func ServeAPI(ginServer *gin.Engine) {
ginServer.Handle("POST", "/api/sync/performSync", model.CheckAuth, performSync)
ginServer.Handle("POST", "/api/sync/performBootSync", model.CheckAuth, performBootSync)
ginServer.Handle("POST", "/api/sync/getBootSync", model.CheckAuth, getBootSync)
- ginServer.Handle("POST", "/api/sync/getSyncDirection", model.CheckAuth, getSyncDirection)
ginServer.Handle("POST", "/api/inbox/getShorthands", model.CheckAuth, getShorthands)
ginServer.Handle("POST", "/api/inbox/removeShorthands", model.CheckAuth, removeShorthands)
diff --git a/kernel/api/sync.go b/kernel/api/sync.go
index 7dbf7d0705..aedb50a810 100644
--- a/kernel/api/sync.go
+++ b/kernel/api/sync.go
@@ -25,19 +25,6 @@ import (
"github.com/siyuan-note/siyuan/kernel/util"
)
-func getSyncDirection(c *gin.Context) {
- ret := gulu.Ret.NewResult()
- defer c.JSON(http.StatusOK, ret)
-
- arg, ok := util.JsonArg(c, ret)
- if !ok {
- return
- }
-
- cloudDirName := arg["name"].(string)
- ret.Code, ret.Msg = model.GetSyncDirection(cloudDirName)
-}
-
func getBootSync(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)
diff --git a/kernel/model/backup.go b/kernel/model/backup.go
deleted file mode 100644
index 6022f3eeb1..0000000000
--- a/kernel/model/backup.go
+++ /dev/null
@@ -1,87 +0,0 @@
-// SiYuan - Build Your Eternal Digital Garden
-// Copyright (c) 2020-present, b3log.org
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Affero General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Affero General Public License for more details.
-//
-// You should have received a copy of the GNU Affero General Public License
-// along with this program. If not, see <https://www.gnu.org/licenses/>.
-
-package model
-
-import (
- "errors"
- "fmt"
-
- "github.com/dustin/go-humanize"
-)
-
-type Backup struct {
- Size int64 `json:"size"`
- HSize string `json:"hSize"`
- Updated string `json:"updated"`
- SaveDir string `json:"saveDir"` // 本地备份数据存放目录路径
-}
-
-type Sync struct {
- Size int64 `json:"size"`
- HSize string `json:"hSize"`
- Updated string `json:"updated"`
- CloudName string `json:"cloudName"` // 云端同步数据存放目录名
- SaveDir string `json:"saveDir"` // 本地同步数据存放目录路径
-}
-
-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
- }
-
- var totalSize, syncSize, backupSize int64
- var syncUpdated, backupUpdated string
- if nil != sync {
- syncSize = int64(sync["size"].(float64))
- syncUpdated = sync["updated"].(string)
- }
- s = &Sync{
- Size: syncSize,
- HSize: humanize.Bytes(uint64(syncSize)),
- Updated: syncUpdated,
- }
-
- if nil != backup {
- backupSize = int64(backup["size"].(float64))
- backupUpdated = backup["updated"].(string)
- }
- b = &Backup{
- Size: backupSize,
- HSize: humanize.Bytes(uint64(backupSize)),
- Updated: backupUpdated,
- }
- totalSize = syncSize + backupSize + assetSize
- hAssetSize = humanize.Bytes(uint64(assetSize))
- hSize = humanize.Bytes(uint64(totalSize))
- hTotalSize = byteCountSI(int64(Conf.User.UserSiYuanRepoSize))
- return
-}
-
-func byteCountSI(b int64) string {
- const unit = 1000
- if b < unit {
- return fmt.Sprintf("%d B", b)
- }
- div, exp := int64(unit), 0
- for n := b / unit; n >= unit; n /= unit {
- div *= unit
- exp++
- }
- return fmt.Sprintf("%.1f %cB", float64(b)/float64(div), "kMGTPE"[exp])
-}
diff --git a/kernel/model/repository.go b/kernel/model/repository.go
index 5565e8e1af..9db36b5d8f 100644
--- a/kernel/model/repository.go
+++ b/kernel/model/repository.go
@@ -27,6 +27,7 @@ import (
"time"
"github.com/88250/gulu"
+ "github.com/dustin/go-humanize"
"github.com/siyuan-note/dejavu"
"github.com/siyuan-note/dejavu/entity"
"github.com/siyuan-note/encryption"
@@ -221,7 +222,7 @@ func DownloadCloudSnapshot(tag, id string) (err error) {
if nil != err {
return
}
- msg := fmt.Sprintf(Conf.Language(153), downloadFileCount, downloadChunkCount, byteCountSI(downloadBytes))
+ msg := fmt.Sprintf(Conf.Language(153), downloadFileCount, downloadChunkCount, humanize.Bytes(uint64(downloadBytes)))
util.PushMsg(msg, 5000)
util.PushStatusBar(msg)
return
@@ -252,7 +253,7 @@ func UploadCloudSnapshot(tag, id string) (err error) {
}
return
}
- msg := fmt.Sprintf(Conf.Language(152), uploadFileCount, uploadChunkCount, byteCountSI(uploadBytes))
+ msg := fmt.Sprintf(Conf.Language(152), uploadFileCount, uploadChunkCount, humanize.Bytes(uint64(uploadBytes)))
util.PushMsg(msg, 5000)
util.PushStatusBar(msg)
return
@@ -458,7 +459,7 @@ func syncRepo(boot, exit, byHand bool) {
util.LogErrorf("sync data repo failed: %s", err)
msg := fmt.Sprintf(Conf.Language(80), formatErrorMsg(err))
if errors.Is(err, dejavu.ErrCloudStorageSizeExceeded) {
- msg = fmt.Sprintf(Conf.Language(43), byteCountSI(int64(Conf.User.UserSiYuanRepoSize)))
+ msg = fmt.Sprintf(Conf.Language(43), humanize.Bytes(uint64(Conf.User.UserSiYuanRepoSize)))
}
Conf.Sync.Stat = msg
util.PushStatusBar(msg)
@@ -474,7 +475,7 @@ func syncRepo(boot, exit, byHand bool) {
}
util.PushStatusBar(fmt.Sprintf(Conf.Language(149), elapsed.Seconds()))
Conf.Sync.Synced = util.CurrentTimeMillis()
- msg := fmt.Sprintf(Conf.Language(150), trafficStat.UploadFileCount, trafficStat.DownloadFileCount, trafficStat.UploadChunkCount, trafficStat.DownloadChunkCount, byteCountSI(trafficStat.UploadBytes), byteCountSI(trafficStat.DownloadBytes))
+ msg := fmt.Sprintf(Conf.Language(150), trafficStat.UploadFileCount, trafficStat.DownloadFileCount, trafficStat.UploadChunkCount, trafficStat.DownloadChunkCount, humanize.Bytes(uint64(trafficStat.UploadBytes)), humanize.Bytes(uint64(trafficStat.DownloadBytes)))
Conf.Sync.Stat = msg
if 1 > len(mergeResult.Upserts) && 1 > len(mergeResult.Removes) { // 没有数据变更
@@ -740,6 +741,56 @@ func buildCloudInfo() (ret *dejavu.CloudInfo, err error) {
return
}
+type Backup struct {
+ Size int64 `json:"size"`
+ HSize string `json:"hSize"`
+ Updated string `json:"updated"`
+ SaveDir string `json:"saveDir"` // 本地备份数据存放目录路径
+}
+
+type Sync struct {
+ Size int64 `json:"size"`
+ HSize string `json:"hSize"`
+ Updated string `json:"updated"`
+ CloudName string `json:"cloudName"` // 云端同步数据存放目录名
+ SaveDir string `json:"saveDir"` // 本地同步数据存放目录路径
+}
+
+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
+ }
+
+ var totalSize, syncSize, backupSize int64
+ var syncUpdated, backupUpdated string
+ if nil != sync {
+ syncSize = int64(sync["size"].(float64))
+ syncUpdated = sync["updated"].(string)
+ }
+ s = &Sync{
+ Size: syncSize,
+ HSize: humanize.Bytes(uint64(syncSize)),
+ Updated: syncUpdated,
+ }
+
+ if nil != backup {
+ backupSize = int64(backup["size"].(float64))
+ backupUpdated = backup["updated"].(string)
+ }
+ b = &Backup{
+ Size: backupSize,
+ HSize: humanize.Bytes(uint64(backupSize)),
+ Updated: backupUpdated,
+ }
+ totalSize = syncSize + backupSize + assetSize
+ hAssetSize = humanize.Bytes(uint64(assetSize))
+ hSize = humanize.Bytes(uint64(totalSize))
+ hTotalSize = humanize.Bytes(uint64(Conf.User.UserSiYuanRepoSize))
+ return
+}
+
func getCloudSpaceOSS() (sync, backup map[string]interface{}, assetSize int64, err error) {
result := map[string]interface{}{}
resp, err := httpclient.NewCloudRequest().
diff --git a/kernel/model/sync.go b/kernel/model/sync.go
index 9edcd8963e..26ad4626c5 100644
--- a/kernel/model/sync.go
+++ b/kernel/model/sync.go
@@ -30,7 +30,6 @@ import (
"github.com/88250/gulu"
"github.com/dustin/go-humanize"
"github.com/siyuan-note/dejavu"
- "github.com/siyuan-note/filelock"
"github.com/siyuan-note/siyuan/kernel/filesys"
"github.com/siyuan-note/siyuan/kernel/sql"
"github.com/siyuan-note/siyuan/kernel/treenode"
@@ -211,47 +210,6 @@ func SetSyncMode(mode int) (err error) {
var syncLock = sync.Mutex{}
-func getWorkspaceDataConf() (conf *filesys.DataConf, err error) {
- conf = &filesys.DataConf{Updated: util.CurrentTimeMillis(), Device: Conf.System.ID}
- confPath := filepath.Join(Conf.Sync.GetSaveDir(), ".siyuan", "conf.json")
- if !gulu.File.IsExist(confPath) {
- os.MkdirAll(filepath.Dir(confPath), 0755)
- data, _ := gulu.JSON.MarshalIndentJSON(conf, "", " ")
- if err = filelock.NoLockFileWrite(confPath, data); nil != err {
- util.LogErrorf("save sync conf [%s] failed: %s", confPath, err)
- }
- return
- }
-
- data, err := filelock.NoLockFileRead(confPath)
- if nil != err {
- util.LogErrorf("read sync conf [%s] failed: %s", confPath, err)
- return
- }
- if err = gulu.JSON.UnmarshalJSON(data, conf); nil != err {
- filesys.IncWorkspaceDataVer(false, Conf.System.ID) // 尝试恢复 data/.siyuan/conf.json
- util.LogErrorf("unmarshal sync conf [%s] failed: %s", confPath, err)
- err = errors.New(Conf.Language(84))
- return
- }
- return
-}
-
-func incLocalSyncVer() {
- conf, err := getWorkspaceDataConf()
- if nil != err {
- return
- }
-
- conf.SyncVer++
- data, _ := gulu.JSON.MarshalIndentJSON(conf, "", " ")
- confPath := filepath.Join(Conf.Sync.GetSaveDir(), ".siyuan", "conf.json")
- if err = gulu.File.WriteFileSafer(confPath, data, 0644); nil != err {
- util.LogErrorf("save sync conf [%s] failed: %s", confPath, err)
- }
- return
-}
-
func CreateCloudSyncDir(name string) (err error) {
syncLock.Lock()
defer syncLock.Unlock()
@@ -389,23 +347,6 @@ func getIgnoreLines() (ret []string) {
return
}
-func GetSyncDirection(cloudDirName string) (code int, msg string) { // 0:失败,10:上传,20:下载,30:一致,40:使用数据仓库同步
- if !IsSubscriber() {
- return
- }
-
- if "" == cloudDirName {
- return
- }
-
- if !IsValidCloudDirName(cloudDirName) {
- return
- }
-
- // TODO: 彻底移除方向判断
- return 40, ""
-}
-
func IncWorkspaceDataVer() {
filesys.IncWorkspaceDataVer(true, Conf.System.ID)
syncSameCount = 0