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: Use the util.FileURLToLocalPath function to convert `file://` file links uniformly (#17239)
Jeffrey Chen26e72ea29255
diff --git a/kernel/api/asset.go b/kernel/api/asset.goindex e38685b444..2595130c45 100644--- a/kernel/api/asset.go+++ b/kernel/api/asset.go@@ -52,14 +52,8 @@ func statAsset(c *gin.Context) {return}- } else if strings.HasPrefix(path, "file://") {- p = strings.TrimPrefix(path, "file://")- if strings.Contains(p, ":") {- p = strings.TrimPrefix(p, "/")- }- if strings.Contains(p, "?") {- p = p[:strings.Index(p, "?")]- }+ } else if localPath := util.FileURLToLocalPath(path); localPath != "" {+ p = localPath} else {ret.Code = 1returndiff --git a/kernel/api/lute.go b/kernel/api/lute.goindex 7db179ed6e..a5ef083dd4 100644--- a/kernel/api/lute.go+++ b/kernel/api/lute.go@@ -18,7 +18,6 @@ package apiimport ("net/http"- "net/url""path/filepath""strings"@@ -156,18 +155,7 @@ func html2BlockDOM(c *gin.Context) {if strings.HasPrefix(localPath, "http") {return ast.WalkContinue}-- localPath = strings.TrimPrefix(localPath, "file://")- if gulu.OS.IsWindows() {- localPath = strings.TrimPrefix(localPath, "/")- }-- unescaped, _ := url.PathUnescape(localPath)- if unescaped != localPath {- // `Convert network images/assets to local` supports URL-encoded local file names https://github.com/siyuan-note/siyuan/issues/9929- localPath = unescaped- }-+ localPath = util.FileURLToLocalPath(localPath)if !filepath.IsAbs(localPath) {// Kernel crash when copy-pasting from some browsers https://github.com/siyuan-note/siyuan/issues/9203return ast.WalkContinuediff --git a/kernel/model/assets.go b/kernel/model/assets.goindex 3c08e8f314..5d9e2dfb6d 100644--- a/kernel/model/assets.go+++ b/kernel/model/assets.go@@ -261,20 +261,7 @@ func netAssets2LocalAssets0(tree *parse.Tree, onlyImg bool, originalURL string,}for _, dest := range dests {- if strings.HasPrefix(strings.ToLower(dest), "file://") { // 处理本地文件链接- u := dest[7:]- unescaped, _ := url.PathUnescape(u)- if unescaped != u {- // `Convert network images/assets to local` supports URL-encoded local file names https://github.com/siyuan-note/siyuan/issues/9929- u = unescaped- }- if strings.Contains(u, ":") {- u = strings.TrimPrefix(u, "/")- }- if strings.Contains(u, "?") {- u = u[:strings.Index(u, "?")]- }-+ if u := util.FileURLToLocalPath(dest); u != "" { // 处理本地文件链接if !gulu.File.IsExist(u) {logging.LogErrorf("local file asset [%s] not exist", u)continue