浏览代码

:art: 云端同步冲突时支持设置是否产生冲突文档 https://github.com/siyuan-note/siyuan/issues/6110

Liang Ding 2 年之前
父节点
当前提交
698f773ee2

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

@@ -1,4 +1,6 @@
 {
+  "generateConflictDoc": "Generate conflict documentation when syncing conflicts",
+  "generateConflictDocTip": "After enabling, a conflict document will be generated when a synchronization conflict occurs, so that it can be opened and viewed directly. Whether enabled or not, the data history will record the conflict document",
   "deleteOpConfirm": "⚠️ Delete operation confirmation",
   "filterDocNameEnter": "Filter doc name Enter",
   "defBlock": "Def block",

+ 2 - 0
app/appearance/langs/es_ES.json

@@ -1,4 +1,6 @@
 {
+  "generateConflictDoc": "Generar documentación de conflicto al sincronizar conflictos",
+  "generateConflictDocTip": "Cuando está habilitado, se generará un documento de conflicto cuando ocurra un conflicto de sincronización, para que pueda abrirse y verse directamente. Ya sea que esté habilitado o no, el historial de datos registrará el documento de conflicto",
   "deleteOpConfirm": "⚠️ Confirmación de operación de eliminación",
   "filterDocNameEnter": "Filtrar doc name Enter",
   "defBlock": "Definir bloque",

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

@@ -1,4 +1,6 @@
 {
+  "generateConflictDoc": "Générer une documentation sur les conflits lors de la synchronisation des conflits",
+  "generateConflictDocTip": "Lorsqu'il est activé, un document de conflit sera généré lorsqu'un conflit de synchronisation se produit, afin qu'il puisse être ouvert et visualisé directement. Qu'il soit activé ou non, l'historique des données enregistrera le document de conflit",
   "deleteOpConfirm": "⚠️ Supprimer la confirmation de l'opération",
   "filterDocNameEnter": "Filtre doc name Enter",
   "defBlock": "Définir le bloc",

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

@@ -1,4 +1,6 @@
 {
+  "generateConflictDoc": "同步衝突時生成衝突文檔",
+  "generateConflictDocTip": "啟用後當同步發生衝突時會生成衝突文檔,以便直接打開查看。無論是否啟用,數據歷史都會記錄衝突文檔",
   "deleteOpConfirm": "⚠️ Delete operation confirmation",
   "filterDocNameEnter": "過濾文檔名 Enter",
   "defBlock": "定義塊",

+ 2 - 0
app/appearance/langs/zh_CN.json

@@ -1,4 +1,6 @@
 {
+  "generateConflictDoc": "同步冲突时生成冲突文档",
+  "generateConflictDocTip": "启用后当同步发生冲突时会生成冲突文档,以便直接打开查看。无论是否启用,数据历史都会记录冲突文档",
   "deleteOpConfirm": "⚠️ 删除操作确认",
   "filterDocNameEnter": "过滤文档名 Enter",
   "defBlock": "定义块",

+ 13 - 0
kernel/api/sync.go

@@ -108,6 +108,19 @@ func createCloudSyncDir(c *gin.Context) {
 	}
 }
 
+func setSyncGenerateConflictDoc(c *gin.Context) {
+	ret := gulu.Ret.NewResult()
+	defer c.JSON(http.StatusOK, ret)
+
+	arg, ok := util.JsonArg(c, ret)
+	if !ok {
+		return
+	}
+
+	enabled := arg["enabled"].(bool)
+	model.SetSyncGenerateConflictDoc(enabled)
+}
+
 func setSyncEnable(c *gin.Context) {
 	ret := gulu.Ret.NewResult()
 	defer c.JSON(http.StatusOK, ret)

+ 10 - 8
kernel/conf/sync.go

@@ -17,17 +17,19 @@
 package conf
 
 type Sync struct {
-	CloudName string `json:"cloudName"` // 云端同步目录名称
-	Enabled   bool   `json:"enabled"`   // 是否开启同步
-	Mode      int    `json:"mode"`      // 同步模式,0:未设置(为兼容已有配置,initConf 函数中会转换为 1),1:自动,2:手动 https://github.com/siyuan-note/siyuan/issues/5089
-	Synced    int64  `json:"synced"`    // 最近同步时间
-	Stat      string `json:"stat"`      // 最近同步统计信息
+	CloudName           string `json:"cloudName"`           // 云端同步目录名称
+	Enabled             bool   `json:"enabled"`             // 是否开启同步
+	Mode                int    `json:"mode"`                // 同步模式,0:未设置(为兼容已有配置,initConf 函数中会转换为 1),1:自动,2:手动 https://github.com/siyuan-note/siyuan/issues/5089
+	Synced              int64  `json:"synced"`              // 最近同步时间
+	Stat                string `json:"stat"`                // 最近同步统计信息
+	GenerateConflictDoc bool   `json:"generateConflictDoc"` // 云端同步冲突时是否生成冲突文档
 }
 
 func NewSync() *Sync {
 	return &Sync{
-		CloudName: "main",
-		Enabled:   false,
-		Mode:      1,
+		CloudName:           "main",
+		Enabled:             false,
+		Mode:                1,
+		GenerateConflictDoc: false,
 	}
 }

+ 1 - 1
kernel/model/repository.go

@@ -541,7 +541,7 @@ func syncRepo(boot, exit, byHand bool) (err error) {
 
 	logSyncMergeResult(mergeResult)
 
-	if 0 < len(mergeResult.Conflicts) {
+	if 0 < len(mergeResult.Conflicts) && Conf.Sync.GenerateConflictDoc {
 		// 云端同步发生冲突时生成副本 https://github.com/siyuan-note/siyuan/issues/5687
 
 		luteEngine := NewLute()

+ 9 - 0
kernel/model/sync.go

@@ -216,6 +216,15 @@ func SetCloudSyncDir(name string) {
 	Conf.Save()
 }
 
+func SetSyncGenerateConflictDoc(b bool) {
+	syncLock.Lock()
+	defer syncLock.Unlock()
+
+	Conf.Sync.GenerateConflictDoc = b
+	Conf.Save()
+	return
+}
+
 func SetSyncEnable(b bool) (err error) {
 	syncLock.Lock()
 	defer syncLock.Unlock()