mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 23:20:13 +01:00
🧑💻 Add a kernel API /api/filetree/moveDocsByID https://github.com/siyuan-note/siyuan/issues/13247
This commit is contained in:
parent
c1fd34f57b
commit
f21f0ea60b
4 changed files with 145 additions and 32 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue