🎨 Improve create doc event push

This commit is contained in:
Daniel 2025-02-09 11:33:43 +08:00
parent 0658c85b2e
commit 4824feaa2f
No known key found for this signature in database
GPG key ID: 86211BA83DF03017

View file

@ -231,24 +231,12 @@ func heading2Doc(c *gin.Context) {
}
model.FlushTxQueue()
luteEngine := util.NewLute()
tree, err := filesys.LoadTree(targetNotebook, targetPath, luteEngine)
if err != nil {
ret.Code = -1
ret.Msg = err.Error()
return
}
name := path.Base(targetPath)
box := model.Conf.Box(targetNotebook)
files, _, _ := model.ListDocTree(targetNotebook, path.Dir(targetPath), util.SortModeUnassigned, false, false, model.Conf.FileTree.MaxListCount)
evt := util.NewCmdResult("heading2doc", 0, util.PushModeBroadcast)
evt.Data = map[string]interface{}{
"box": box,
"path": targetPath,
"files": files,
"name": name,
"id": tree.Root.ID,
"srcRootBlockID": srcRootBlockID,
}
evt.Callback = arg["callback"]
@ -283,24 +271,12 @@ func li2Doc(c *gin.Context) {
}
model.FlushTxQueue()
luteEngine := util.NewLute()
tree, err := filesys.LoadTree(targetNotebook, targetPath, luteEngine)
if err != nil {
ret.Code = -1
ret.Msg = err.Error()
return
}
name := path.Base(targetPath)
box := model.Conf.Box(targetNotebook)
files, _, _ := model.ListDocTree(targetNotebook, path.Dir(targetPath), util.SortModeUnassigned, false, false, model.Conf.FileTree.MaxListCount)
evt := util.NewCmdResult("li2doc", 0, util.PushModeBroadcast)
evt.Data = map[string]interface{}{
"box": box,
"path": targetPath,
"files": files,
"name": name,
"id": tree.Root.ID,
"srcRootBlockID": srcRootBlockID,
}
evt.Callback = arg["callback"]
@ -679,7 +655,7 @@ func duplicateDoc(c *gin.Context) {
notebook := tree.Box
box := model.Conf.Box(notebook)
model.DuplicateDoc(tree)
pushCreate(box, tree.Path, tree.ID, arg)
pushCreate(box, tree.Path, arg)
ret.Data = map[string]interface{}{
"id": tree.Root.ID,
@ -720,7 +696,7 @@ func createDoc(c *gin.Context) {
model.FlushTxQueue()
box := model.Conf.Box(notebook)
pushCreate(box, p, tree.Root.ID, arg)
pushCreate(box, p, arg)
ret.Data = map[string]interface{}{
"id": tree.Root.ID,
@ -856,7 +832,7 @@ func createDocWithMd(c *gin.Context) {
box := model.Conf.Box(notebook)
b, _ := model.GetBlock(id, nil)
p := b.Path
pushCreate(box, p, id, arg)
pushCreate(box, p, arg)
}
func getDocCreateSavePath(c *gin.Context) {
@ -1164,16 +1140,11 @@ func getDoc(c *gin.Context) {
}
}
func pushCreate(box *model.Box, p, treeID string, arg map[string]interface{}) {
func pushCreate(box *model.Box, p string, arg map[string]interface{}) {
evt := util.NewCmdResult("create", 0, util.PushModeBroadcast)
name := path.Base(p)
files, _, _ := model.ListDocTree(box.ID, path.Dir(p), util.SortModeUnassigned, false, false, model.Conf.FileTree.MaxListCount)
evt.Data = map[string]interface{}{
"box": box,
"path": p,
"files": files,
"name": name,
"id": treeID,
"box": box,
"path": p,
}
evt.Callback = arg["callback"]
util.PushEvent(evt)