ソースを参照

:art: 数据快照 https://github.com/siyuan-note/siyuan/issues/5159

Liang Ding 3 年 前
コミット
c70f7ee28c

+ 2 - 1
app/appearance/langs/en_US.json

@@ -883,6 +883,7 @@
     "138": "Data repository key is set",
     "139": "Data snapshot is being generated, [%s] data files have been processed, [%s] remaining...",
     "140": "Failed to create data snapshot",
-    "141": "Failed to rollback data snapshot"
+    "141": "Failed to rollback data snapshot",
+    "142": "Snapshot memo cannot be empty"
   }
 }

+ 2 - 1
app/appearance/langs/fr_FR.json

@@ -883,6 +883,7 @@
     "138": "La clé du référentiel de données est définie",
     "139": "L'instantané des données est en cours de génération, [%s] fichiers de données ont été traités, [%s] restants...",
     "140": "Échec de la création de l'instantané des données",
-    "141": "Échec de la restauration de l'instantané des données"
+    "141": "Échec de la restauration de l'instantané des données",
+    "142": "Le mémo d'instantané ne peut pas être vide"
   }
 }

+ 2 - 1
app/appearance/langs/zh_CHT.json

@@ -882,6 +882,7 @@
     "138": "數據倉庫密鑰設置完畢",
     "139": "正在生成數據快照,已處理 [%s] 個數據文件,剩餘待處理 [%s]...",
     "140": "創建數據快照失敗",
-    "141": "回滾數據快照失敗"
+    "141": "回滾數據快照失敗",
+    "142": "快照備註不能為空"
   }
 }

+ 3 - 1
app/appearance/langs/zh_CN.json

@@ -1,4 +1,5 @@
 {
+  "memo"
   "createSnapshot": "创建快照",
   "dataSnapshot": "数据快照",
   "copyKey": "复制密钥字符串",
@@ -884,6 +885,7 @@
     "138": "数据仓库密钥设置完毕",
     "139": "正在生成数据快照,已处理 [%s] 个数据文件,剩余待处理 [%s]...",
     "140": "创建数据快照失败",
-    "141": "回滚数据快照失败"
+    "141": "回滚数据快照失败",
+    "142": "快照备注不能为空"
   }
 }

+ 9 - 2
kernel/model/repository.go

@@ -22,6 +22,7 @@ import (
 	"errors"
 	"os"
 
+	"github.com/88250/gulu"
 	"github.com/siyuan-note/dejavu"
 	"github.com/siyuan-note/dejavu/entity"
 	"github.com/siyuan-note/encryption"
@@ -148,12 +149,18 @@ var indexCallbacks = map[string]dejavu.Callback{
 	},
 }
 
-func IndexRepo(message string) (err error) {
+func IndexRepo(memo string) (err error) {
 	if 1 > len(Conf.Repo.Key) {
 		err = errors.New("repo key is nil")
 		return
 	}
 
+	memo = gulu.Str.RemoveInvisible(memo)
+	if "" == memo {
+		err = errors.New(Conf.Language(142))
+		return
+	}
+
 	repo, err := dejavu.NewRepo(util.DataDir, util.RepoDir, Conf.Repo.Key)
 	if nil != err {
 		util.LogErrorf("init repo failed: %s", err)
@@ -164,7 +171,7 @@ func IndexRepo(message string) (err error) {
 	syncLock.Lock()
 	defer syncLock.Unlock()
 	filesys.ReleaseAllFileLocks()
-	_, err = repo.Index(message, util.PushEndlessProgress, indexCallbacks)
+	_, err = repo.Index(memo, util.PushEndlessProgress, indexCallbacks)
 	util.PushClearProgress()
 	return
 }