mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-07 16:04:19 +01:00
🎨 Add kernel API /api/filetree/getIDsByHPath https://github.com/siyuan-note/siyuan/issues/9654
This commit is contained in:
parent
8eb5e53f81
commit
38099e4892
6 changed files with 115 additions and 2 deletions
|
|
@ -249,6 +249,36 @@ func getFullHPathByID(c *gin.Context) {
|
|||
ret.Data = hPath
|
||||
}
|
||||
|
||||
func getIDsByHPath(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
||||
arg, ok := util.JsonArg(c, ret)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if nil == arg["path"] {
|
||||
return
|
||||
}
|
||||
if nil == arg["notebook"] {
|
||||
return
|
||||
}
|
||||
|
||||
notebook := arg["notebook"].(string)
|
||||
if util.InvalidIDPattern(notebook, ret) {
|
||||
return
|
||||
}
|
||||
|
||||
p := arg["path"].(string)
|
||||
ids, err := model.GetIDsByHPath(p, notebook)
|
||||
if nil != err {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
ret.Data = ids
|
||||
}
|
||||
|
||||
func moveDocs(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
|
|
|||
|
|
@ -106,6 +106,7 @@ func ServeAPI(ginServer *gin.Engine) {
|
|||
ginServer.Handle("POST", "/api/filetree/getHPathsByPaths", model.CheckAuth, getHPathsByPaths)
|
||||
ginServer.Handle("POST", "/api/filetree/getHPathByID", model.CheckAuth, getHPathByID)
|
||||
ginServer.Handle("POST", "/api/filetree/getFullHPathByID", model.CheckAuth, getFullHPathByID)
|
||||
ginServer.Handle("POST", "/api/filetree/getIDsByHPath", model.CheckAuth, getIDsByHPath)
|
||||
ginServer.Handle("POST", "/api/filetree/doc2Heading", model.CheckAuth, model.CheckReadonly, doc2Heading)
|
||||
ginServer.Handle("POST", "/api/filetree/heading2Doc", model.CheckAuth, model.CheckReadonly, heading2Doc)
|
||||
ginServer.Handle("POST", "/api/filetree/li2Doc", model.CheckAuth, model.CheckReadonly, li2Doc)
|
||||
|
|
|
|||
|
|
@ -1183,6 +1183,19 @@ func GetFullHPathByID(id string) (hPath string, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func GetIDsByHPath(hpath, boxID string) (ret []string, err error) {
|
||||
roots := treenode.GetBlockTreeRootsByHPath(boxID, hpath)
|
||||
if 1 > len(roots) {
|
||||
return
|
||||
}
|
||||
|
||||
for _, root := range roots {
|
||||
ret = append(ret, root.ID)
|
||||
}
|
||||
ret = gulu.Str.RemoveDuplicatedElem(ret)
|
||||
return
|
||||
}
|
||||
|
||||
func MoveDocs(fromPaths []string, toBoxID, toPath string, callback interface{}) (err error) {
|
||||
toBox := Conf.Box(toBoxID)
|
||||
if nil == toBox {
|
||||
|
|
|
|||
|
|
@ -143,6 +143,22 @@ func GetBlockTreeRootByHPath(boxID, hPath string) (ret *BlockTree) {
|
|||
return
|
||||
}
|
||||
|
||||
func GetBlockTreeRootsByHPath(boxID, hPath string) (ret []*BlockTree) {
|
||||
hPath = gulu.Str.RemoveInvisible(hPath)
|
||||
blockTrees.Range(func(key, value interface{}) bool {
|
||||
slice := value.(*btSlice)
|
||||
slice.m.Lock()
|
||||
for _, b := range slice.data {
|
||||
if b.BoxID == boxID && b.HPath == hPath && b.RootID == b.ID {
|
||||
ret = append(ret, b)
|
||||
}
|
||||
}
|
||||
slice.m.Unlock()
|
||||
return true
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func GetBlockTreeRootByHPathPreferredParentID(boxID, hPath, preferredParentID string) (ret *BlockTree) {
|
||||
hPath = gulu.Str.RemoveInvisible(hPath)
|
||||
var roots []*BlockTree
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue