history.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. "net/http"
  19. "time"
  20. "github.com/88250/gulu"
  21. "github.com/gin-gonic/gin"
  22. "github.com/siyuan-note/siyuan/kernel/model"
  23. "github.com/siyuan-note/siyuan/kernel/util"
  24. )
  25. func getNotebookHistory(c *gin.Context) {
  26. ret := gulu.Ret.NewResult()
  27. defer c.JSON(http.StatusOK, ret)
  28. histories, err := model.GetNotebookHistory()
  29. if nil != err {
  30. ret.Code = -1
  31. ret.Msg = err.Error()
  32. return
  33. }
  34. ret.Data = map[string]interface{}{
  35. "histories": histories,
  36. }
  37. }
  38. func getAssetsHistory(c *gin.Context) {
  39. ret := gulu.Ret.NewResult()
  40. defer c.JSON(http.StatusOK, ret)
  41. histories, err := model.GetAssetsHistory()
  42. if nil != err {
  43. ret.Code = -1
  44. ret.Msg = err.Error()
  45. return
  46. }
  47. ret.Data = map[string]interface{}{
  48. "histories": histories,
  49. }
  50. }
  51. func clearWorkspaceHistory(c *gin.Context) {
  52. ret := gulu.Ret.NewResult()
  53. defer c.JSON(http.StatusOK, ret)
  54. msgId := util.PushMsg(model.Conf.Language(100), 1000*60*15)
  55. time.Sleep(3 * time.Second)
  56. err := model.ClearWorkspaceHistory()
  57. if nil != err {
  58. ret.Code = -1
  59. ret.Msg = err.Error()
  60. return
  61. }
  62. util.PushClearMsg(msgId)
  63. util.PushMsg(model.Conf.Language(99), 1000*5)
  64. }
  65. func getDocHistory(c *gin.Context) {
  66. ret := gulu.Ret.NewResult()
  67. defer c.JSON(http.StatusOK, ret)
  68. arg, ok := util.JsonArg(c, ret)
  69. if !ok {
  70. return
  71. }
  72. notebook := arg["notebook"].(string)
  73. histories, err := model.GetDocHistory(notebook)
  74. if nil != err {
  75. ret.Code = -1
  76. ret.Msg = err.Error()
  77. return
  78. }
  79. ret.Data = map[string]interface{}{
  80. "box": notebook,
  81. "histories": histories,
  82. }
  83. }
  84. func getDocHistoryContent(c *gin.Context) {
  85. ret := gulu.Ret.NewResult()
  86. defer c.JSON(http.StatusOK, ret)
  87. arg, ok := util.JsonArg(c, ret)
  88. if !ok {
  89. return
  90. }
  91. historyPath := arg["historyPath"].(string)
  92. content, err := model.GetDocHistoryContent(historyPath)
  93. if nil != err {
  94. ret.Code = -1
  95. ret.Msg = err.Error()
  96. return
  97. }
  98. ret.Data = map[string]interface{}{
  99. "content": content,
  100. }
  101. }
  102. func rollbackDocHistory(c *gin.Context) {
  103. ret := gulu.Ret.NewResult()
  104. defer c.JSON(http.StatusOK, ret)
  105. arg, ok := util.JsonArg(c, ret)
  106. if !ok {
  107. return
  108. }
  109. notebook := arg["notebook"].(string)
  110. historyPath := arg["historyPath"].(string)
  111. err := model.RollbackDocHistory(notebook, historyPath)
  112. if nil != err {
  113. ret.Code = -1
  114. ret.Msg = err.Error()
  115. return
  116. }
  117. ret.Data = map[string]interface{}{
  118. "box": notebook,
  119. }
  120. }
  121. func rollbackAssetsHistory(c *gin.Context) {
  122. ret := gulu.Ret.NewResult()
  123. defer c.JSON(http.StatusOK, ret)
  124. arg, ok := util.JsonArg(c, ret)
  125. if !ok {
  126. return
  127. }
  128. historyPath := arg["historyPath"].(string)
  129. err := model.RollbackAssetsHistory(historyPath)
  130. if nil != err {
  131. ret.Code = -1
  132. ret.Msg = err.Error()
  133. return
  134. }
  135. }
  136. func rollbackNotebookHistory(c *gin.Context) {
  137. ret := gulu.Ret.NewResult()
  138. defer c.JSON(http.StatusOK, ret)
  139. arg, ok := util.JsonArg(c, ret)
  140. if !ok {
  141. return
  142. }
  143. historyPath := arg["historyPath"].(string)
  144. err := model.RollbackNotebookHistory(historyPath)
  145. if nil != err {
  146. ret.Code = -1
  147. ret.Msg = err.Error()
  148. return
  149. }
  150. }