🐛 Dragging a file from the assets folder into the editor causes the kernel to exit https://github.com/siyuan-note/siyuan/issues/15355

This commit is contained in:
Daniel 2025-07-24 11:19:25 +08:00
parent 684286fc8a
commit 10a760b97a
No known key found for this signature in database
GPG key ID: 86211BA83DF03017

View file

@ -33,7 +33,7 @@ import (
"github.com/siyuan-note/siyuan/kernel/util" "github.com/siyuan-note/siyuan/kernel/util"
) )
func InsertLocalAssets(id string, assetPaths []string, isUpload bool) (succMap map[string]interface{}, err error) { func InsertLocalAssets(id string, assetAbsPaths []string, isUpload bool) (succMap map[string]interface{}, err error) {
succMap = map[string]interface{}{} succMap = map[string]interface{}{}
bt := treenode.GetBlockTree(id) bt := treenode.GetBlockTree(id)
@ -50,28 +50,35 @@ func InsertLocalAssets(id string, assetPaths []string, isUpload bool) (succMap m
} }
} }
for _, p := range assetPaths { for _, assetAbsPath := range assetAbsPaths {
baseName := filepath.Base(p) baseName := filepath.Base(assetAbsPath)
fName := baseName fName := baseName
fName = util.FilterUploadFileName(fName) fName = util.FilterUploadFileName(fName)
ext := filepath.Ext(fName) ext := filepath.Ext(fName)
fName = strings.TrimSuffix(fName, ext) fName = strings.TrimSuffix(fName, ext)
ext = strings.ToLower(ext) ext = strings.ToLower(ext)
fName += ext fName += ext
if gulu.File.IsDir(p) || !isUpload { if gulu.File.IsDir(assetAbsPath) || !isUpload {
if !strings.HasPrefix(p, "\\\\") { if !strings.HasPrefix(assetAbsPath, "\\\\") {
p = "file://" + p assetAbsPath = "file://" + assetAbsPath
} }
succMap[baseName] = p succMap[baseName] = assetAbsPath
continue continue
} }
fi, statErr := os.Stat(p) if util.IsSubPath(assetsDirPath, assetAbsPath) {
// 已经位于 assets 目录下的资源文件不处理
// Dragging a file from the assets folder into the editor causes the kernel to exit https://github.com/siyuan-note/siyuan/issues/15355
succMap[baseName] = "assets/" + fName
continue
}
fi, statErr := os.Stat(assetAbsPath)
if nil != statErr { if nil != statErr {
err = statErr err = statErr
return return
} }
f, openErr := os.Open(p) f, openErr := os.Open(assetAbsPath)
if nil != openErr { if nil != openErr {
err = openErr err = openErr
return return