From f988805c93264f4c88fe6f7244e4193f3cd233bf Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Mon, 31 Oct 2022 22:42:30 +0800 Subject: [PATCH 1/7] =?UTF-8?q?:art:=20=E6=94=B9=E8=BF=9B=E6=96=87?= =?UTF-8?q?=E6=A1=A3=E6=A0=91=E6=8B=96=E6=8B=BD=E5=BD=A2=E6=88=90=E5=AD=90?= =?UTF-8?q?=E6=96=87=E6=A1=A3=E6=97=B6=E7=9A=84=E5=B1=82=E7=BA=A7=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C=20Fix=20https://github.com/siyuan-note/siyuan/issues/?= =?UTF-8?q?6434?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/file.go | 11 ++++++----- kernel/util/path.go | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/kernel/model/file.go b/kernel/model/file.go index eb18bf34c..efcaebf70 100644 --- a/kernel/model/file.go +++ b/kernel/model/file.go @@ -992,11 +992,6 @@ func MoveDoc(fromBoxID, fromPath, toBoxID, toPath string) (newPath string, err e return } - if depth := strings.Count(toPath, "/"); 6 < depth && !Conf.FileTree.AllowCreateDeeper { - err = errors.New(Conf.Language(118)) - return - } - fromDir := strings.TrimSuffix(fromPath, ".sy") if strings.HasPrefix(toPath, fromDir) { err = errors.New(Conf.Language(87)) @@ -1016,6 +1011,12 @@ func MoveDoc(fromBoxID, fromPath, toBoxID, toPath string) (newPath string, err e return } + childDepth := util.GetChildDocDepth(filepath.Join(util.DataDir, fromBoxID, fromPath)) + if depth := strings.Count(toPath, "/") + childDepth; 6 < depth && !Conf.FileTree.AllowCreateDeeper { + err = errors.New(Conf.Language(118)) + return + } + toBox := Conf.Box(toBoxID) if nil == toBox { err = errors.New(Conf.Language(0)) diff --git a/kernel/util/path.go b/kernel/util/path.go index f630f7a81..26be07a28 100644 --- a/kernel/util/path.go +++ b/kernel/util/path.go @@ -21,6 +21,7 @@ import ( "net" "os" "path" + "path/filepath" "strings" "time" @@ -138,3 +139,23 @@ func TimeFromID(id string) (ret string) { ret = id[:14] return } + +func GetChildDocDepth(treeAbsPath string) (ret int) { + dir := strings.TrimSuffix(treeAbsPath, ".sy") + if !gulu.File.IsDir(dir) { + return + } + + baseDepth := strings.Count(filepath.ToSlash(treeAbsPath), "/") + depth := 1 + filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { + p := filepath.ToSlash(path) + currentDepth := strings.Count(p, "/") + if depth < currentDepth { + depth = currentDepth + } + return nil + }) + ret = depth - baseDepth + return +} From 1eaa791c1dbe57e899c0a83cd57c0df9ca3ff378 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Mon, 31 Oct 2022 22:55:20 +0800 Subject: [PATCH 2/7] =?UTF-8?q?:recycle:=20=E9=87=8D=E6=9E=84=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E4=BB=93=E5=BA=93=E5=90=8C=E6=AD=A5=20Fix=20https://g?= =?UTF-8?q?ithub.com/siyuan-note/siyuan/issues/6427?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/conf/sync.go | 11 +++++++++++ kernel/go.mod | 4 ++-- kernel/go.sum | 19 ++++--------------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/kernel/conf/sync.go b/kernel/conf/sync.go index fdfc71552..e587272e9 100644 --- a/kernel/conf/sync.go +++ b/kernel/conf/sync.go @@ -23,6 +23,8 @@ type Sync struct { Synced int64 `json:"synced"` // 最近同步时间 Stat string `json:"stat"` // 最近同步统计信息 GenerateConflictDoc bool `json:"generateConflictDoc"` // 云端同步冲突时是否生成冲突文档 + Provider int `json:"provider"` // 云端存储服务提供者,0:思源官方,1:S3 协议对象存储服务 + S3 *S3 `json:"s3"` // S3 协议对象存储服务配置 } func NewSync() *Sync { @@ -31,5 +33,14 @@ func NewSync() *Sync { Enabled: false, Mode: 1, GenerateConflictDoc: false, + Provider: 0, } } + +type S3 struct { + Endpoint string // 服务端点 + AccessKey string // Access Key + SecretKey string // Secret Key + Regin string // 存储区域 + Bucket string // 存储空间 +} diff --git a/kernel/go.mod b/kernel/go.mod index e804ae763..ef6ca5eb1 100644 --- a/kernel/go.mod +++ b/kernel/go.mod @@ -35,9 +35,8 @@ require ( github.com/olahol/melody v1.1.1 github.com/panjf2000/ants/v2 v2.6.0 github.com/patrickmn/go-cache v2.1.0+incompatible - github.com/qiniu/go-sdk/v7 v7.13.0 github.com/radovskyb/watcher v1.0.7 - github.com/siyuan-note/dejavu v0.0.0-20221031125623-fe9358b6cc16 + github.com/siyuan-note/dejavu v0.0.0-20221031145103-cabf164a3427 github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75 github.com/siyuan-note/eventbus v0.0.0-20220916025349-3ac6e75522da github.com/siyuan-note/filelock v0.0.0-20221007163134-7e64809023ef @@ -102,6 +101,7 @@ require ( github.com/onsi/ginkgo/v2 v2.4.0 // indirect github.com/pelletier/go-toml/v2 v2.0.5 // indirect github.com/pkg/errors v0.9.1 // indirect + github.com/qiniu/go-sdk/v7 v7.13.0 // indirect github.com/restic/chunker v0.4.0 // indirect github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 // indirect github.com/shopspring/decimal v1.3.1 // indirect diff --git a/kernel/go.sum b/kernel/go.sum index f0ea01fed..1f993dcce 100644 --- a/kernel/go.sum +++ b/kernel/go.sum @@ -105,6 +105,7 @@ github.com/gin-gonic/gin v1.8.1/go.mod h1:ji8BvRH1azfM+SYow9zQ6SZMvR8qOMZHmsCuWR github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA= +github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0= github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A= github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= @@ -214,8 +215,6 @@ github.com/juju/loggo v0.0.0-20190526231331-6e530bcce5d8/go.mod h1:vgyd7OREkbtVE github.com/juju/testing v0.0.0-20191001232224-ce9dec17d28b/go.mod h1:63prj8cnj0tU0S9OHjGJn+b1h0ZghCndfnbQolrYTwA= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= -github.com/klauspost/compress v1.15.11 h1:Lcadnb3RKGin4FYM/orgq0qde+nc15E5Cbqg4B9Sx9c= -github.com/klauspost/compress v1.15.11/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrDDJnH7hvFVbGM= github.com/klauspost/compress v1.15.12 h1:YClS/PImqYbn+UILDnqxQCZ3RehC9N318SU3kElDUEM= github.com/klauspost/compress v1.15.12/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrDDJnH7hvFVbGM= github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= @@ -285,17 +284,13 @@ github.com/onsi/ginkgo v1.16.2/go.mod h1:CObGmKUOKaSC0RjmoAK7tKyn4Azo5P2IWuoMnvw github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= -github.com/onsi/ginkgo/v2 v2.3.1 h1:8SbseP7qM32WcvE6VaN6vfXxv698izmsJ1UQX9ve7T8= -github.com/onsi/ginkgo/v2 v2.3.1/go.mod h1:Sv4yQXwG5VmF7tm3Q5Z+RWUpPo24LF1mpnz2crUb8Ys= github.com/onsi/ginkgo/v2 v2.4.0 h1:+Ig9nvqgS5OBSACXNk15PLdp0U9XPYROt9CFzVdFGIs= github.com/onsi/ginkgo/v2 v2.4.0/go.mod h1:iHkDK1fKGcBoEHT5W7YBq4RFWaQulw+caOMkAt4OrFo= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/onsi/gomega v1.13.0/go.mod h1:lRk9szgn8TxENtWd0Tp4c3wjlRfMTMH27I+3Je41yGY= -github.com/onsi/gomega v1.22.0 h1:AIg2/OntwkBiCg5Tt1ayyiF1ArFrWFoCSMtMi/wdApk= +github.com/onsi/gomega v1.22.1 h1:pY8O4lBfsHKZHM/6nrxkhVPUznOlIu3quZcKP/M20KI= github.com/openzipkin/zipkin-go v0.1.1/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTmOf0Erfk+hxe8= -github.com/panjf2000/ants/v2 v2.5.0 h1:1rWGWSnxCsQBga+nQbA4/iY6VMeNoOIAM0ZWh9u3q2Q= -github.com/panjf2000/ants/v2 v2.5.0/go.mod h1:cU93usDlihJZ5CfRGNDYsiBYvoilLvBF5Qp/BT2GNRE= github.com/panjf2000/ants/v2 v2.6.0 h1:xOSpw42m+BMiJ2I33we7h6fYzG4DAlpE1xyI7VS2gxU= github.com/panjf2000/ants/v2 v2.6.0/go.mod h1:cU93usDlihJZ5CfRGNDYsiBYvoilLvBF5Qp/BT2GNRE= github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc= @@ -358,10 +353,8 @@ github.com/shurcooL/reactions v0.0.0-20181006231557-f2e0b4ca5b82/go.mod h1:TCR1l github.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-20221023024107-17bf52da95a1 h1:sk6pyVp22MfFXK8C5YOKD5eqWtvcMnkiEh1nyZlw4aU= -github.com/siyuan-note/dejavu v0.0.0-20221023024107-17bf52da95a1/go.mod h1:f+6y7KcTLlk2N2dLl5HeV/YzkyCTEqWNoMiWT0gkMi8= -github.com/siyuan-note/dejavu v0.0.0-20221031125623-fe9358b6cc16 h1:05p9tr+rJrKurRQG3NF9i/IPgGdBMPu5tKi1Ux427lY= -github.com/siyuan-note/dejavu v0.0.0-20221031125623-fe9358b6cc16/go.mod h1:+U86jfsvpacZBThE3Ouf/ZQ4EsB4jGPJsMO2iuRv0LQ= +github.com/siyuan-note/dejavu v0.0.0-20221031145103-cabf164a3427 h1:xLo2tlKDM1sZgTOzMWGALujU9qM0OTNVqXBMKAKVt80= +github.com/siyuan-note/dejavu v0.0.0-20221031145103-cabf164a3427/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= @@ -370,8 +363,6 @@ github.com/siyuan-note/filelock v0.0.0-20221007163134-7e64809023ef h1:mbDOxW0N2O github.com/siyuan-note/filelock v0.0.0-20221007163134-7e64809023ef/go.mod h1:NmpSIVtIGy8eNWapjDIiiCw5+5r5wxC76k40oG+WRXQ= github.com/siyuan-note/httpclient v0.0.0-20221019094331-c904ac9be571 h1:AclwUOWgJQt1F8AXc2s6l/J+Edp/GYIgbI2/RoNlKU0= github.com/siyuan-note/httpclient v0.0.0-20221019094331-c904ac9be571/go.mod h1:FTPEFG3q0LAn33zON47HeRbLOWNk7HM+OPafmQgq4hU= -github.com/siyuan-note/logging v0.0.0-20220717040626-f796b05ee520 h1:kscYjMt7jXYdd7Qj2OSUoBnoHc5B0U/E6OSx86VRLr4= -github.com/siyuan-note/logging v0.0.0-20220717040626-f796b05ee520/go.mod h1:t1zRGxK13L/9ZFoGyTD39IbFCbee3CsypDj4b5dt4qM= github.com/siyuan-note/logging v0.0.0-20221031125421-9b7234d79d8a h1:b9VJCE8IccYjsadwNBI11he+Wn25hI9lCma4uYoIYEM= github.com/siyuan-note/logging v0.0.0-20221031125421-9b7234d79d8a/go.mod h1:t1zRGxK13L/9ZFoGyTD39IbFCbee3CsypDj4b5dt4qM= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= @@ -438,8 +429,6 @@ golang.org/x/crypto v0.1.0 h1:MDRAIl0xIo9Io2xV565hzXHw3zVseKrJKodhohM5CjU= golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56/go.mod h1:JhuoJpWY28nO4Vef9tZUw9qufEGTyX1+7lmHxV5q5G4= -golang.org/x/exp v0.0.0-20221019170559-20944726eadf h1:nFVjjKDgNY37+ZSYCJmtYf7tOlfQswHqplG2eosjOMg= -golang.org/x/exp v0.0.0-20221019170559-20944726eadf/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE= golang.org/x/exp v0.0.0-20221028150844-83b7d23a625f h1:Al51T6tzvuh3oiwX11vex3QgJ2XTedFPGmbEVh8cdoc= golang.org/x/exp v0.0.0-20221028150844-83b7d23a625f/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= From ea89f6a78ad84439efcde75f04766fbe0cb2d850 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Mon, 31 Oct 2022 23:52:57 +0800 Subject: [PATCH 3/7] =?UTF-8?q?:recycle:=20=E9=87=8D=E6=9E=84=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E4=BB=93=E5=BA=93=E5=90=8C=E6=AD=A5=20Fix=20https://g?= =?UTF-8?q?ithub.com/siyuan-note/siyuan/issues/6427?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/go.mod | 2 +- kernel/go.sum | 4 ++-- kernel/model/sync.go | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/kernel/go.mod b/kernel/go.mod index ef6ca5eb1..c605a9b0d 100644 --- a/kernel/go.mod +++ b/kernel/go.mod @@ -36,7 +36,7 @@ require ( github.com/panjf2000/ants/v2 v2.6.0 github.com/patrickmn/go-cache v2.1.0+incompatible github.com/radovskyb/watcher v1.0.7 - github.com/siyuan-note/dejavu v0.0.0-20221031145103-cabf164a3427 + github.com/siyuan-note/dejavu v0.0.0-20221031154617-cd9466fb0785 github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75 github.com/siyuan-note/eventbus v0.0.0-20220916025349-3ac6e75522da github.com/siyuan-note/filelock v0.0.0-20221007163134-7e64809023ef diff --git a/kernel/go.sum b/kernel/go.sum index 1f993dcce..21566afb1 100644 --- a/kernel/go.sum +++ b/kernel/go.sum @@ -353,8 +353,8 @@ github.com/shurcooL/reactions v0.0.0-20181006231557-f2e0b4ca5b82/go.mod h1:TCR1l github.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-20221031145103-cabf164a3427 h1:xLo2tlKDM1sZgTOzMWGALujU9qM0OTNVqXBMKAKVt80= -github.com/siyuan-note/dejavu v0.0.0-20221031145103-cabf164a3427/go.mod h1:+U86jfsvpacZBThE3Ouf/ZQ4EsB4jGPJsMO2iuRv0LQ= +github.com/siyuan-note/dejavu v0.0.0-20221031154617-cd9466fb0785 h1:ZvlTJvaYf7AsME4cR+qMZVxvRff23KRlkqtiHc/W4wI= +github.com/siyuan-note/dejavu v0.0.0-20221031154617-cd9466fb0785/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/sync.go b/kernel/model/sync.go index 85343a8e3..9321cc35d 100644 --- a/kernel/model/sync.go +++ b/kernel/model/sync.go @@ -29,7 +29,7 @@ import ( "github.com/88250/gulu" "github.com/dustin/go-humanize" - "github.com/siyuan-note/dejavu" + "github.com/siyuan-note/dejavu/transport" "github.com/siyuan-note/logging" "github.com/siyuan-note/siyuan/kernel/sql" "github.com/siyuan-note/siyuan/kernel/treenode" @@ -378,7 +378,7 @@ func ListCloudSyncDir() (syncDirs []*Sync, hSize string, err error) { } func formatErrorMsg(err error) string { - if errors.Is(err, dejavu.ErrCloudAuthFailed) { + if errors.Is(err, transport.ErrCloudAuthFailed) { return Conf.Language(31) + " v" + util.Ver } From dc1afe1a46150ecf02058f35ccb4db6d5127ba6f Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Tue, 1 Nov 2022 00:05:42 +0800 Subject: [PATCH 4/7] =?UTF-8?q?:recycle:=20=E9=87=8D=E6=9E=84=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E4=BB=93=E5=BA=93=E5=90=8C=E6=AD=A5=20Fix=20https://g?= =?UTF-8?q?ithub.com/siyuan-note/siyuan/issues/6427?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/go.mod | 2 +- kernel/go.sum | 2 ++ kernel/model/repository.go | 12 ++++++------ kernel/model/sync.go | 4 ++-- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/kernel/go.mod b/kernel/go.mod index c605a9b0d..a9bf77f91 100644 --- a/kernel/go.mod +++ b/kernel/go.mod @@ -36,7 +36,7 @@ require ( github.com/panjf2000/ants/v2 v2.6.0 github.com/patrickmn/go-cache v2.1.0+incompatible github.com/radovskyb/watcher v1.0.7 - github.com/siyuan-note/dejavu v0.0.0-20221031154617-cd9466fb0785 + github.com/siyuan-note/dejavu v0.0.0-20221031160243-9bedc511961f github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75 github.com/siyuan-note/eventbus v0.0.0-20220916025349-3ac6e75522da github.com/siyuan-note/filelock v0.0.0-20221007163134-7e64809023ef diff --git a/kernel/go.sum b/kernel/go.sum index 21566afb1..456a6d624 100644 --- a/kernel/go.sum +++ b/kernel/go.sum @@ -355,6 +355,8 @@ github.com/shurcooL/users v0.0.0-20180125191416-49c67e49c537/go.mod h1:QJTqeLYED github.com/shurcooL/webdavfs v0.0.0-20170829043945-18c3829fa133/go.mod h1:hKmq5kWdCj2z2KEozexVbfEZIWiTjhE0+UjmZgPqehw= github.com/siyuan-note/dejavu v0.0.0-20221031154617-cd9466fb0785 h1:ZvlTJvaYf7AsME4cR+qMZVxvRff23KRlkqtiHc/W4wI= github.com/siyuan-note/dejavu v0.0.0-20221031154617-cd9466fb0785/go.mod h1:+U86jfsvpacZBThE3Ouf/ZQ4EsB4jGPJsMO2iuRv0LQ= +github.com/siyuan-note/dejavu v0.0.0-20221031160243-9bedc511961f h1:pN62Dby/Pt4gejJqNJJxWW72LXBKP1ZF2f1vYh7L5Wg= +github.com/siyuan-note/dejavu v0.0.0-20221031160243-9bedc511961f/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/repository.go b/kernel/model/repository.go index 518a734f8..e04fce17e 100644 --- a/kernel/model/repository.go +++ b/kernel/model/repository.go @@ -34,8 +34,8 @@ import ( "github.com/88250/gulu" "github.com/dustin/go-humanize" "github.com/siyuan-note/dejavu" + "github.com/siyuan-note/dejavu/cloud" "github.com/siyuan-note/dejavu/entity" - "github.com/siyuan-note/dejavu/transport" "github.com/siyuan-note/encryption" "github.com/siyuan-note/eventbus" "github.com/siyuan-note/httpclient" @@ -809,17 +809,17 @@ func resetRepository(repo *dejavu.Repo) (index *entity.Index, err error) { } func newRepository() (ret *dejavu.Repo, err error) { - transportConf, err := buildRepoTransportConf() + cloudConf, err := buildCloudConf() if nil != err { return } // TODO: 数据同步支持接入第三方对象存储服务 https://github.com/siyuan-note/siyuan/issues/6426 - siyuanTransport := &transport.SiYuan{Conf: transportConf} + cloudSiYuan := &cloud.SiYuan{Conf: cloudConf} ignoreLines := getIgnoreLines() ignoreLines = append(ignoreLines, "/.siyuan/conf.json") // 忽略旧版同步配置 - ret, err = dejavu.NewRepo(util.DataDir, util.RepoDir, util.HistoryDir, util.TempDir, Conf.Repo.Key, ignoreLines, siyuanTransport) + ret, err = dejavu.NewRepo(util.DataDir, util.RepoDir, util.HistoryDir, util.TempDir, Conf.Repo.Key, ignoreLines, cloudSiYuan) if nil != err { logging.LogErrorf("init data repo failed: %s", err) } @@ -998,7 +998,7 @@ func subscribeEvents() { }) } -func buildRepoTransportConf() (ret *transport.Conf, err error) { +func buildCloudConf() (ret *cloud.Conf, err error) { if !IsValidCloudDirName(Conf.Sync.CloudName) { logging.LogWarnf("invalid cloud repo name, rename it to [main]") Conf.Sync.CloudName = "main" @@ -1011,7 +1011,7 @@ func buildRepoTransportConf() (ret *transport.Conf, err error) { token = Conf.User.UserToken } - ret = &transport.Conf{ + ret = &cloud.Conf{ Dir: Conf.Sync.CloudName, UserID: userId, Token: token, diff --git a/kernel/model/sync.go b/kernel/model/sync.go index 9321cc35d..a1b895d73 100644 --- a/kernel/model/sync.go +++ b/kernel/model/sync.go @@ -29,7 +29,7 @@ import ( "github.com/88250/gulu" "github.com/dustin/go-humanize" - "github.com/siyuan-note/dejavu/transport" + "github.com/siyuan-note/dejavu/cloud" "github.com/siyuan-note/logging" "github.com/siyuan-note/siyuan/kernel/sql" "github.com/siyuan-note/siyuan/kernel/treenode" @@ -378,7 +378,7 @@ func ListCloudSyncDir() (syncDirs []*Sync, hSize string, err error) { } func formatErrorMsg(err error) string { - if errors.Is(err, transport.ErrCloudAuthFailed) { + if errors.Is(err, cloud.ErrCloudAuthFailed) { return Conf.Language(31) + " v" + util.Ver } From f8a1d5c81d79708a28ddfe458005d95f79a45962 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Tue, 1 Nov 2022 09:05:34 +0800 Subject: [PATCH 5/7] =?UTF-8?q?:recycle:=20=E9=87=8D=E6=9E=84=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E4=BB=93=E5=BA=93=E5=90=8C=E6=AD=A5=20Fix=20https://g?= =?UTF-8?q?ithub.com/siyuan-note/siyuan/issues/6427?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/go.mod | 4 ++-- kernel/go.sum | 4 ++++ kernel/model/repository.go | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/kernel/go.mod b/kernel/go.mod index a9bf77f91..ba8f4b350 100644 --- a/kernel/go.mod +++ b/kernel/go.mod @@ -36,7 +36,7 @@ require ( github.com/panjf2000/ants/v2 v2.6.0 github.com/patrickmn/go-cache v2.1.0+incompatible github.com/radovskyb/watcher v1.0.7 - github.com/siyuan-note/dejavu v0.0.0-20221031160243-9bedc511961f + github.com/siyuan-note/dejavu v0.0.0-20221101010132-53c11123d85a github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75 github.com/siyuan-note/eventbus v0.0.0-20220916025349-3ac6e75522da github.com/siyuan-note/filelock v0.0.0-20221007163134-7e64809023ef @@ -111,7 +111,7 @@ require ( go.uber.org/atomic v1.10.0 // indirect go.uber.org/multierr v1.8.0 // indirect golang.org/x/crypto v0.1.0 // indirect - golang.org/x/exp v0.0.0-20221028150844-83b7d23a625f // indirect + golang.org/x/exp v0.0.0-20221031165847-c99f073a8326 // indirect golang.org/x/mod v0.6.0 // indirect golang.org/x/net v0.1.0 // indirect golang.org/x/sync v0.1.0 // indirect diff --git a/kernel/go.sum b/kernel/go.sum index 456a6d624..f50c1d35d 100644 --- a/kernel/go.sum +++ b/kernel/go.sum @@ -357,6 +357,8 @@ github.com/siyuan-note/dejavu v0.0.0-20221031154617-cd9466fb0785 h1:ZvlTJvaYf7As github.com/siyuan-note/dejavu v0.0.0-20221031154617-cd9466fb0785/go.mod h1:+U86jfsvpacZBThE3Ouf/ZQ4EsB4jGPJsMO2iuRv0LQ= github.com/siyuan-note/dejavu v0.0.0-20221031160243-9bedc511961f h1:pN62Dby/Pt4gejJqNJJxWW72LXBKP1ZF2f1vYh7L5Wg= github.com/siyuan-note/dejavu v0.0.0-20221031160243-9bedc511961f/go.mod h1:+U86jfsvpacZBThE3Ouf/ZQ4EsB4jGPJsMO2iuRv0LQ= +github.com/siyuan-note/dejavu v0.0.0-20221101010132-53c11123d85a h1:bE/9NcE4GUl9ooSfry7hp0jJ+9zb3EFQ1YILL3mzchQ= +github.com/siyuan-note/dejavu v0.0.0-20221101010132-53c11123d85a/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= @@ -433,6 +435,8 @@ golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56/go.mod h1:JhuoJpWY28nO4Vef9tZUw9qufEGTyX1+7lmHxV5q5G4= golang.org/x/exp v0.0.0-20221028150844-83b7d23a625f h1:Al51T6tzvuh3oiwX11vex3QgJ2XTedFPGmbEVh8cdoc= golang.org/x/exp v0.0.0-20221028150844-83b7d23a625f/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= +golang.org/x/exp v0.0.0-20221031165847-c99f073a8326 h1:QfTh0HpN6hlw6D3vu8DAwC8pBIwikq0AI1evdm+FksE= +golang.org/x/exp v0.0.0-20221031165847-c99f073a8326/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/image v0.0.0-20190823064033-3a9bac650e44/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= diff --git a/kernel/model/repository.go b/kernel/model/repository.go index e04fce17e..11ea90245 100644 --- a/kernel/model/repository.go +++ b/kernel/model/repository.go @@ -815,7 +815,7 @@ func newRepository() (ret *dejavu.Repo, err error) { } // TODO: 数据同步支持接入第三方对象存储服务 https://github.com/siyuan-note/siyuan/issues/6426 - cloudSiYuan := &cloud.SiYuan{Conf: cloudConf} + cloudSiYuan := &cloud.SiYuan{BaseCloud: &cloud.BaseCloud{Conf: cloudConf}} ignoreLines := getIgnoreLines() ignoreLines = append(ignoreLines, "/.siyuan/conf.json") // 忽略旧版同步配置 From 1fa2140bc309245a693c2c718f7863ec08a45be7 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Tue, 1 Nov 2022 09:25:29 +0800 Subject: [PATCH 6/7] =?UTF-8?q?:art:=20=E6=94=B9=E8=BF=9B=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E5=BF=AB=E7=85=A7=E5=A4=87=E6=B3=A8=E5=92=8C=E6=A0=87?= =?UTF-8?q?=E8=AE=B0=E5=BF=AB=E7=85=A7=E5=90=8D=E7=A7=B0=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/repository.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/model/repository.go b/kernel/model/repository.go index 11ea90245..f8479f233 100644 --- a/kernel/model/repository.go +++ b/kernel/model/repository.go @@ -378,6 +378,7 @@ func TagSnapshot(id, name string) (err error) { return } + name = strings.TrimSpace(name) name = gulu.Str.RemoveInvisible(name) if "" == name { err = errors.New(Conf.Language(142)) @@ -413,6 +414,7 @@ func IndexRepo(memo string) (err error) { return } + memo = strings.TrimSpace(memo) memo = gulu.Str.RemoveInvisible(memo) if "" == memo { err = errors.New(Conf.Language(142)) From b87a6cd57da799f0b30a44ac1d34ed7408638fc2 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Tue, 1 Nov 2022 10:06:32 +0800 Subject: [PATCH 7/7] =?UTF-8?q?:art:=20=E8=87=AA=E5=8A=A8=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E4=B8=8B=E8=BD=BD=E5=AE=89=E8=A3=85=E5=8C=85=E6=97=B6?= =?UTF-8?q?=E4=BC=98=E5=85=88=E4=BD=BF=E7=94=A8=20GitHub=20Releases=20Fix?= =?UTF-8?q?=20https://github.com/siyuan-note/siyuan/issues/6435?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/updater.go | 45 ++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/kernel/model/updater.go b/kernel/model/updater.go index 5cd8fe6bd..b0a5667c1 100644 --- a/kernel/model/updater.go +++ b/kernel/model/updater.go @@ -62,12 +62,12 @@ func getNewVerInstallPkgPath() string { return "" } - downloadPkgURL, checksum, err := getUpdatePkg() - if nil != err || "" == downloadPkgURL || "" == checksum { + downloadPkgURLs, checksum, err := getUpdatePkg() + if nil != err || 1 > len(downloadPkgURLs) || "" == checksum { return "" } - pkg := path.Base(downloadPkgURL) + pkg := path.Base(downloadPkgURLs[0]) ret := filepath.Join(util.TempDir, "install", pkg) localChecksum, _ := sha256Hash(ret) if checksum != localChecksum { @@ -92,21 +92,32 @@ func checkDownloadInstallPkg() { checkDownloadInstallPkgLock.Lock() defer checkDownloadInstallPkgLock.Unlock() - downloadPkgURL, checksum, err := getUpdatePkg() - if nil != err || "" == downloadPkgURL || "" == checksum { + downloadPkgURLs, checksum, err := getUpdatePkg() + if nil != err || 1 > len(downloadPkgURLs) || "" == checksum { return } - downloadInstallPkg(downloadPkgURL, checksum) + msgId := util.PushMsg(Conf.Language(103), 60*1000*10) + succ := false + for _, downloadPkgURL := range downloadPkgURLs { + err = downloadInstallPkg(downloadPkgURL, checksum) + if nil == err { + succ = true + break + + } + } + if !succ { + util.PushUpdateMsg(msgId, Conf.Language(104), 7000) + } } -func getUpdatePkg() (downloadPkgURL, checksum string, err error) { +func getUpdatePkg() (downloadPkgURLs []string, checksum string, err error) { result, err := util.GetRhyResult(false) if nil != err { return } - installPkgSite := result["installPkg"].(string) ver := result["ver"].(string) if isVersionUpToDate(ver) { return @@ -125,13 +136,20 @@ func getUpdatePkg() (downloadPkgURL, checksum string, err error) { suffix = "linux.AppImage" } pkg := "siyuan-" + ver + "-" + suffix - downloadPkgURL = installPkgSite + "siyuan/" + pkg + + url := "https://github.com/siyuan-note/siyuan/releases/download/v" + ver + "/" + pkg + downloadPkgURLs = append(downloadPkgURLs, url) + url = "https://ghproxy.com/" + url + downloadPkgURLs = append(downloadPkgURLs, url) + url = "https://release.b3log.org/siyuan/" + pkg + downloadPkgURLs = append(downloadPkgURLs, url) + checksums := result["checksums"].(map[string]interface{}) checksum = checksums[pkg].(string) return } -func downloadInstallPkg(pkgURL, checksum string) { +func downloadInstallPkg(pkgURL, checksum string) (err error) { if "" == pkgURL || "" == checksum { return } @@ -145,22 +163,20 @@ func downloadInstallPkg(pkgURL, checksum string) { } } - err := os.MkdirAll(filepath.Join(util.TempDir, "install"), 0755) + err = os.MkdirAll(filepath.Join(util.TempDir, "install"), 0755) if nil != err { logging.LogErrorf("create temp install dir failed: %s", err) return } logging.LogInfof("downloading install package [%s]", pkgURL) - msgId := util.PushMsg(Conf.Language(103), 60*1000*10) client := req.C().SetTLSHandshakeTimeout(7 * time.Second).SetTimeout(10 * time.Minute) callback := func(info req.DownloadInfo) { //logging.LogDebugf("downloading install package [%s %.2f%%]", pkgURL, float64(info.DownloadedSize)/float64(info.Response.ContentLength)*100.0) } _, err = client.R().SetOutputFile(savePath).SetDownloadCallback(callback).Get(pkgURL) if nil != err { - logging.LogErrorf("download install package failed: %s", err) - util.PushUpdateMsg(msgId, Conf.Language(104), 7000) + logging.LogErrorf("download install package [%s] failed: %s", pkgURL, err) return } @@ -170,6 +186,7 @@ func downloadInstallPkg(pkgURL, checksum string) { return } logging.LogInfof("downloaded install package [%s] to [%s]", pkgURL, savePath) + return } func sha256Hash(filename string) (ret string, err error) {