filetree.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  1. // SiYuan - Build Your Eternal Digital Garden
  2. // Copyright (c) 2020-present, b3log.org
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Affero General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Affero General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Affero General Public License
  15. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. package api
  17. import (
  18. "errors"
  19. "fmt"
  20. "net/http"
  21. "path"
  22. "regexp"
  23. "strings"
  24. "unicode/utf8"
  25. "github.com/88250/gulu"
  26. "github.com/gin-gonic/gin"
  27. "github.com/siyuan-note/filelock"
  28. "github.com/siyuan-note/siyuan/kernel/filesys"
  29. "github.com/siyuan-note/siyuan/kernel/model"
  30. "github.com/siyuan-note/siyuan/kernel/util"
  31. )
  32. func refreshFiletree(c *gin.Context) {
  33. ret := gulu.Ret.NewResult()
  34. defer c.JSON(http.StatusOK, ret)
  35. model.FullReindex()
  36. }
  37. func doc2Heading(c *gin.Context) {
  38. ret := gulu.Ret.NewResult()
  39. defer c.JSON(http.StatusOK, ret)
  40. arg, ok := util.JsonArg(c, ret)
  41. if !ok {
  42. return
  43. }
  44. srcID := arg["srcID"].(string)
  45. targetID := arg["targetID"].(string)
  46. after := arg["after"].(bool)
  47. srcTreeBox, srcTreePath, err := model.Doc2Heading(srcID, targetID, after)
  48. if nil != err {
  49. ret.Code = -1
  50. ret.Msg = err.Error()
  51. ret.Data = map[string]interface{}{"closeTimeout": 5000}
  52. return
  53. }
  54. ret.Data = map[string]interface{}{
  55. "srcTreeBox": srcTreeBox,
  56. "srcTreePath": srcTreePath,
  57. }
  58. }
  59. func heading2Doc(c *gin.Context) {
  60. ret := gulu.Ret.NewResult()
  61. defer c.JSON(http.StatusOK, ret)
  62. arg, ok := util.JsonArg(c, ret)
  63. if !ok {
  64. return
  65. }
  66. srcHeadingID := arg["srcHeadingID"].(string)
  67. targetNotebook := arg["targetNoteBook"].(string)
  68. targetPath := arg["targetPath"].(string)
  69. srcRootBlockID, targetPath, err := model.Heading2Doc(srcHeadingID, targetNotebook, targetPath)
  70. if nil != err {
  71. ret.Code = -1
  72. ret.Msg = err.Error()
  73. ret.Data = map[string]interface{}{"closeTimeout": 5000}
  74. return
  75. }
  76. model.WaitForWritingFiles()
  77. luteEngine := util.NewLute()
  78. tree, err := filesys.LoadTree(targetNotebook, targetPath, luteEngine)
  79. if nil != err {
  80. ret.Code = -1
  81. ret.Msg = err.Error()
  82. return
  83. }
  84. name := path.Base(targetPath)
  85. box := model.Conf.Box(targetNotebook)
  86. files, _, _ := model.ListDocTree(targetNotebook, path.Dir(targetPath), model.Conf.FileTree.Sort)
  87. evt := util.NewCmdResult("heading2doc", 0, util.PushModeBroadcast)
  88. evt.Data = map[string]interface{}{
  89. "box": box,
  90. "path": targetPath,
  91. "files": files,
  92. "name": name,
  93. "id": tree.Root.ID,
  94. "srcRootBlockID": srcRootBlockID,
  95. }
  96. evt.Callback = arg["callback"]
  97. util.PushEvent(evt)
  98. }
  99. func li2Doc(c *gin.Context) {
  100. ret := gulu.Ret.NewResult()
  101. defer c.JSON(http.StatusOK, ret)
  102. arg, ok := util.JsonArg(c, ret)
  103. if !ok {
  104. return
  105. }
  106. srcListItemID := arg["srcListItemID"].(string)
  107. targetNotebook := arg["targetNoteBook"].(string)
  108. targetPath := arg["targetPath"].(string)
  109. srcRootBlockID, targetPath, err := model.ListItem2Doc(srcListItemID, targetNotebook, targetPath)
  110. if nil != err {
  111. ret.Code = -1
  112. ret.Msg = err.Error()
  113. ret.Data = map[string]interface{}{"closeTimeout": 5000}
  114. return
  115. }
  116. model.WaitForWritingFiles()
  117. luteEngine := util.NewLute()
  118. tree, err := filesys.LoadTree(targetNotebook, targetPath, luteEngine)
  119. if nil != err {
  120. ret.Code = -1
  121. ret.Msg = err.Error()
  122. return
  123. }
  124. name := path.Base(targetPath)
  125. box := model.Conf.Box(targetNotebook)
  126. files, _, _ := model.ListDocTree(targetNotebook, path.Dir(targetPath), model.Conf.FileTree.Sort)
  127. evt := util.NewCmdResult("li2doc", 0, util.PushModeBroadcast)
  128. evt.Data = map[string]interface{}{
  129. "box": box,
  130. "path": targetPath,
  131. "files": files,
  132. "name": name,
  133. "id": tree.Root.ID,
  134. "srcRootBlockID": srcRootBlockID,
  135. }
  136. evt.Callback = arg["callback"]
  137. util.PushEvent(evt)
  138. }
  139. func getHPathByPath(c *gin.Context) {
  140. ret := gulu.Ret.NewResult()
  141. defer c.JSON(http.StatusOK, ret)
  142. arg, ok := util.JsonArg(c, ret)
  143. if !ok {
  144. return
  145. }
  146. notebook := arg["notebook"].(string)
  147. if util.InvalidIDPattern(notebook, ret) {
  148. return
  149. }
  150. p := arg["path"].(string)
  151. hPath, err := model.GetHPathByPath(notebook, p)
  152. if nil != err {
  153. ret.Code = -1
  154. ret.Msg = err.Error()
  155. return
  156. }
  157. ret.Data = hPath
  158. }
  159. func getHPathsByPaths(c *gin.Context) {
  160. ret := gulu.Ret.NewResult()
  161. defer c.JSON(http.StatusOK, ret)
  162. arg, ok := util.JsonArg(c, ret)
  163. if !ok {
  164. return
  165. }
  166. pathsArg := arg["paths"].([]interface{})
  167. var paths []string
  168. for _, p := range pathsArg {
  169. paths = append(paths, p.(string))
  170. }
  171. hPath, err := model.GetHPathsByPaths(paths)
  172. if nil != err {
  173. ret.Code = -1
  174. ret.Msg = err.Error()
  175. return
  176. }
  177. ret.Data = hPath
  178. }
  179. func getHPathByID(c *gin.Context) {
  180. ret := gulu.Ret.NewResult()
  181. defer c.JSON(http.StatusOK, ret)
  182. arg, ok := util.JsonArg(c, ret)
  183. if !ok {
  184. return
  185. }
  186. id := arg["id"].(string)
  187. if util.InvalidIDPattern(id, ret) {
  188. return
  189. }
  190. hPath, err := model.GetHPathByID(id)
  191. if nil != err {
  192. ret.Code = -1
  193. ret.Msg = err.Error()
  194. return
  195. }
  196. ret.Data = hPath
  197. }
  198. func getFullHPathByID(c *gin.Context) {
  199. ret := gulu.Ret.NewResult()
  200. defer c.JSON(http.StatusOK, ret)
  201. arg, ok := util.JsonArg(c, ret)
  202. if !ok {
  203. return
  204. }
  205. if nil == arg["id"] {
  206. return
  207. }
  208. id := arg["id"].(string)
  209. hPath, err := model.GetFullHPathByID(id)
  210. if nil != err {
  211. ret.Code = -1
  212. ret.Msg = err.Error()
  213. return
  214. }
  215. ret.Data = hPath
  216. }
  217. func moveDocs(c *gin.Context) {
  218. ret := gulu.Ret.NewResult()
  219. defer c.JSON(http.StatusOK, ret)
  220. arg, ok := util.JsonArg(c, ret)
  221. if !ok {
  222. return
  223. }
  224. var fromPaths []string
  225. fromPathsArg := arg["fromPaths"].([]interface{})
  226. for _, fromPath := range fromPathsArg {
  227. fromPaths = append(fromPaths, fromPath.(string))
  228. }
  229. toPath := arg["toPath"].(string)
  230. toNotebook := arg["toNotebook"].(string)
  231. if util.InvalidIDPattern(toNotebook, ret) {
  232. return
  233. }
  234. err := model.MoveDocs(fromPaths, toNotebook, toPath)
  235. if nil != err {
  236. ret.Code = -1
  237. ret.Msg = err.Error()
  238. ret.Data = map[string]interface{}{"closeTimeout": 7000}
  239. return
  240. }
  241. }
  242. func removeDoc(c *gin.Context) {
  243. ret := gulu.Ret.NewResult()
  244. defer c.JSON(http.StatusOK, ret)
  245. arg, ok := util.JsonArg(c, ret)
  246. if !ok {
  247. return
  248. }
  249. notebook := arg["notebook"].(string)
  250. if util.InvalidIDPattern(notebook, ret) {
  251. return
  252. }
  253. p := arg["path"].(string)
  254. model.RemoveDoc(notebook, p)
  255. }
  256. func removeDocs(c *gin.Context) {
  257. ret := gulu.Ret.NewResult()
  258. defer c.JSON(http.StatusOK, ret)
  259. arg, ok := util.JsonArg(c, ret)
  260. if !ok {
  261. return
  262. }
  263. pathsArg := arg["paths"].([]interface{})
  264. var paths []string
  265. for _, path := range pathsArg {
  266. paths = append(paths, path.(string))
  267. }
  268. model.RemoveDocs(paths)
  269. }
  270. func renameDoc(c *gin.Context) {
  271. ret := gulu.Ret.NewResult()
  272. defer c.JSON(http.StatusOK, ret)
  273. arg, ok := util.JsonArg(c, ret)
  274. if !ok {
  275. return
  276. }
  277. notebook := arg["notebook"].(string)
  278. if util.InvalidIDPattern(notebook, ret) {
  279. return
  280. }
  281. p := arg["path"].(string)
  282. title := arg["title"].(string)
  283. err := model.RenameDoc(notebook, p, title)
  284. if nil != err {
  285. ret.Code = -1
  286. ret.Msg = err.Error()
  287. return
  288. }
  289. return
  290. }
  291. func duplicateDoc(c *gin.Context) {
  292. ret := gulu.Ret.NewResult()
  293. defer c.JSON(http.StatusOK, ret)
  294. arg, ok := util.JsonArg(c, ret)
  295. if !ok {
  296. return
  297. }
  298. id := arg["id"].(string)
  299. tree, err := model.LoadTreeByID(id)
  300. if nil != err {
  301. ret.Code = -1
  302. ret.Msg = err.Error()
  303. ret.Data = map[string]interface{}{"closeTimeout": 7000}
  304. return
  305. }
  306. p := tree.Path
  307. notebook := tree.Box
  308. box := model.Conf.Box(notebook)
  309. model.DuplicateDoc(tree)
  310. pushCreate(box, p, tree.Root.ID, arg)
  311. ret.Data = map[string]interface{}{
  312. "id": tree.Root.ID,
  313. "notebook": notebook,
  314. "path": tree.Path,
  315. "hPath": tree.HPath,
  316. }
  317. }
  318. func createDoc(c *gin.Context) {
  319. ret := gulu.Ret.NewResult()
  320. defer c.JSON(http.StatusOK, ret)
  321. arg, ok := util.JsonArg(c, ret)
  322. if !ok {
  323. return
  324. }
  325. notebook := arg["notebook"].(string)
  326. p := arg["path"].(string)
  327. title := arg["title"].(string)
  328. md := arg["md"].(string)
  329. sortsArg := arg["sorts"]
  330. var sorts []string
  331. if nil != sortsArg {
  332. for _, sort := range sortsArg.([]interface{}) {
  333. sorts = append(sorts, sort.(string))
  334. }
  335. }
  336. tree, err := model.CreateDocByMd(notebook, p, title, md, sorts)
  337. if nil != err {
  338. ret.Code = -1
  339. ret.Msg = err.Error()
  340. ret.Data = map[string]interface{}{"closeTimeout": 7000}
  341. return
  342. }
  343. box := model.Conf.Box(notebook)
  344. pushCreate(box, p, tree.Root.ID, arg)
  345. }
  346. func createDailyNote(c *gin.Context) {
  347. ret := gulu.Ret.NewResult()
  348. defer c.JSON(http.StatusOK, ret)
  349. arg, ok := util.JsonArg(c, ret)
  350. if !ok {
  351. return
  352. }
  353. notebook := arg["notebook"].(string)
  354. p, existed, err := model.CreateDailyNote(notebook)
  355. if nil != err {
  356. if model.ErrBoxNotFound == err {
  357. ret.Code = 1
  358. } else {
  359. ret.Code = -1
  360. }
  361. ret.Msg = err.Error()
  362. return
  363. }
  364. box := model.Conf.Box(notebook)
  365. model.WaitForWritingFiles()
  366. luteEngine := util.NewLute()
  367. tree, err := filesys.LoadTree(box.ID, p, luteEngine)
  368. if nil != err {
  369. ret.Code = -1
  370. ret.Msg = err.Error()
  371. return
  372. }
  373. appArg := arg["app"]
  374. app := ""
  375. if nil != appArg {
  376. app = appArg.(string)
  377. }
  378. pushMode := util.PushModeBroadcast
  379. if existed && "" != app {
  380. pushMode = util.PushModeBroadcastApp
  381. }
  382. evt := util.NewCmdResult("createdailynote", 0, pushMode)
  383. evt.AppId = app
  384. name := path.Base(p)
  385. files, _, _ := model.ListDocTree(box.ID, path.Dir(p), model.Conf.FileTree.Sort)
  386. evt.Data = map[string]interface{}{
  387. "box": box,
  388. "path": p,
  389. "files": files,
  390. "name": name,
  391. "id": tree.Root.ID,
  392. }
  393. evt.Callback = arg["callback"]
  394. util.PushEvent(evt)
  395. }
  396. func createDocWithMd(c *gin.Context) {
  397. ret := gulu.Ret.NewResult()
  398. defer c.JSON(http.StatusOK, ret)
  399. arg, ok := util.JsonArg(c, ret)
  400. if !ok {
  401. return
  402. }
  403. notebook := arg["notebook"].(string)
  404. if util.InvalidIDPattern(notebook, ret) {
  405. return
  406. }
  407. hPath := arg["path"].(string)
  408. markdown := arg["markdown"].(string)
  409. baseName := path.Base(hPath)
  410. dir := path.Dir(hPath)
  411. r, _ := regexp.Compile("\r\n|\r|\n|\u2028|\u2029|\t|/")
  412. baseName = r.ReplaceAllString(baseName, "")
  413. if 512 < utf8.RuneCountInString(baseName) {
  414. baseName = gulu.Str.SubStr(baseName, 512)
  415. }
  416. hPath = path.Join(dir, baseName)
  417. if !strings.HasPrefix(hPath, "/") {
  418. hPath = "/" + hPath
  419. }
  420. id, err := model.CreateWithMarkdown(notebook, hPath, markdown)
  421. if nil != err {
  422. ret.Code = -1
  423. ret.Msg = err.Error()
  424. return
  425. }
  426. ret.Data = id
  427. box := model.Conf.Box(notebook)
  428. b, _ := model.GetBlock(id, nil)
  429. p := b.Path
  430. pushCreate(box, p, id, arg)
  431. }
  432. func lockFile(c *gin.Context) {
  433. ret := gulu.Ret.NewResult()
  434. defer c.JSON(http.StatusOK, ret)
  435. arg, ok := util.JsonArg(c, ret)
  436. if !ok {
  437. return
  438. }
  439. id := arg["id"].(string)
  440. locked := model.TryAccessFileByBlockID(id)
  441. if !locked {
  442. ret.Code = -1
  443. ret.Msg = fmt.Sprintf(model.Conf.Language(75))
  444. ret.Data = map[string]interface{}{"closeTimeout": 5000}
  445. }
  446. }
  447. func getDocCreateSavePath(c *gin.Context) {
  448. ret := gulu.Ret.NewResult()
  449. defer c.JSON(http.StatusOK, ret)
  450. arg, ok := util.JsonArg(c, ret)
  451. if !ok {
  452. return
  453. }
  454. notebook := arg["notebook"].(string)
  455. box := model.Conf.Box(notebook)
  456. docCreateSavePathTpl := model.Conf.FileTree.DocCreateSavePath
  457. if nil != box {
  458. docCreateSavePathTpl = box.GetConf().DocCreateSavePath
  459. }
  460. if "" == docCreateSavePathTpl {
  461. docCreateSavePathTpl = model.Conf.FileTree.DocCreateSavePath
  462. }
  463. p, err := model.RenderGoTemplate(docCreateSavePathTpl)
  464. if nil != err {
  465. ret.Code = -1
  466. ret.Msg = err.Error()
  467. return
  468. }
  469. ret.Data = map[string]interface{}{
  470. "path": p,
  471. }
  472. }
  473. func getRefCreateSavePath(c *gin.Context) {
  474. ret := gulu.Ret.NewResult()
  475. defer c.JSON(http.StatusOK, ret)
  476. arg, ok := util.JsonArg(c, ret)
  477. if !ok {
  478. return
  479. }
  480. notebook := arg["notebook"].(string)
  481. box := model.Conf.Box(notebook)
  482. refCreateSavePath := model.Conf.FileTree.RefCreateSavePath
  483. if nil != box {
  484. refCreateSavePath = box.GetConf().RefCreateSavePath
  485. }
  486. if "" == refCreateSavePath {
  487. refCreateSavePath = model.Conf.FileTree.RefCreateSavePath
  488. }
  489. p, err := model.RenderGoTemplate(refCreateSavePath)
  490. if nil != err {
  491. ret.Code = -1
  492. ret.Msg = err.Error()
  493. return
  494. }
  495. ret.Data = map[string]interface{}{
  496. "path": p,
  497. }
  498. }
  499. func changeSort(c *gin.Context) {
  500. ret := gulu.Ret.NewResult()
  501. defer c.JSON(http.StatusOK, ret)
  502. arg, ok := util.JsonArg(c, ret)
  503. if !ok {
  504. return
  505. }
  506. notebook := arg["notebook"].(string)
  507. pathsArg := arg["paths"].([]interface{})
  508. var paths []string
  509. for _, p := range pathsArg {
  510. paths = append(paths, p.(string))
  511. }
  512. model.ChangeFileTreeSort(notebook, paths)
  513. }
  514. func searchDocs(c *gin.Context) {
  515. ret := gulu.Ret.NewResult()
  516. defer c.JSON(http.StatusOK, ret)
  517. arg, ok := util.JsonArg(c, ret)
  518. if !ok {
  519. return
  520. }
  521. k := arg["k"].(string)
  522. ret.Data = model.SearchDocsByKeyword(k)
  523. }
  524. func listDocsByPath(c *gin.Context) {
  525. ret := gulu.Ret.NewResult()
  526. defer c.JSON(http.StatusOK, ret)
  527. arg, ok := util.JsonArg(c, ret)
  528. if !ok {
  529. return
  530. }
  531. notebook := arg["notebook"].(string)
  532. p := arg["path"].(string)
  533. sortParam := arg["sort"]
  534. sortMode := model.Conf.FileTree.Sort
  535. if nil != sortParam {
  536. sortMode = int(sortParam.(float64))
  537. }
  538. files, totals, err := model.ListDocTree(notebook, p, sortMode)
  539. if nil != err {
  540. ret.Code = -1
  541. ret.Msg = err.Error()
  542. return
  543. }
  544. if model.Conf.FileTree.MaxListCount < totals {
  545. util.PushMsg(fmt.Sprintf(model.Conf.Language(48), len(files)), 7000)
  546. }
  547. ret.Data = map[string]interface{}{
  548. "box": notebook,
  549. "path": p,
  550. "files": files,
  551. }
  552. }
  553. func getDoc(c *gin.Context) {
  554. ret := gulu.Ret.NewResult()
  555. defer c.JSON(http.StatusOK, ret)
  556. arg, ok := util.JsonArg(c, ret)
  557. if !ok {
  558. return
  559. }
  560. id := arg["id"].(string)
  561. idx := arg["index"]
  562. index := 0
  563. if nil != idx {
  564. index = int(idx.(float64))
  565. }
  566. k := arg["k"]
  567. var keyword string
  568. if nil != k {
  569. keyword = k.(string)
  570. }
  571. m := arg["mode"] // 0: 仅当前 ID,1:向上 2:向下,3:上下都加载,4:加载末尾
  572. mode := 0
  573. if nil != m {
  574. mode = int(m.(float64))
  575. }
  576. s := arg["size"]
  577. size := 102400 // 默认最大加载块数
  578. if nil != s {
  579. size = int(s.(float64))
  580. }
  581. startID := ""
  582. endID := ""
  583. startIDArg := arg["startID"]
  584. endIDArg := arg["endID"]
  585. if nil != startIDArg && nil != endIDArg {
  586. startID = startIDArg.(string)
  587. endID = endIDArg.(string)
  588. size = 36
  589. }
  590. isBacklinkArg := arg["isBacklink"]
  591. isBacklink := false
  592. if nil != isBacklinkArg {
  593. isBacklink = isBacklinkArg.(bool)
  594. }
  595. blockCount, content, parentID, parent2ID, rootID, typ, eof, scroll, boxID, docPath, isBacklinkExpand, err := model.GetDoc(startID, endID, id, index, keyword, mode, size, isBacklink)
  596. if errors.Is(err, filelock.ErrUnableAccessFile) {
  597. ret.Code = 2
  598. ret.Data = id
  599. return
  600. }
  601. if model.ErrBlockNotFound == err {
  602. ret.Code = 3
  603. return
  604. }
  605. if nil != err {
  606. ret.Code = 1
  607. ret.Msg = err.Error()
  608. return
  609. }
  610. // 判断是否正在同步中 https://github.com/siyuan-note/siyuan/issues/6290
  611. isSyncing := model.IsSyncingFile(rootID)
  612. ret.Data = map[string]interface{}{
  613. "id": id,
  614. "mode": mode,
  615. "parentID": parentID,
  616. "parent2ID": parent2ID,
  617. "rootID": rootID,
  618. "type": typ,
  619. "content": content,
  620. "blockCount": blockCount,
  621. "eof": eof,
  622. "scroll": scroll,
  623. "box": boxID,
  624. "path": docPath,
  625. "isSyncing": isSyncing,
  626. "isBacklinkExpand": isBacklinkExpand,
  627. }
  628. }
  629. func pushCreate(box *model.Box, p, treeID string, arg map[string]interface{}) {
  630. evt := util.NewCmdResult("create", 0, util.PushModeBroadcast)
  631. name := path.Base(p)
  632. files, _, _ := model.ListDocTree(box.ID, path.Dir(p), model.Conf.FileTree.Sort)
  633. evt.Data = map[string]interface{}{
  634. "box": box,
  635. "path": p,
  636. "files": files,
  637. "name": name,
  638. "id": treeID,
  639. }
  640. evt.Callback = arg["callback"]
  641. util.PushEvent(evt)
  642. }