mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-19 16:10:12 +01:00
🎨 All plain text formats are supported when comparing data snapshots https://github.com/siyuan-note/siyuan/issues/12975
This commit is contained in:
parent
fc50b864ad
commit
a2cb7d4c9b
3 changed files with 22 additions and 1 deletions
|
|
@ -98,6 +98,10 @@ func GetAssetAbsPath(asset string) (ret string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetMimeTypeByExt(ext string) string {
|
||||||
|
return util.GetMimeTypeByExt(ext)
|
||||||
|
}
|
||||||
|
|
||||||
func SetTimezone(container, appDir, timezoneID string) {
|
func SetTimezone(container, appDir, timezoneID string) {
|
||||||
if "ios" == container {
|
if "ios" == container {
|
||||||
os.Setenv("ZONEINFO", filepath.Join(appDir, "app", "zoneinfo.zip"))
|
os.Setenv("ZONEINFO", filepath.Join(appDir, "app", "zoneinfo.zip"))
|
||||||
|
|
|
||||||
|
|
@ -153,7 +153,7 @@ func OpenRepoSnapshotDoc(fileID string) (title, content string, displayInText bo
|
||||||
displayInText = true
|
displayInText = true
|
||||||
title = path.Base(file.Path)
|
title = path.Base(file.Path)
|
||||||
|
|
||||||
if mimeType := mime.TypeByExtension(filepath.Ext(file.Path)); strings.HasPrefix(mimeType, "text/") {
|
if mimeType := mime.TypeByExtension(filepath.Ext(file.Path)); strings.HasPrefix(mimeType, "text/") || strings.Contains(mimeType, "json") {
|
||||||
// 如果是文本文件,直接返回文本内容
|
// 如果是文本文件,直接返回文本内容
|
||||||
// All plain text formats are supported when comparing data snapshots https://github.com/siyuan-note/siyuan/issues/12975
|
// All plain text formats are supported when comparing data snapshots https://github.com/siyuan-note/siyuan/issues/12975
|
||||||
content = gulu.Str.FromBytes(data)
|
content = gulu.Str.FromBytes(data)
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
|
"mime"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
@ -29,6 +30,7 @@ import (
|
||||||
|
|
||||||
"github.com/88250/gulu"
|
"github.com/88250/gulu"
|
||||||
"github.com/88250/lute/ast"
|
"github.com/88250/lute/ast"
|
||||||
|
"github.com/gabriel-vasile/mimetype"
|
||||||
"github.com/siyuan-note/filelock"
|
"github.com/siyuan-note/filelock"
|
||||||
"github.com/siyuan-note/logging"
|
"github.com/siyuan-note/logging"
|
||||||
)
|
)
|
||||||
|
|
@ -73,6 +75,21 @@ func GetUniqueFilename(filePath string) string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetMimeTypeByExt(filePath string) (ret string) {
|
||||||
|
ret = mime.TypeByExtension(filepath.Ext(filePath))
|
||||||
|
if "" == ret {
|
||||||
|
m, err := mimetype.DetectFile(filePath)
|
||||||
|
if err != nil {
|
||||||
|
logging.LogErrorf("detect mime type of [%s] failed: %s", filePath, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if nil != m {
|
||||||
|
ret = m.String()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func IsSymlinkPath(absPath string) bool {
|
func IsSymlinkPath(absPath string) bool {
|
||||||
fi, err := os.Lstat(absPath)
|
fi, err := os.Lstat(absPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue