An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: Unable to search audio, video blocks by asset path https://github.com/siyuan-note/siyuan/issues/10468
Daniel8d9eafbfd8d5
diff --git a/kernel/model/assets.go b/kernel/model/assets.goindex 6786431d05..4c27560da9 100644--- a/kernel/model/assets.go+++ b/kernel/model/assets.go@@ -1104,21 +1104,21 @@ func assetsLinkDestsInNode(node *ast.Node) (ret []string) {}if ast.NodeLinkDest == n.Type {- if !isRelativePath(n.Tokens) {+ if !treenode.IsRelativePath(n.Tokens) {return ast.WalkContinue}dest := strings.TrimSpace(string(n.Tokens))ret = append(ret, dest)} else if n.IsTextMarkType("a") {- if !isRelativePath(gulu.Str.ToBytes(n.TextMarkAHref)) {+ if !treenode.IsRelativePath(gulu.Str.ToBytes(n.TextMarkAHref)) {return ast.WalkContinue}dest := strings.TrimSpace(n.TextMarkAHref)ret = append(ret, dest)} else if n.IsTextMarkType("file-annotation-ref") {- if !isRelativePath(gulu.Str.ToBytes(n.TextMarkFileAnnotationRefID)) {+ if !treenode.IsRelativePath(gulu.Str.ToBytes(n.TextMarkFileAnnotationRefID)) {return ast.WalkContinue}@@ -1136,24 +1136,14 @@ func assetsLinkDestsInNode(node *ast.Node) (ret []string) {// 兼容两种属性名 custom-data-assets 和 data-assets https://github.com/siyuan-note/siyuan/issues/4122#issuecomment-1154796568dataAssets = n.IALAttr("data-assets")}- if "" == dataAssets || !isRelativePath([]byte(dataAssets)) {+ if "" == dataAssets || !treenode.IsRelativePath([]byte(dataAssets)) {return ast.WalkContinue}ret = append(ret, dataAssets)} else { // HTMLBlock/InlineHTML/IFrame/Audio/Video- if index := bytes.Index(n.Tokens, []byte("src=\"")); 0 < index {- src := n.Tokens[index+len("src=\""):]- if index = bytes.Index(src, []byte("\"")); 0 < index {- src = src[:bytes.Index(src, []byte("\""))]- if !isRelativePath(src) {- return ast.WalkContinue- }-- dest := strings.TrimSpace(string(src))- ret = append(ret, dest)- } else {- logging.LogWarnf("src is missing the closing double quote in tree [%s] ", node.Box+node.Path)- }+ dest := treenode.GetNodeSrcTokens(n)+ if "" != dest {+ ret = append(ret, dest)}}}@@ -1169,16 +1159,6 @@ func assetsLinkDestsInNode(node *ast.Node) (ret []string) {return}-func isRelativePath(dest []byte) bool {- if 1 > len(dest) {- return false- }- if '/' == dest[0] {- return false- }- return !bytes.Contains(dest, []byte(":"))-}-// allAssetAbsPaths 返回 asset 相对路径(assets/xxx)到绝对路径(F:\SiYuan\data\assets\xxx)的映射。func allAssetAbsPaths() (assetsAbsPathMap map[string]string, err error) {notebooks, err := ListNotebooks()diff --git a/kernel/model/export.go b/kernel/model/export.goindex 93ba47f3c7..763a49081c 100644--- a/kernel/model/export.go+++ b/kernel/model/export.go@@ -1620,7 +1620,7 @@ func exportSYZip(boxID, rootDirPath, baseFolderName string, docPaths []string) (case av.KeyTypeMAsset: // 导出资源文件列 https://github.com/siyuan-note/siyuan/issues/9919for _, value := range keyValues.Values {for _, asset := range value.MAsset {- if !isRelativePath([]byte(asset.Content)) {+ if !treenode.IsRelativePath([]byte(asset.Content)) {continue}diff --git a/kernel/treenode/node.go b/kernel/treenode/node.goindex f9076b07c7..a3f6bad5dc 100644--- a/kernel/treenode/node.go+++ b/kernel/treenode/node.go@@ -283,6 +283,9 @@ func NodeStaticContent(node *ast.Node, excludeTypes []string, includeTextMarkATibuf.WriteByte(lex.ItemBackslash)case ast.NodeBackslashContent:buf.Write(n.Tokens)+ case ast.NodeAudio, ast.NodeVideo:+ buf.WriteString(GetNodeSrcTokens(n))+ buf.WriteByte(' ')}lastSpace = falsereturn ast.WalkContinue@@ -293,6 +296,34 @@ func NodeStaticContent(node *ast.Node, excludeTypes []string, includeTextMarkATireturn buf.String()}+func GetNodeSrcTokens(n *ast.Node) (ret string) {+ if index := bytes.Index(n.Tokens, []byte("src=\"")); 0 < index {+ src := n.Tokens[index+len("src=\""):]+ if index = bytes.Index(src, []byte("\"")); 0 < index {+ src = src[:bytes.Index(src, []byte("\""))]+ if !IsRelativePath(src) {+ return+ }++ ret = strings.TrimSpace(string(src))+ return+ }++ logging.LogWarnf("src is missing the closing double quote in tree [%s] ", n.Box+n.Path)+ }+ return+}++func IsRelativePath(dest []byte) bool {+ if 1 > len(dest) {+ return false+ }+ if '/' == dest[0] {+ return false+ }+ return !bytes.Contains(dest, []byte(":"))+}+func FirstLeafBlock(node *ast.Node) (ret *ast.Node) {ast.Walk(node, func(n *ast.Node, entering bool) ast.WalkStatus {if !entering || n.IsMarker() {