mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 07:00:12 +01:00
🎨 超链接地址更好地兼容本地路径 https://github.com/siyuan-note/siyuan/issues/5980
This commit is contained in:
parent
af25cf1d7c
commit
bc6f6e467e
2 changed files with 12 additions and 7 deletions
|
|
@ -231,8 +231,13 @@ func insertLocalAssets(c *gin.Context) {
|
||||||
for _, pathArg := range assetPathsArg {
|
for _, pathArg := range assetPathsArg {
|
||||||
assetPaths = append(assetPaths, pathArg.(string))
|
assetPaths = append(assetPaths, pathArg.(string))
|
||||||
}
|
}
|
||||||
|
isUpload := true
|
||||||
|
isUploadArg := arg["isUpload"]
|
||||||
|
if nil != isUploadArg {
|
||||||
|
isUpload = isUploadArg.(bool)
|
||||||
|
}
|
||||||
id := arg["id"].(string)
|
id := arg["id"].(string)
|
||||||
succMap, err := model.InsertLocalAssets(id, assetPaths)
|
succMap, err := model.InsertLocalAssets(id, assetPaths, isUpload)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
ret.Code = -1
|
ret.Code = -1
|
||||||
ret.Msg = err.Error()
|
ret.Msg = err.Error()
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ import (
|
||||||
"github.com/siyuan-note/siyuan/kernel/util"
|
"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{}{}
|
succMap = map[string]interface{}{}
|
||||||
|
|
||||||
bt := treenode.GetBlockTree(id)
|
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))
|
docDirLocalPath := filepath.Join(util.DataDir, bt.BoxID, path.Dir(bt.Path))
|
||||||
assets := getAssetsDir(filepath.Join(util.DataDir, bt.BoxID), docDirLocalPath)
|
assetsDirPath := getAssetsDir(filepath.Join(util.DataDir, bt.BoxID), docDirLocalPath)
|
||||||
if !gulu.File.IsExist(assets) {
|
if !gulu.File.IsExist(assetsDirPath) {
|
||||||
if err = os.MkdirAll(assets, 0755); nil != err {
|
if err = os.MkdirAll(assetsDirPath, 0755); nil != err {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -59,7 +59,7 @@ func InsertLocalAssets(id string, assetPaths []string) (succMap map[string]inter
|
||||||
ext = strings.ToLower(ext)
|
ext = strings.ToLower(ext)
|
||||||
fName += ext
|
fName += ext
|
||||||
baseName := fName
|
baseName := fName
|
||||||
if gulu.File.IsDir(p) {
|
if gulu.File.IsDir(p) || !isUpload {
|
||||||
succMap[baseName] = "file://" + p
|
succMap[baseName] = "file://" + p
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
@ -87,7 +87,7 @@ func InsertLocalAssets(id string, assetPaths []string) (succMap map[string]inter
|
||||||
ext := path.Ext(fName)
|
ext := path.Ext(fName)
|
||||||
fName = fName[0 : len(fName)-len(ext)]
|
fName = fName[0 : len(fName)-len(ext)]
|
||||||
fName = fName + "-" + ast.NewNodeID() + 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 {
|
if _, err = f.Seek(0, io.SeekStart); nil != err {
|
||||||
f.Close()
|
f.Close()
|
||||||
return
|
return
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue