Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: The images in the embed blocks are not uploaded to the community hosting https://github.com/siyuan-note/siyuan/issues/10042

Daniel275714f0170b
diff --git a/app/changelogs/v2.12.0/v2.12.0.md b/app/changelogs/v2.12.0/v2.12.0.md
index 3a77274eab..fa104d3c28 100644
--- a/app/changelogs/v2.12.0/v2.12.0.md
+++ b/app/changelogs/v2.12.0/v2.12.0.md
@@ -36,6 +36,7 @@ Below are the detailed changes in this version.
* [Reference jump is not located in read-only mode](https://github.com/siyuan-note/siyuan/issues/10028)
* [Converting PDF annotation ref to text fails after setting the appearance](https://github.com/siyuan-note/siyuan/issues/10029)
* [Pressing the scoring shortcut key immediately after `Alt+F` is invalid](https://github.com/siyuan-note/siyuan/issues/10020)
+* [The images in the embed blocks are not uploaded to the community hosting](https://github.com/siyuan-note/siyuan/issues/10042)
### Development
diff --git a/app/changelogs/v2.12.0/v2.12.0_zh_CHT.md b/app/changelogs/v2.12.0/v2.12.0_zh_CHT.md
index 39ba7f3c38..e2be68fff8 100644
--- a/app/changelogs/v2.12.0/v2.12.0_zh_CHT.md
+++ b/app/changelogs/v2.12.0/v2.12.0_zh_CHT.md
@@ -36,6 +36,7 @@
* [唯讀模式下引用跳轉後未定位瀏覽位置](https://github.com/siyuan-note/siyuan/issues/10028)
* [無法轉換外觀樣式的 PDF 註解引用為文字](https://github.com/siyuan-note/siyuan/issues/10029)
* [`Alt+F` 後快速按下評分快捷鍵失效](https://github.com/siyuan-note/siyuan/issues/10020)
+* [在嵌入區塊中的圖片未能上傳社群](https://github.com/siyuan-note/siyuan/issues/10042)
### 開發者
diff --git a/app/changelogs/v2.12.0/v2.12.0_zh_CN.md b/app/changelogs/v2.12.0/v2.12.0_zh_CN.md
index 36ed88b0b2..da9159b30c 100644
--- a/app/changelogs/v2.12.0/v2.12.0_zh_CN.md
+++ b/app/changelogs/v2.12.0/v2.12.0_zh_CN.md
@@ -36,6 +36,7 @@
* [只读模式下引用跳转后未定位浏览位置](https://github.com/siyuan-note/siyuan/issues/10028)
* [无法转换带外观样式的 PDF 注释引用为文本](https://github.com/siyuan-note/siyuan/issues/10029)
* [`Alt+F` 后快速按下评分快捷键失效](https://github.com/siyuan-note/siyuan/issues/10020)
+* [在嵌入块中的图片未能上传社区](https://github.com/siyuan-note/siyuan/issues/10042)
### 开发者
diff --git a/kernel/model/assets.go b/kernel/model/assets.go
index f1050f960e..3f0a02750e 100644
--- a/kernel/model/assets.go
+++ b/kernel/model/assets.go
@@ -20,6 +20,7 @@ import (
"bytes"
"errors"
"fmt"
+ "github.com/88250/lute/editor"
"io"
"io/fs"
"mime"
@@ -520,6 +521,9 @@ func UploadAssets2Cloud(rootID string) (count int, err error) {
}
assets := assetsLinkDestsInTree(tree)
+ embedAssets := assetsLinkDestsInQueryEmbedNodes(tree)
+ assets = append(assets, embedAssets...)
+ assets = gulu.Str.RemoveDuplicatedElem(assets)
err = uploadAssets2Cloud(assets, bizTypeUploadAssets)
if nil != err {
return
@@ -1053,9 +1057,43 @@ func emojisInTree(tree *parse.Tree) (ret []string) {
return
}
-func assetsLinkDestsInTree(tree *parse.Tree) (ret []string) {
+func assetsLinkDestsInQueryEmbedNodes(tree *parse.Tree) (ret []string) {
ret = []string{}
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
+ if !entering || ast.NodeBlockQueryEmbedScript != n.Type {
+ return ast.WalkContinue
+ }
+
+ stmt := n.ChildByType(ast.NodeBlockQueryEmbedScript).TokensStr()
+ stmt = html.UnescapeString(stmt)
+ stmt = strings.ReplaceAll(stmt, editor.IALValEscNewLine, "\n")
+ sqlBlocks := sql.SelectBlocksRawStmt(stmt, 1, Conf.Search.Limit)
+ for _, sqlBlock := range sqlBlocks {
+ subtree, _ := loadTreeByBlockID(sqlBlock.ID)
+ if nil == subtree {
+ continue
+ }
+ embedNode := treenode.GetNodeInTree(subtree, sqlBlock.ID)
+ if nil == embedNode {
+ continue
+ }
+
+ ret = append(ret, assetsLinkDestsInNode(embedNode)...)
+ }
+ return ast.WalkContinue
+ })
+ ret = gulu.Str.RemoveDuplicatedElem(ret)
+ return
+}
+
+func assetsLinkDestsInTree(tree *parse.Tree) (ret []string) {
+ ret = assetsLinkDestsInNode(tree.Root)
+ return
+}
+
+func assetsLinkDestsInNode(node *ast.Node) (ret []string) {
+ ret = []string{}
+ ast.Walk(node, func(n *ast.Node, entering bool) ast.WalkStatus {
// 修改以下代码时需要同时修改 database 构造行级元素实现,增加必要的类型
if !entering || (ast.NodeLinkDest != n.Type && ast.NodeHTMLBlock != n.Type && ast.NodeInlineHTML != n.Type &&
ast.NodeIFrame != n.Type && ast.NodeWidget != n.Type && ast.NodeAudio != n.Type && ast.NodeVideo != n.Type &&
@@ -1112,7 +1150,7 @@ func assetsLinkDestsInTree(tree *parse.Tree) (ret []string) {
dest := strings.TrimSpace(string(src))
ret = append(ret, dest)
} else {
- logging.LogWarnf("src is missing the closing double quote in tree [%s] ", tree.Box+tree.Path)
+ logging.LogWarnf("src is missing the closing double quote in tree [%s] ", node.Box+node.Path)
}
}
}
diff --git a/kernel/model/export.go b/kernel/model/export.go
index fa91a029b0..62d6f02d60 100644
--- a/kernel/model/export.go
+++ b/kernel/model/export.go
@@ -68,6 +68,9 @@ func Export2Liandi(id string) (err error) {
}
assets := assetsLinkDestsInTree(tree)
+ embedAssets := assetsLinkDestsInQueryEmbedNodes(tree)
+ assets = append(assets, embedAssets...)
+ assets = gulu.Str.RemoveDuplicatedElem(assets)
err = uploadAssets2Cloud(assets, bizTypeExport2Liandi)
if nil != err {
return