An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:technologist: Add internal kernel API `/api/block/getBlocksIndexes` Fix https://github.com/siyuan-note/siyuan/issues/10608
Daniel095dfc2b3504
diff --git a/kernel/api/block.go b/kernel/api/block.goindex 6054bcf062..7d242a6cd3 100644--- a/kernel/api/block.go+++ b/kernel/api/block.go@@ -436,6 +436,24 @@ func getBlockIndex(c *gin.Context) {ret.Data = index}+func getBlocksIndexes(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))+ }+ index := model.GetBlocksIndexes(ids)+ ret.Data = index+}+func getBlockInfo(c *gin.Context) {ret := gulu.Ret.NewResult()defer c.JSON(http.StatusOK, ret)diff --git a/kernel/api/router.go b/kernel/api/router.goindex 6d3fbef6a9..f598494803 100644--- a/kernel/api/router.go+++ b/kernel/api/router.go@@ -168,6 +168,7 @@ func ServeAPI(ginServer *gin.Engine) {ginServer.Handle("POST", "/api/block/getTailChildBlocks", model.CheckAuth, getTailChildBlocks)ginServer.Handle("POST", "/api/block/getBlockBreadcrumb", model.CheckAuth, getBlockBreadcrumb)ginServer.Handle("POST", "/api/block/getBlockIndex", model.CheckAuth, getBlockIndex)+ ginServer.Handle("POST", "/api/block/getBlocksIndexes", model.CheckAuth, getBlocksIndexes)ginServer.Handle("POST", "/api/block/getRefIDs", model.CheckAuth, getRefIDs)ginServer.Handle("POST", "/api/block/getRefIDsByFileAnnotationID", model.CheckAuth, getRefIDsByFileAnnotationID)ginServer.Handle("POST", "/api/block/getBlockDefIDsByRefText", model.CheckAuth, getBlockDefIDsByRefText)diff --git a/kernel/model/blockinfo.go b/kernel/model/blockinfo.goindex f59ccc9938..5b9ca044b3 100644--- a/kernel/model/blockinfo.go+++ b/kernel/model/blockinfo.go@@ -274,6 +274,39 @@ func GetBlockIndex(id string) (ret int) {return}+func GetBlocksIndexes(ids []string) (ret map[string]int) {+ ret = map[string]int{}+ if 1 > len(ids) {+ return+ }++ tree, _ := LoadTreeByBlockID(ids[0])+ if nil == tree {+ return+ }++ idx := 0+ nodesIndexes := map[string]int{}+ ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {+ if !entering {+ return ast.WalkContinue+ }++ if !n.IsChildBlockOf(tree.Root, 1) {+ return ast.WalkContinue+ }++ nodesIndexes[n.ID] = idx+ idx+++ return ast.WalkContinue+ })++ for _, id := range ids {+ ret[id] = nodesIndexes[id]+ }+ return+}+type BlockPath struct {ID string `json:"id"`Name string `json:"name"`