Просмотр исходного кода

:art: Add more file formats supporting snapshots comparing https://github.com/siyuan-note/siyuan/issues/8438

Daniel 2 лет назад
Родитель
Сommit
e50a9b4e11
3 измененных файлов с 13 добавлено и 13 удалено
  1. 2 2
      app/src/history/diff.ts
  2. 4 4
      kernel/api/repo.go
  3. 7 7
      kernel/model/repository.go

+ 2 - 2
app/src/history/diff.ts

@@ -75,7 +75,7 @@ const renderCompare = (app: App, element: HTMLElement) => {
             textElement.previousElementSibling.classList.remove("fn__none");
             textElement.classList.add("fn__none");
             leftElement.lastElementChild.classList.add("fn__none");
-        } else if (response.data.isLargeDoc) {
+        } else if (response.data.isProtyleDoc) {
             textElement.value = response.data.content;
             textElement.classList.remove("fn__none");
             leftElement.lastElementChild.classList.add("fn__none");
@@ -103,7 +103,7 @@ const renderCompare = (app: App, element: HTMLElement) => {
                 textElement.previousElementSibling.classList.remove("fn__none");
                 textElement.classList.add("fn__none");
                 rightElement.lastElementChild.classList.add("fn__none");
-            } else if (response.data.isLargeDoc) {
+            } else if (response.data.isProtyleDoc) {
                 textElement.value = response.data.content;
                 textElement.classList.remove("fn__none");
                 rightElement.lastElementChild.classList.add("fn__none");

+ 4 - 4
kernel/api/repo.go

@@ -36,7 +36,7 @@ func openRepoSnapshotDoc(c *gin.Context) {
 	}
 
 	id := arg["id"].(string)
-	content, isLargeDoc, updated, err := model.OpenRepoSnapshotDoc(id)
+	content, isProtyleDoc, updated, err := model.OpenRepoSnapshotDoc(id)
 	if nil != err {
 		ret.Code = -1
 		ret.Msg = err.Error()
@@ -44,9 +44,9 @@ func openRepoSnapshotDoc(c *gin.Context) {
 	}
 
 	ret.Data = map[string]interface{}{
-		"content":    content,
-		"isLargeDoc": isLargeDoc,
-		"updated":    updated,
+		"content":      content,
+		"isProtyleDoc": isProtyleDoc,
+		"updated":      updated,
 	}
 }
 

+ 7 - 7
kernel/model/repository.go

@@ -71,7 +71,7 @@ type TypeCount struct {
 	Count int    `json:"count"`
 }
 
-func OpenRepoSnapshotDoc(fileID string) (content string, isLargeDoc bool, updated int64, err error) {
+func OpenRepoSnapshotDoc(fileID string) (content string, isProtyleDoc bool, updated int64, err error) {
 	if 1 > len(Conf.Repo.Key) {
 		err = errors.New(Conf.Language(26))
 		return
@@ -97,13 +97,13 @@ func OpenRepoSnapshotDoc(fileID string) (content string, isLargeDoc bool, update
 	if strings.HasSuffix(file.Path, ".sy") {
 		luteEngine := NewLute()
 		var snapshotTree *parse.Tree
-		isLargeDoc, snapshotTree, err = parseTreeInSnapshot(data, luteEngine)
+		isProtyleDoc, snapshotTree, err = parseTreeInSnapshot(data, luteEngine)
 		if nil != err {
 			logging.LogErrorf("parse tree from snapshot file [%s] failed", fileID)
 			return
 		}
 
-		if !isLargeDoc {
+		if !isProtyleDoc {
 			renderTree := &parse.Tree{Root: &ast.Node{Type: ast.NodeDocument}}
 
 			var unlinks []*ast.Node
@@ -133,7 +133,7 @@ func OpenRepoSnapshotDoc(fileID string) (content string, isLargeDoc bool, update
 		}
 
 		luteEngine.RenderOptions.ProtyleContenteditable = false
-		if isLargeDoc {
+		if isProtyleDoc {
 			util.PushMsg(Conf.Language(36), 5000)
 			formatRenderer := render.NewFormatRenderer(snapshotTree, luteEngine.RenderOptions)
 			content = gulu.Str.FromBytes(formatRenderer.Render())
@@ -141,7 +141,7 @@ func OpenRepoSnapshotDoc(fileID string) (content string, isLargeDoc bool, update
 			content = luteEngine.Tree2BlockDOM(snapshotTree, luteEngine.RenderOptions)
 		}
 	} else {
-		isLargeDoc = true
+		isProtyleDoc = true
 		if strings.HasSuffix(file.Path, ".json") {
 			content = gulu.Str.FromBytes(data)
 		} else {
@@ -306,8 +306,8 @@ func parseTitleInSnapshot(fileID string, repo *dejavu.Repo, luteEngine *lute.Lut
 	return
 }
 
-func parseTreeInSnapshot(data []byte, luteEngine *lute.Lute) (isLargeDoc bool, tree *parse.Tree, err error) {
-	isLargeDoc = 1024*1024*1 <= len(data)
+func parseTreeInSnapshot(data []byte, luteEngine *lute.Lute) (isProtyleDoc bool, tree *parse.Tree, err error) {
+	isProtyleDoc = 1024*1024*1 <= len(data)
 	tree, err = filesys.ParseJSONWithoutFix(data, luteEngine.ParseOptions)
 	if nil != err {
 		return