From f4a5bd105fb926d3ae2f7a45f8a07e647c4e55c1 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Tue, 10 Jun 2025 17:05:08 +0800 Subject: [PATCH] :technologist: Add kernel API `/api/block/getBlockDOMs` https://github.com/siyuan-note/siyuan/issues/15004 --- kernel/api/block.go | 19 +++++++++++++++++++ kernel/api/router.go | 2 +- kernel/model/block.go | 18 ++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/kernel/api/block.go b/kernel/api/block.go index 3948d4c67..8bf57072e 100644 --- a/kernel/api/block.go +++ b/kernel/api/block.go @@ -653,6 +653,25 @@ func getBlockDOM(c *gin.Context) { } } +func getBlockDOMs(c *gin.Context) { + ret := gulu.Ret.NewResult() + defer c.JSON(http.StatusOK, ret) + + arg, ok := util.JsonArg(c, ret) + if !ok { + return + } + + idsArg := arg["ids"].([]interface{}) + var ids []string + for _, id := range idsArg { + ids = append(ids, id.(string)) + } + + doms := model.GetBlockDOMs(ids) + ret.Data = doms +} + func getBlockKramdown(c *gin.Context) { ret := gulu.Ret.NewResult() defer c.JSON(http.StatusOK, ret) diff --git a/kernel/api/router.go b/kernel/api/router.go index 2865e7ec9..dc0c7fa5f 100644 --- a/kernel/api/router.go +++ b/kernel/api/router.go @@ -174,6 +174,7 @@ func ServeAPI(ginServer *gin.Engine) { ginServer.Handle("POST", "/api/block/getBlockInfo", model.CheckAuth, getBlockInfo) ginServer.Handle("POST", "/api/block/getBlockDOM", model.CheckAuth, getBlockDOM) + ginServer.Handle("POST", "/api/block/getBlockDOMs", model.CheckAuth, getBlockDOMs) ginServer.Handle("POST", "/api/block/getBlockKramdown", model.CheckAuth, getBlockKramdown) ginServer.Handle("POST", "/api/block/getChildBlocks", model.CheckAuth, getChildBlocks) ginServer.Handle("POST", "/api/block/getTailChildBlocks", model.CheckAuth, getTailChildBlocks) @@ -455,7 +456,6 @@ func ServeAPI(ginServer *gin.Engine) { ginServer.Handle("POST", "/api/av/appendAttributeViewDetachedBlocksWithValues", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, appendAttributeViewDetachedBlocksWithValues) ginServer.Handle("POST", "/api/av/getCurrentAttrViewImages", model.CheckAuth, getCurrentAttrViewImages) - ginServer.Handle("POST", "/api/ai/chatGPT", model.CheckAuth, model.CheckAdminRole, chatGPT) ginServer.Handle("POST", "/api/ai/chatGPTWithAction", model.CheckAuth, model.CheckAdminRole, chatGPTWithAction) diff --git a/kernel/model/block.go b/kernel/model/block.go index 179eb8296..0b6885780 100644 --- a/kernel/model/block.go +++ b/kernel/model/block.go @@ -696,6 +696,24 @@ func GetBlockDOM(id string) (ret string) { return } +func GetBlockDOMs(ids []string) (ret map[string]string) { + ret = map[string]string{} + if 0 == len(ids) { + return + } + + luteEngine := NewLute() + trees := filesys.LoadTrees(ids) + for id, tree := range trees { + node := treenode.GetNodeInTree(tree, id) + if nil == node { + continue + } + ret[id] = luteEngine.RenderNodeBlockDOM(node) + } + return +} + func GetBlockKramdown(id, mode string) (ret string) { if "" == id { return