An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: `网络图片转换为本地图片` 支持处理 `file://` 本地路径图片 Fix https://github.com/siyuan-note/siyuan/issues/6546
Liang Dingb07ff243071d
diff --git a/kernel/model/assets.go b/kernel/model/assets.goindex c8bcd1332c..d67fed9191 100644--- a/kernel/model/assets.go+++ b/kernel/model/assets.go@@ -92,7 +92,33 @@ func NetImg2LocalAssets(rootID string) (err error) {if ast.NodeImage == n.Type {linkDest := n.ChildByType(ast.NodeLinkDest)dest := linkDest.Tokens- if !sql.IsAssetLinkDest(dest) && (bytes.HasPrefix(bytes.ToLower(dest), []byte("https://")) || bytes.HasPrefix(bytes.ToLower(dest), []byte("http://"))) {+ if util.IsAssetLinkDest(dest) {+ return ast.WalkSkipChildren+ }++ if bytes.HasPrefix(bytes.ToLower(dest), []byte("file://")) {+ // `网络图片转换为本地图片` 支持处理 `file://` 本地路径图片 https://github.com/siyuan-note/siyuan/issues/6546++ u := string(dest)[7:]+ if !gulu.File.IsExist(u) {+ return ast.WalkSkipChildren+ }++ name := filepath.Base(u)+ name = "net-img-" + name+ name = util.AssetName(name)+ writePath := filepath.Join(assetsDirPath, name)+ if err = gulu.File.Copy(u, writePath); nil != err {+ logging.LogErrorf("copy [%s] to [%s] failed: %s", u, writePath, err)+ return ast.WalkSkipChildren+ }++ linkDest.Tokens = []byte("assets/" + name)+ files+++ return ast.WalkSkipChildren+ }++ if bytes.HasPrefix(bytes.ToLower(dest), []byte("https://")) || bytes.HasPrefix(bytes.ToLower(dest), []byte("http://")) {u := string(dest)if strings.Contains(u, "qpic.cn") {// 改进 `网络图片转换为本地图片` 微信图片拉取 https://github.com/siyuan-note/siyuan/issues/5052@@ -592,7 +618,7 @@ func UnusedAssets() (ret []string) {if titleImgPath := treenode.GetDocTitleImgPath(tree.Root); "" != titleImgPath {// 题头图计入- if !sql.IsAssetLinkDest([]byte(titleImgPath)) {+ if !util.IsAssetLinkDest([]byte(titleImgPath)) {continue}dests[titleImgPath] = truediff --git a/kernel/sql/aseet.go b/kernel/sql/aseet.goindex a3dff9767f..4040944a3e 100644--- a/kernel/sql/aseet.go+++ b/kernel/sql/aseet.go@@ -64,7 +64,7 @@ func docTagSpans(n *ast.Node) (ret []*Span) {func docTitleImgAsset(root *ast.Node) *Asset {if p := treenode.GetDocTitleImgPath(root); "" != p {- if !IsAssetLinkDest([]byte(p)) {+ if !util.IsAssetLinkDest([]byte(p)) {return nil}diff --git a/kernel/sql/database.go b/kernel/sql/database.goindex 45037f38db..6be61e0243 100644--- a/kernel/sql/database.go+++ b/kernel/sql/database.go@@ -582,7 +582,7 @@ func buildSpanFromNode(n *ast.Node, tree *parse.Tree, rootID, boxID, p string) (// assetsLinkDestsInTree- if !IsAssetLinkDest(destNode.Tokens) {+ if !util.IsAssetLinkDest(destNode.Tokens) {return}@@ -690,7 +690,7 @@ func buildSpanFromNode(n *ast.Node, tree *parse.Tree, rootID, boxID, p string) (return}- if !IsAssetLinkDest(src) {+ if !util.IsAssetLinkDest(src) {walkStatus = ast.WalkContinuereturn}@@ -1247,10 +1247,6 @@ func ialAttr(ial, name string) (ret string) {return}-func IsAssetLinkDest(dest []byte) bool {- return bytes.HasPrefix(dest, []byte("assets/"))-}-func removeDatabaseFile() (err error) {err = os.RemoveAll(util.DBPath)if nil != err {diff --git a/kernel/util/path.go b/kernel/util/path.goindex 741e8354ab..a9cc81a79c 100644--- a/kernel/util/path.go+++ b/kernel/util/path.go@@ -208,3 +208,7 @@ func FilterSelfChildDocs(paths []string) (ret []string) {}return}++func IsAssetLinkDest(dest []byte) bool {+ return bytes.HasPrefix(dest, []byte("assets/"))+}