filetree.go 16 KB

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