An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: 开源云端同步服务实现 https://github.com/siyuan-note/siyuan/issues/6445
Liang Ding272db50b88ff
diff --git a/kernel/api/repo.go b/kernel/api/repo.goindex c42d1bf73e..60927e0fc4 100644--- a/kernel/api/repo.go+++ b/kernel/api/repo.go@@ -21,7 +21,6 @@ import ("net/http""github.com/88250/gulu"- "github.com/dustin/go-humanize""github.com/gin-gonic/gin""github.com/siyuan-note/siyuan/kernel/model""github.com/siyuan-note/siyuan/kernel/util"@@ -31,7 +30,7 @@ func getCloudSpace(c *gin.Context) {ret := gulu.Ret.NewResult()defer c.JSON(http.StatusOK, ret)- sync, backup, size, assetSize, totalSize, err := model.GetCloudSpace()+ sync, backup, size, assetSize, totalSize, hTrafficUploadSize, hTrafficDownloadSize, err := model.GetCloudSpace()if nil != err {ret.Code = 1ret.Msg = err.Error()@@ -39,9 +38,6 @@ func getCloudSpace(c *gin.Context) {return}- hTrafficUploadSize := humanize.Bytes(uint64(model.Conf.User.UserTrafficUpload))- hTrafficDownloadSize := humanize.Bytes(uint64(model.Conf.User.UserTrafficDownload))-ret.Data = map[string]interface{}{"sync": sync,"backup": backup,diff --git a/kernel/go.mod b/kernel/go.modindex 5106a18aa8..043e0ad0c5 100644--- a/kernel/go.mod+++ b/kernel/go.mod@@ -36,7 +36,7 @@ require (github.com/panjf2000/ants/v2 v2.6.0github.com/patrickmn/go-cache v2.1.0+incompatiblegithub.com/radovskyb/watcher v1.0.7- github.com/siyuan-note/dejavu v0.0.0-20221102075801-148594bd43e2+ github.com/siyuan-note/dejavu v0.0.0-20221102101918-9258bfd2c7cagithub.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75github.com/siyuan-note/eventbus v0.0.0-20220916025349-3ac6e75522dagithub.com/siyuan-note/filelock v0.0.0-20221007163134-7e64809023ef@@ -69,7 +69,7 @@ require (github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirectgithub.com/golang/glog v1.0.0 // indirectgithub.com/golang/mock v1.6.0 // indirect- github.com/google/pprof v0.0.0-20221010195024-131d412537ea // indirect+ github.com/google/pprof v0.0.0-20221102093814-76f304f74e5e // indirectgithub.com/google/uuid v1.3.0 // indirectgithub.com/gopherjs/gopherjs v1.17.2 // indirectgithub.com/gorilla/context v1.1.1 // indirectdiff --git a/kernel/go.sum b/kernel/go.sumindex 2903e393a2..57c4b12484 100644--- a/kernel/go.sum+++ b/kernel/go.sum@@ -158,8 +158,8 @@ github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUOgithub.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=-github.com/google/pprof v0.0.0-20221010195024-131d412537ea h1:R3VfsTXMMK4JCWZDdxScmnTzu9n9YRsDvguLis0U/b8=-github.com/google/pprof v0.0.0-20221010195024-131d412537ea/go.mod h1:dDKJzRmX4S37WGHujM7tX//fmj1uioxKzKxz3lo4HJo=+github.com/google/pprof v0.0.0-20221102093814-76f304f74e5e h1:F1LLQqQ8WoIbyoxLUY+JUZe1kuHdxThM6CPUATzE6Io=+github.com/google/pprof v0.0.0-20221102093814-76f304f74e5e/go.mod h1:dDKJzRmX4S37WGHujM7tX//fmj1uioxKzKxz3lo4HJo=github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=@@ -353,8 +353,8 @@ github.com/shurcooL/reactions v0.0.0-20181006231557-f2e0b4ca5b82/go.mod h1:TCR1lgithub.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-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/dejavu v0.0.0-20221102101918-9258bfd2c7ca h1:yxlwyy/GxuzIBhTadAxjXNGAJYc3yrTjX8Yqq1SlVg4=+github.com/siyuan-note/dejavu v0.0.0-20221102101918-9258bfd2c7ca/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=diff --git a/kernel/model/conf.go b/kernel/model/conf.goindex 6327a278a3..ff42b3d0a8 100644--- a/kernel/model/conf.go+++ b/kernel/model/conf.go@@ -245,6 +245,15 @@ func InitConf() {if nil == Conf.Sync.OSS {Conf.Sync.OSS = &conf.OSS{}}+ endpoint := Conf.Sync.OSS.Endpoint+ endpoint = strings.TrimSpace(endpoint)+ if !strings.HasPrefix(endpoint, "http://") && !strings.HasPrefix(endpoint, "https://") {+ endpoint = "http://" + endpoint+ }+ if !strings.HasSuffix(endpoint, "/") {+ endpoint = endpoint + "/"+ }+ Conf.Sync.OSS.Endpoint = endpointif nil == Conf.Api {Conf.Api = conf.NewAPI()diff --git a/kernel/model/repository.go b/kernel/model/repository.goindex 25e4756bc3..d71b7ca006 100644--- a/kernel/model/repository.go+++ b/kernel/model/repository.go@@ -38,7 +38,6 @@ import ("github.com/siyuan-note/dejavu/entity""github.com/siyuan-note/encryption""github.com/siyuan-note/eventbus"- "github.com/siyuan-note/httpclient""github.com/siyuan-note/logging""github.com/siyuan-note/siyuan/kernel/cache""github.com/siyuan-note/siyuan/kernel/conf"@@ -1054,69 +1053,54 @@ type Sync struct {SaveDir string `json:"saveDir"` // 本地同步数据存放目录路径}-func GetCloudSpace() (s *Sync, b *Backup, hSize, hAssetSize, hTotalSize string, err error) {- sync, backup, assetSize, err := getCloudSpaceOSS()+func GetCloudSpace() (s *Sync, b *Backup, hSize, hAssetSize, hTotalSize, hTrafficUploadSize, hTrafficDownloadSize string, err error) {+ stat, 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)- }+ syncSize := stat.Sync.Size+ syncUpdated := stat.Sync.Updateds = &Sync{Size: syncSize,HSize: humanize.Bytes(uint64(syncSize)),Updated: syncUpdated,}- if nil != backup {- backupSize = int64(backup["size"].(float64))- backupUpdated = backup["updated"].(string)- }+ backupSize := stat.Backup.Size+ backupUpdated := stat.Backup.Updatedb = &Backup{Size: backupSize,HSize: humanize.Bytes(uint64(backupSize)),Updated: backupUpdated,}- totalSize = syncSize + backupSize + assetSize++ assetSize := stat.AssetSize+ totalSize := syncSize + backupSize + assetSizehAssetSize = humanize.Bytes(uint64(assetSize))hSize = humanize.Bytes(uint64(totalSize))- hTotalSize = humanize.Bytes(uint64(Conf.User.UserSiYuanRepoSize))+ hTotalSize = "-"+ hTrafficUploadSize = "-"+ hTrafficDownloadSize = "-"+ if conf.ProviderSiYuan == Conf.Sync.Provider {+ hTotalSize = humanize.Bytes(uint64(Conf.User.UserSiYuanRepoSize))+ hTrafficUploadSize = humanize.Bytes(uint64(Conf.User.UserTrafficUpload))+ hTrafficDownloadSize = humanize.Bytes(uint64(Conf.User.UserTrafficDownload))+ }return}-func getCloudSpaceOSS() (sync, backup map[string]interface{}, assetSize int64, err error) {- result := map[string]interface{}{}- resp, err := httpclient.NewCloudRequest().- SetResult(&result).- SetBody(map[string]string{"token": Conf.User.UserToken}).- Post(util.AliyunServer + "/apis/siyuan/dejavu/getRepoStat?uid=" + Conf.User.UserId)-+func getCloudSpaceOSS() (stat *cloud.Stat, err error) {+ repo, err := newRepository()if nil != err {- logging.LogErrorf("get cloud space failed: %s", err)- err = ErrFailedToConnectCloudServerreturn}- if 401 == resp.StatusCode {- err = errors.New(Conf.Language(31))- return- }-- code := result["code"].(float64)- if 0 != code {- logging.LogErrorf("get cloud space failed: %s", result["msg"])- err = errors.New(result["msg"].(string))+ stat, err = repo.GetCloudRepoStat()+ if nil != err {+ logging.LogErrorf("get cloud repo stat failed: %s", err)return}-- data := result["data"].(map[string]interface{})- sync = data["sync"].(map[string]interface{})- backup = data["backup"].(map[string]interface{})- assetSize = int64(data["assetSize"].(float64))return}