🎨 超链接地址更好地兼容本地路径 https://github.com/siyuan-note/siyuan/issues/5980

This commit is contained in:
Liang Ding 2022-09-27 14:45:24 +08:00
parent af25cf1d7c
commit bc6f6e467e
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
2 changed files with 12 additions and 7 deletions

View file

@ -34,7 +34,7 @@ import (
"github.com/siyuan-note/siyuan/kernel/util"
)
func InsertLocalAssets(id string, assetPaths []string) (succMap map[string]interface{}, err error) {
func InsertLocalAssets(id string, assetPaths []string, isUpload bool) (succMap map[string]interface{}, err error) {
succMap = map[string]interface{}{}
bt := treenode.GetBlockTree(id)
@ -44,9 +44,9 @@ func InsertLocalAssets(id string, assetPaths []string) (succMap map[string]inter
}
docDirLocalPath := filepath.Join(util.DataDir, bt.BoxID, path.Dir(bt.Path))
assets := getAssetsDir(filepath.Join(util.DataDir, bt.BoxID), docDirLocalPath)
if !gulu.File.IsExist(assets) {
if err = os.MkdirAll(assets, 0755); nil != err {
assetsDirPath := getAssetsDir(filepath.Join(util.DataDir, bt.BoxID), docDirLocalPath)
if !gulu.File.IsExist(assetsDirPath) {
if err = os.MkdirAll(assetsDirPath, 0755); nil != err {
return
}
}
@ -59,7 +59,7 @@ func InsertLocalAssets(id string, assetPaths []string) (succMap map[string]inter
ext = strings.ToLower(ext)
fName += ext
baseName := fName
if gulu.File.IsDir(p) {
if gulu.File.IsDir(p) || !isUpload {
succMap[baseName] = "file://" + p
continue
}
@ -87,7 +87,7 @@ func InsertLocalAssets(id string, assetPaths []string) (succMap map[string]inter
ext := path.Ext(fName)
fName = fName[0 : len(fName)-len(ext)]
fName = fName + "-" + ast.NewNodeID() + ext
writePath := filepath.Join(assets, fName)
writePath := filepath.Join(assetsDirPath, fName)
if _, err = f.Seek(0, io.SeekStart); nil != err {
f.Close()
return