From 540c81995e7a92126ab6c771bc33d2f6840e8b30 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sat, 12 Jul 2025 10:40:20 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/15260 --- kernel/util/path.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/kernel/util/path.go b/kernel/util/path.go index d651dc829..5f382934f 100644 --- a/kernel/util/path.go +++ b/kernel/util/path.go @@ -29,6 +29,7 @@ import ( "time" "github.com/88250/gulu" + "github.com/gabriel-vasile/mimetype" "github.com/siyuan-note/filelock" "github.com/siyuan-note/logging" ) @@ -317,10 +318,23 @@ var ( SiYuanAssetsVideo = []string{".mov", ".weba", ".mkv", ".mp4", ".webm"} ) -func IsAssetsImage(p string) bool { - ext := strings.ToLower(filepath.Ext(p)) +func IsAssetsImage(assetPath string) bool { + ext := strings.ToLower(filepath.Ext(assetPath)) if "" == ext { - return false + absPath := filepath.Join(DataDir, assetPath) + f, err := filelock.OpenFile(absPath, os.O_RDONLY, 0644) + if err != nil { + logging.LogErrorf("open file [%s] failed: %s", absPath, err) + return false + } + defer filelock.CloseFile(f) + m, err := mimetype.DetectReader(f) + if nil != err { + logging.LogWarnf("detect file [%s] mimetype failed: %v", absPath, err) + return false + } + + ext = m.Extension() } return gulu.Str.Contains(ext, SiYuanAssetsImage) }