repo.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. "fmt"
  19. "net/http"
  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 checkoutRepo(c *gin.Context) {
  26. ret := gulu.Ret.NewResult()
  27. defer c.JSON(http.StatusOK, ret)
  28. arg, ok := util.JsonArg(c, ret)
  29. if !ok {
  30. return
  31. }
  32. id := arg["id"].(string)
  33. if err := model.CheckoutRepo(id); nil != err {
  34. ret.Code = -1
  35. ret.Msg = model.Conf.Language(141)
  36. return
  37. }
  38. }
  39. func getRepoIndexLogs(c *gin.Context) {
  40. ret := gulu.Ret.NewResult()
  41. defer c.JSON(http.StatusOK, ret)
  42. arg, ok := util.JsonArg(c, ret)
  43. if !ok {
  44. return
  45. }
  46. page := arg["page"].(float64)
  47. logs, pageCount, totalCount, err := model.GetRepoIndexLogs(int(page))
  48. if nil != err {
  49. ret.Code = -1
  50. ret.Msg = err.Error()
  51. return
  52. }
  53. ret.Data = map[string]interface{}{
  54. "logs": logs,
  55. "pageCount": pageCount,
  56. "totalCount": totalCount,
  57. }
  58. }
  59. func indexRepo(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. message := arg["message"].(string)
  67. if err := model.IndexRepo(message); nil != err {
  68. ret.Code = -1
  69. ret.Msg = fmt.Sprintf(model.Conf.Language(140), err)
  70. ret.Data = map[string]interface{}{"closeTimeout": 5000}
  71. return
  72. }
  73. }
  74. func importRepoKey(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. base64Key := arg["key"].(string)
  82. if err := model.ImportRepoKey(base64Key); nil != err {
  83. ret.Code = -1
  84. ret.Msg = model.Conf.Language(137)
  85. return
  86. }
  87. }
  88. func initRepoKey(c *gin.Context) {
  89. ret := gulu.Ret.NewResult()
  90. defer c.JSON(http.StatusOK, ret)
  91. if err := model.InitRepoKey(); nil != err {
  92. ret.Code = -1
  93. ret.Msg = model.Conf.Language(137)
  94. return
  95. }
  96. ret.Data = map[string]interface{}{
  97. "key": model.Conf.Repo.Key,
  98. }
  99. }
  100. func resetRepo(c *gin.Context) {
  101. ret := gulu.Ret.NewResult()
  102. defer c.JSON(http.StatusOK, ret)
  103. if err := model.ResetRepo(); nil != err {
  104. ret.Code = -1
  105. ret.Msg = fmt.Sprintf(model.Conf.Language(146), err.Error())
  106. return
  107. }
  108. }