A privacy-first, self-hosted, fully open source personal knowledge management software, written in typescript and golang. (PERSONAL FORK)

:art: All plain text formats are supported when comparing data snapshots https://github.com/siyuan-note/siyuan/issues/12975

Daniel 6db7b847 641550e1

+19 -37
+2 -2
app/src/history/diff.ts
··· 86 86 textElement.previousElementSibling.classList.remove("fn__none"); 87 87 textElement.classList.add("fn__none"); 88 88 leftElement.lastElementChild.classList.add("fn__none"); 89 - } else if (response.data.isProtyleDoc) { 89 + } else if (response.data.displayInText) { 90 90 textElement.value = response.data.content; 91 91 textElement.classList.remove("fn__none"); 92 92 leftElement.lastElementChild.classList.add("fn__none"); ··· 117 117 textElement.previousElementSibling.classList.remove("fn__none"); 118 118 textElement.classList.add("fn__none"); 119 119 rightElement.lastElementChild.classList.add("fn__none"); 120 - } else if (response.data.isProtyleDoc) { 120 + } else if (response.data.displayInText) { 121 121 textElement.value = response.data.content; 122 122 textElement.classList.remove("fn__none"); 123 123 rightElement.lastElementChild.classList.add("fn__none");
+5 -5
kernel/api/repo.go
··· 70 70 } 71 71 72 72 id := arg["id"].(string) 73 - title, content, isProtyleDoc, updated, err := model.OpenRepoSnapshotDoc(id) 73 + title, content, displayInText, updated, err := model.OpenRepoSnapshotDoc(id) 74 74 if err != nil { 75 75 ret.Code = -1 76 76 ret.Msg = err.Error() ··· 78 78 } 79 79 80 80 ret.Data = map[string]interface{}{ 81 - "title": title, 82 - "content": content, 83 - "isProtyleDoc": isProtyleDoc, 84 - "updated": updated, 81 + "title": title, 82 + "content": content, 83 + "displayInText": displayInText, 84 + "updated": updated, 85 85 } 86 86 } 87 87
-4
kernel/mobile/kernel.go
··· 98 98 return 99 99 } 100 100 101 - func GetMimeTypeByExt(ext string) string { 102 - return util.GetMimeTypeByExt(ext) 103 - } 104 - 105 101 func SetTimezone(container, appDir, timezoneID string) { 106 102 if "ios" == container { 107 103 os.Setenv("ZONEINFO", filepath.Join(appDir, "app", "zoneinfo.zip"))
+12 -9
kernel/model/repository.go
··· 24 24 "errors" 25 25 "fmt" 26 26 "math" 27 + "mime" 27 28 "net/http" 28 29 "os" 29 30 "path" ··· 79 80 return 80 81 } 81 82 82 - func OpenRepoSnapshotDoc(fileID string) (title, content string, isProtyleDoc bool, updated int64, err error) { 83 + func OpenRepoSnapshotDoc(fileID string) (title, content string, displayInText bool, updated int64, err error) { 83 84 if 1 > len(Conf.Repo.Key) { 84 85 err = errors.New(Conf.Language(26)) 85 86 return ··· 105 106 if strings.HasSuffix(file.Path, ".sy") { 106 107 luteEngine := NewLute() 107 108 var snapshotTree *parse.Tree 108 - isProtyleDoc, snapshotTree, err = parseTreeInSnapshot(data, luteEngine) 109 + displayInText, snapshotTree, err = parseTreeInSnapshot(data, luteEngine) 109 110 if err != nil { 110 111 logging.LogErrorf("parse tree from snapshot file [%s] failed", fileID) 111 112 return 112 113 } 113 114 title = snapshotTree.Root.IALAttr("title") 114 115 115 - if !isProtyleDoc { 116 + if !displayInText { 116 117 renderTree := &parse.Tree{Root: &ast.Node{Type: ast.NodeDocument}} 117 - 118 118 var unlinks []*ast.Node 119 119 ast.Walk(snapshotTree.Root, func(n *ast.Node, entering bool) ast.WalkStatus { 120 120 if !entering { ··· 142 142 } 143 143 144 144 luteEngine.RenderOptions.ProtyleContenteditable = false 145 - if isProtyleDoc { 145 + if displayInText { 146 146 util.PushMsg(Conf.Language(36), 5000) 147 147 formatRenderer := render.NewFormatRenderer(snapshotTree, luteEngine.RenderOptions) 148 148 content = gulu.Str.FromBytes(formatRenderer.Render()) ··· 150 150 content = luteEngine.Tree2BlockDOM(snapshotTree, luteEngine.RenderOptions) 151 151 } 152 152 } else { 153 - isProtyleDoc = true 153 + displayInText = true 154 154 title = path.Base(file.Path) 155 - if strings.HasSuffix(file.Path, ".json") { 155 + 156 + if mimeType := mime.TypeByExtension(filepath.Ext(file.Path)); strings.HasPrefix(mimeType, "text/") { 157 + // 如果是文本文件,直接返回文本内容 158 + // All plain text formats are supported when comparing data snapshots https://github.com/siyuan-note/siyuan/issues/12975 156 159 content = gulu.Str.FromBytes(data) 157 160 } else { 158 161 if strings.Contains(file.Path, "assets/") { // 剔除笔记本级或者文档级资源文件路径前缀 ··· 328 331 return 329 332 } 330 333 331 - func parseTreeInSnapshot(data []byte, luteEngine *lute.Lute) (isProtyleDoc bool, tree *parse.Tree, err error) { 332 - isProtyleDoc = 1024*1024*1 <= len(data) 334 + func parseTreeInSnapshot(data []byte, luteEngine *lute.Lute) (isLargeDoc bool, tree *parse.Tree, err error) { 335 + isLargeDoc = 1024*1024*1 <= len(data) 333 336 tree, err = filesys.ParseJSONWithoutFix(data, luteEngine.ParseOptions) 334 337 if err != nil { 335 338 return
-17
kernel/util/file.go
··· 20 20 "bytes" 21 21 "io" 22 22 "io/fs" 23 - "mime" 24 23 "os" 25 24 "path" 26 25 "path/filepath" ··· 30 29 31 30 "github.com/88250/gulu" 32 31 "github.com/88250/lute/ast" 33 - "github.com/gabriel-vasile/mimetype" 34 32 "github.com/siyuan-note/filelock" 35 33 "github.com/siyuan-note/logging" 36 34 ) ··· 73 71 } 74 72 i++ 75 73 } 76 - } 77 - 78 - func GetMimeTypeByExt(filePath string) (ret string) { 79 - ret = mime.TypeByExtension(filepath.Ext(filePath)) 80 - if "" == ret { 81 - m, err := mimetype.DetectFile(filePath) 82 - if err != nil { 83 - logging.LogErrorf("detect mime type of [%s] failed: %s", filePath, err) 84 - return 85 - } 86 - if nil != m { 87 - ret = m.String() 88 - } 89 - } 90 - return 91 74 } 92 75 93 76 func IsSymlinkPath(absPath string) bool {