mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-22 17:40:13 +01:00
🎨 网络图片转换为本地图片 遵循笔记本级资源文件设置 Fix https://github.com/siyuan-note/siyuan/issues/6407
This commit is contained in:
parent
bc8e26937f
commit
c2188b8c19
1 changed files with 10 additions and 1 deletions
|
|
@ -76,6 +76,15 @@ func NetImg2LocalAssets(rootID string) (err error) {
|
|||
|
||||
var files int
|
||||
msgId := gulu.Rand.String(7)
|
||||
|
||||
docDirLocalPath := filepath.Join(util.DataDir, tree.Box, path.Dir(tree.Path))
|
||||
assetsDirPath := getAssetsDir(filepath.Join(util.DataDir, tree.Box), docDirLocalPath)
|
||||
if !gulu.File.IsExist(assetsDirPath) {
|
||||
if err = os.MkdirAll(assetsDirPath, 0755); nil != err {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
|
||||
if !entering {
|
||||
return ast.WalkContinue
|
||||
|
|
@ -140,7 +149,7 @@ func NetImg2LocalAssets(rootID string) (err error) {
|
|||
name = gulu.Str.SubStr(name, 64)
|
||||
name = util.FilterFileName(name)
|
||||
name = "net-img-" + name + "-" + ast.NewNodeID() + ext
|
||||
writePath := filepath.Join(util.DataDir, "assets", name)
|
||||
writePath := filepath.Join(assetsDirPath, name)
|
||||
if err = filelock.WriteFile(writePath, data); nil != err {
|
||||
logging.LogErrorf("write downloaded net img [%s] to local assets [%s] failed: %s", u, writePath, err)
|
||||
return ast.WalkSkipChildren
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue