repo.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. "encoding/hex"
  19. "net/http"
  20. "time"
  21. "github.com/88250/gulu"
  22. "github.com/gin-gonic/gin"
  23. "github.com/siyuan-note/siyuan/kernel/model"
  24. "github.com/siyuan-note/siyuan/kernel/util"
  25. )
  26. func getRepoIndexLogs(c *gin.Context) {
  27. ret := gulu.Ret.NewResult()
  28. defer c.JSON(http.StatusOK, ret)
  29. arg, ok := util.JsonArg(c, ret)
  30. if !ok {
  31. return
  32. }
  33. page := arg["page"].(float64)
  34. logs, err := model.GetRepoIndexLogs(int(page))
  35. if nil != err {
  36. ret.Code = -1
  37. ret.Msg = err.Error()
  38. return
  39. }
  40. ret.Data = map[string]interface{}{
  41. "logs": logs,
  42. }
  43. }
  44. func indexRepo(c *gin.Context) {
  45. ret := gulu.Ret.NewResult()
  46. defer c.JSON(http.StatusOK, ret)
  47. arg, ok := util.JsonArg(c, ret)
  48. if !ok {
  49. return
  50. }
  51. message := arg["message"].(string)
  52. if err := model.IndexRepo(message); nil != err {
  53. ret.Code = -1
  54. ret.Msg = model.Conf.Language(137)
  55. return
  56. }
  57. }
  58. func importRepoKey(c *gin.Context) {
  59. ret := gulu.Ret.NewResult()
  60. defer c.JSON(http.StatusOK, ret)
  61. arg, ok := util.JsonArg(c, ret)
  62. if !ok {
  63. return
  64. }
  65. msgId := util.PushMsg(model.Conf.Language(136), 1000*7)
  66. hexKey := arg["key"].(string)
  67. if err := model.ImportRepoKey(hexKey); nil != err {
  68. ret.Code = -1
  69. ret.Msg = model.Conf.Language(137)
  70. return
  71. }
  72. time.Sleep(1 * time.Second)
  73. util.PushUpdateMsg(msgId, model.Conf.Language(138), 3000)
  74. }
  75. func initRepoKey(c *gin.Context) {
  76. ret := gulu.Ret.NewResult()
  77. defer c.JSON(http.StatusOK, ret)
  78. msgId := util.PushMsg(model.Conf.Language(136), 1000*7)
  79. if err := model.InitRepoKey(); nil != err {
  80. ret.Code = -1
  81. ret.Msg = model.Conf.Language(137)
  82. return
  83. }
  84. time.Sleep(1 * time.Second)
  85. util.PushUpdateMsg(msgId, model.Conf.Language(138), 3000)
  86. ret.Data = map[string]interface{}{
  87. "key": hex.EncodeToString(model.Conf.Repo.Key),
  88. }
  89. }