From 94ffa49435319772f8eaf9cb77d71e689c02eefb Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Mon, 15 Jan 2024 00:19:39 +0800 Subject: [PATCH] :art: Support manual purge of unreferenced data snapshots in the S3/WebDAV cloud storage https://github.com/siyuan-note/siyuan/issues/10081 --- app/appearance/langs/en_US.json | 3 ++- app/appearance/langs/es_ES.json | 3 ++- app/appearance/langs/fr_FR.json | 3 ++- app/appearance/langs/zh_CHT.json | 3 ++- app/appearance/langs/zh_CN.json | 3 ++- kernel/go.mod | 4 ++-- kernel/go.sum | 20 ++++---------------- kernel/model/repository.go | 24 ++++++++++++++++++++++++ kernel/util/websocket.go | 2 ++ 9 files changed, 42 insertions(+), 23 deletions(-) diff --git a/app/appearance/langs/en_US.json b/app/appearance/langs/en_US.json index 80d696754..0757c5f67 100644 --- a/app/appearance/langs/en_US.json +++ b/app/appearance/langs/en_US.json @@ -1389,6 +1389,7 @@ "219": "The cloud storage service is unavailable, please try again later", "220": "Due to a defect in the previous version, the cloud data is corrupted. Please refer to the User Guide-FAQ-Lost Key steps to reset the local data repo and cloud directory", "221": "The replacement operation is not supported after grouping by document. Please use ungrouping and then replace", - "222": "Data sync is in progress, please wait until data sync is completed and try again" + "222": "Data sync is in progress, please wait until data sync is completed and try again", + "223": "Cleaning cloud storage..." } } diff --git a/app/appearance/langs/es_ES.json b/app/appearance/langs/es_ES.json index 4e628760a..b40659304 100644 --- a/app/appearance/langs/es_ES.json +++ b/app/appearance/langs/es_ES.json @@ -1389,6 +1389,7 @@ "219": "El servicio de almacenamiento en la nube no está disponible, inténtalo de nuevo más tarde", "220": "Debido a un defecto en la versión anterior, los datos de la nube están dañados. Consulte los pasos de la User Guide-FAQ-Lost Key para restablecer el repositorio de datos local y el directorio de la nube", "221": "La operación de reemplazo no es compatible después de agrupar por documento. Utilice desagrupar y luego reemplazar", - "222": "La sincronización de datos está en curso. Espere hasta que se complete la sincronización de datos e inténtelo de nuevo" + "222": "La sincronización de datos está en curso. Espere hasta que se complete la sincronización de datos e inténtelo de nuevo", + "223": "Limpiando el almacenamiento en la nube..." } } diff --git a/app/appearance/langs/fr_FR.json b/app/appearance/langs/fr_FR.json index 7df0e3dd8..997388abb 100644 --- a/app/appearance/langs/fr_FR.json +++ b/app/appearance/langs/fr_FR.json @@ -1389,6 +1389,7 @@ "219": "Le service de stockage cloud n'est pas disponible, veuillez réessayer plus tard", "220": "En raison d'un défaut dans la version précédente, les données cloud sont corrompues. Veuillez vous référer aux étapes User Guide-FAQ-Lost Key pour réinitialiser le référentiel de données local et le répertoire cloud", "221": "L'opération de remplacement n'est pas prise en charge après le regroupement par document. Veuillez utiliser le dissociation puis remplacer", - "222": "La synchronisation des données est en cours, veuillez attendre que la synchronisation des données soit terminée et réessayer" + "222": "La synchronisation des données est en cours, veuillez attendre que la synchronisation des données soit terminée et réessayer", + "223": "Nettoyage du stockage cloud..." } } diff --git a/app/appearance/langs/zh_CHT.json b/app/appearance/langs/zh_CHT.json index a40d371ff..994c0db80 100644 --- a/app/appearance/langs/zh_CHT.json +++ b/app/appearance/langs/zh_CHT.json @@ -1389,6 +1389,7 @@ "219": "雲端儲存服務不可用,請稍後再試", "220": "由於先前版本的缺陷導致了雲端資料損壞,請參考 用戶指南-常見問題-遺失密鑰 步驟來重置本地資料倉儲和雲端目錄", "221": "按文檔分組後不支援替換操作,請使用取消分組後再進行替換", - "222": "資料同步中,請等待資料同步完成後再試" + "222": "資料同步中,請等待資料同步完成後再試", + "223": "正在清理雲端儲存..." } } diff --git a/app/appearance/langs/zh_CN.json b/app/appearance/langs/zh_CN.json index c5aadf55e..c20a65bf2 100644 --- a/app/appearance/langs/zh_CN.json +++ b/app/appearance/langs/zh_CN.json @@ -1389,6 +1389,7 @@ "219": "云端存储服务不可用,请稍后再试", "220": "由于之前版本的缺陷导致了云端数据损坏,请参考 用户指南-常见问题-遗失密钥 步骤来重置本地数据仓库和云端目录", "221": "按文档分组后不支持替换操作,请使用取消分组后再进行替换", - "222": "数据同步中,请等待数据同步完成后再试" + "222": "数据同步中,请等待数据同步完成后再试", + "223": "正在清理云端存储..." } } diff --git a/kernel/go.mod b/kernel/go.mod index 9aee2ac9b..6c51e8ba9 100644 --- a/kernel/go.mod +++ b/kernel/go.mod @@ -51,9 +51,9 @@ require ( github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 github.com/sashabaranov/go-openai v1.17.11 github.com/shirou/gopsutil/v3 v3.23.12 - github.com/siyuan-note/dejavu v0.0.0-20240114035445-cb46035821cb + github.com/siyuan-note/dejavu v0.0.0-20240114161747-36bb80f2521a github.com/siyuan-note/encryption v0.0.0-20231219001248-1e028a4d13b4 - github.com/siyuan-note/eventbus v0.0.0-20231210025112-82fdedd8e374 + github.com/siyuan-note/eventbus v0.0.0-20240114153055-cf4c124ddf6d github.com/siyuan-note/filelock v0.0.0-20231211015131-3b3dfabdce9c github.com/siyuan-note/httpclient v0.0.0-20240105083729-70d0557bc690 github.com/siyuan-note/logging v0.0.0-20231208035918-61f884c854f0 diff --git a/kernel/go.sum b/kernel/go.sum index e2803a7c5..ba208d4bb 100644 --- a/kernel/go.sum +++ b/kernel/go.sum @@ -38,8 +38,6 @@ github.com/advancedlogic/GoOse v0.0.0-20231203033844-ae6b36caf275 h1:Kuhf+w+ilOG github.com/advancedlogic/GoOse v0.0.0-20231203033844-ae6b36caf275/go.mod h1:98NztIIMIntZGtQVIs8H85Q5b88fTbwWFbLz/lM9/xU= github.com/alecthomas/chroma v0.10.0 h1:7XDcGkCQopCNKjZHfYrNLraA+M7e0fMiJ/Mfikbfjek= github.com/alecthomas/chroma v0.10.0/go.mod h1:jtJATyUxlIORhUOFNA9NZDWGAQ8wpxQQqNSB4rjA/1s= -github.com/andybalholm/brotli v1.0.6 h1:Yf9fFpf49Zrxb9NlQaluyE92/+X7UVHlhMNJN2sxfOI= -github.com/andybalholm/brotli v1.0.6/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M= github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY= github.com/andybalholm/cascadia v1.0.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y= @@ -51,8 +49,6 @@ github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de h1:FxWPpzIjnTlhP github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de/go.mod h1:DCaWoUhZrYW9p1lxo/cm8EmUOOzAPSEZNGF2DK1dJgw= github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef h1:2JGTg6JapxP9/R33ZaagQtAM4EkkSYnIAlOG5EI8gkM= github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef/go.mod h1:JS7hed4L1fj0hXcyEejnW57/7LCetXggd+vwrRnYeII= -github.com/aws/aws-sdk-go v1.49.18 h1:g/iMXkfXeJQ7MvnLwroxWsTTNkHtdVJGxIgrAIEG62M= -github.com/aws/aws-sdk-go v1.49.18/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk= github.com/aws/aws-sdk-go v1.49.20 h1:VgEUq2/ZbUkLbqPyDcxrirfXB+PgiZUUF5XbsgWe2S0= github.com/aws/aws-sdk-go v1.49.20/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk= github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= @@ -282,8 +278,6 @@ github.com/olahol/melody v1.1.4/go.mod h1:GgkTl6Y7yWj/HtfD48Q5vLKPVoZOH+Qqgfa7Cv github.com/olekukonko/tablewriter v0.0.0-20180506121414-d4647c9c7a84/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= -github.com/onsi/ginkgo/v2 v2.13.2 h1:Bi2gGVkfn6gQcjNjZJVO8Gf0FHzMPf2phUei9tejVMs= -github.com/onsi/ginkgo/v2 v2.13.2/go.mod h1:XStQ8QcGwLyF4HdfcZB8SFOS/MWCgDuXMSBe6zrvLgM= github.com/onsi/ginkgo/v2 v2.14.0 h1:vSmGj2Z5YPb9JwCWT6z6ihcUvDhuXLc3sJiqd3jMKAY= github.com/onsi/ginkgo/v2 v2.14.0/go.mod h1:JkUdW7JkN0V6rFvsHcJ478egV3XH9NxpD27Hal/PhZw= github.com/onsi/gomega v1.30.0 h1:hvMK7xYz4D3HapigLTeGdId/NcfQx1VHMJc60ew99+8= @@ -360,14 +354,12 @@ github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFR github.com/shurcooL/gofontwoff v0.0.0-20181114050219-180f79e6909d h1:lvCTyBbr36+tqMccdGMwuEU+hjux/zL6xSmf5S9ITaA= github.com/shurcooL/gofontwoff v0.0.0-20181114050219-180f79e6909d/go.mod h1:05UtEgK5zq39gLST6uB0cf3NEHjETfB4Fgr3Gx5R9Vw= github.com/simplereach/timeutils v1.2.0/go.mod h1:VVbQDfN/FHRZa1LSqcwo4kNZ62OOyqLLGQKYB3pB0Q8= -github.com/siyuan-note/dejavu v0.0.0-20240111141110-01248e7cc4f0 h1:JzdZxhJ7M6Pd35Z/HkWW8DP7TqMrBurRXsK2fjN1Obg= -github.com/siyuan-note/dejavu v0.0.0-20240111141110-01248e7cc4f0/go.mod h1:oXMdsH817hquMrFUar0pT+lZxneawAI4u/3cghzvGrw= -github.com/siyuan-note/dejavu v0.0.0-20240114035445-cb46035821cb h1:TRnnJSV0DPWTsYskUhIAF0wC5zwb0dNlqS6CUxhgWvI= -github.com/siyuan-note/dejavu v0.0.0-20240114035445-cb46035821cb/go.mod h1:eCbmgVcApV+S7zmiOeiqCqOLb5HIJaFi4Af8hhEjfYA= +github.com/siyuan-note/dejavu v0.0.0-20240114161747-36bb80f2521a h1:09URTA1Oj04bmMH3qOYUR7qKcHF2IAZsO7n1SmDxj3Y= +github.com/siyuan-note/dejavu v0.0.0-20240114161747-36bb80f2521a/go.mod h1:yuc6UPkBkb0KvaZzkXGnKYzxQDOLAXfNwgs5HwnjuNU= github.com/siyuan-note/encryption v0.0.0-20231219001248-1e028a4d13b4 h1:kJaw5L/evyW6LcB9IQT8PR4ppx8JVqOFP9Ix3rfwSrc= github.com/siyuan-note/encryption v0.0.0-20231219001248-1e028a4d13b4/go.mod h1:UYcCCY+0wh+GmUoDOaO63j1sV5lgy7laLAk1XhEiUis= -github.com/siyuan-note/eventbus v0.0.0-20231210025112-82fdedd8e374 h1:haPIOZBOAEQaXsUPUpyZeOeMgw6g/9O7RBbS3d39Ta8= -github.com/siyuan-note/eventbus v0.0.0-20231210025112-82fdedd8e374/go.mod h1:Sqo4FYX5lAXu7gWkbEdJF0e6P57tNNVV4WDKYDctokI= +github.com/siyuan-note/eventbus v0.0.0-20240114153055-cf4c124ddf6d h1:ZFhIq+gy5w+FJNX3D4yIp5Aj1H/dM0rrkEdRtk3Ia44= +github.com/siyuan-note/eventbus v0.0.0-20240114153055-cf4c124ddf6d/go.mod h1:1/nGgthl89FPA7GzAcEWKl6zRRnfgyTjzLZj9bW7kuw= github.com/siyuan-note/filelock v0.0.0-20231211015131-3b3dfabdce9c h1:ljGWxKi4zT+cl7NkuNahTGOko9nw+Ed0xqsKgZiExyg= github.com/siyuan-note/filelock v0.0.0-20231211015131-3b3dfabdce9c/go.mod h1:++qrlYXSLss5AtNrHm3MNtDAQSI2gT8m3m15zLPjWJg= github.com/siyuan-note/httpclient v0.0.0-20240105083729-70d0557bc690 h1:r7qWSaYQhomCAdQl/dZe4NdAn1zadytb4jcOeopdHw4= @@ -454,8 +446,6 @@ golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc= golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= -golang.org/x/exp v0.0.0-20240110193028-0dcbfd608b1e h1:723BNChdd0c2Wk6WOE320qGBiPtYx0F0Bbm1kriShfE= -golang.org/x/exp v0.0.0-20240110193028-0dcbfd608b1e/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI= golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3 h1:hNQpMuAJe5CtcUqCXaWga3FHu+kQvCqcsoVaQgSV60o= golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3/go.mod h1:idGWGoKP1toJGkd5/ig9ZLuPcZBC3ewk7SzmH0uou08= golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM= @@ -546,8 +536,6 @@ golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3 golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= -golang.org/x/tools v0.16.1 h1:TLyB3WofjdOEepBHAU20JdNC1Zbg87elYofWYAY5oZA= -golang.org/x/tools v0.16.1/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0= golang.org/x/tools v0.17.0 h1:FvmRgNOcs3kOa+T20R1uhfP9F6HgG2mfxDv1vrx1Htc= golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/kernel/model/repository.go b/kernel/model/repository.go index ad0959d62..8f987d442 100644 --- a/kernel/model/repository.go +++ b/kernel/model/repository.go @@ -483,6 +483,30 @@ func ResetRepo() (err error) { return } +func PurgeCloud() (err error) { + // TODO https://github.com/siyuan-note/siyuan/issues/10081 + msg := Conf.Language(223) + util.PushEndlessProgress(msg) + defer util.PushClearProgress() + + repo, err := newRepository() + if nil != err { + return + } + + stat, err := repo.PurgeCloud() + if nil != err { + return + } + + deletedIndexes := stat.Indexes + deletedObjects := stat.Objects + deletedSize := humanize.Bytes(uint64(stat.Size)) + msg = fmt.Sprintf(Conf.Language(203), deletedIndexes, deletedObjects, deletedSize) + util.PushMsg(msg, 5000) + return +} + func PurgeRepo() (err error) { msg := Conf.Language(202) util.PushEndlessProgress(msg) diff --git a/kernel/util/websocket.go b/kernel/util/websocket.go index 541f4f749..370c819a6 100644 --- a/kernel/util/websocket.go +++ b/kernel/util/websocket.go @@ -168,6 +168,8 @@ type BlockStatResult struct { func ContextPushMsg(context map[string]interface{}, msg string) { switch context[eventbus.CtxPushMsg].(int) { + case eventbus.CtxPushMsgToNone: + break case eventbus.CtxPushMsgToProgress: PushEndlessProgress(msg) case eventbus.CtxPushMsgToStatusBar: