🧑‍💻 Add a kernel API /api/filetree/moveDocsByID https://github.com/siyuan-note/siyuan/issues/13247

This commit is contained in:
Daniel 2024-12-05 10:49:54 +08:00
parent c1fd34f57b
commit f21f0ea60b
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
4 changed files with 145 additions and 32 deletions

View file

@ -472,9 +472,7 @@ func moveDocs(c *gin.Context) {
if util.InvalidIDPattern(toNotebook, ret) {
return
}
callback := arg["callback"]
err := model.MoveDocs(fromPaths, toNotebook, toPath, callback)
if err != nil {
ret.Code = -1
@ -484,6 +482,61 @@ func moveDocs(c *gin.Context) {
}
}
func moveDocsByID(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)
arg, ok := util.JsonArg(c, ret)
if !ok {
return
}
fromIDsArg := arg["fromIDs"].([]any)
var fromIDs []string
for _, fromIDArg := range fromIDsArg {
fromID := fromIDArg.(string)
if util.InvalidIDPattern(fromID, ret) {
return
}
fromIDs = append(fromIDs, fromID)
}
toID := arg["toID"].(string)
if util.InvalidIDPattern(toID, ret) {
return
}
var fromPaths []string
for _, fromID := range fromIDs {
tree, err := model.LoadTreeByBlockID(fromID)
if err != nil {
ret.Code = -1
ret.Msg = err.Error()
ret.Data = map[string]interface{}{"closeTimeout": 7000}
return
}
fromPaths = append(fromPaths, tree.Path)
}
fromPaths = gulu.Str.RemoveDuplicatedElem(fromPaths)
toTree, err := model.LoadTreeByBlockID(toID)
if err != nil {
ret.Code = -1
ret.Msg = err.Error()
ret.Data = map[string]interface{}{"closeTimeout": 7000}
return
}
toNotebook := toTree.Box
toPath := toTree.Path
callback := arg["callback"]
err = model.MoveDocs(fromPaths, toNotebook, toPath, callback)
if err != nil {
ret.Code = -1
ret.Msg = err.Error()
ret.Data = map[string]interface{}{"closeTimeout": 7000}
return
}
}
func removeDoc(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)