repo.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. "os"
  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 indexRepo(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. message := arg["message"].(string)
  34. if err := model.IndexRepo(message); nil != err {
  35. ret.Code = -1
  36. ret.Msg = model.Conf.Language(137)
  37. return
  38. }
  39. }
  40. func initRepoKey(c *gin.Context) {
  41. ret := gulu.Ret.NewResult()
  42. defer c.JSON(http.StatusOK, ret)
  43. util.PushMsg(model.Conf.Language(136), 1000*7)
  44. if err := os.RemoveAll(model.Conf.Repo.GetSaveDir()); nil != err {
  45. ret.Code = -1
  46. ret.Msg = err.Error()
  47. return
  48. }
  49. if err := os.MkdirAll(model.Conf.Repo.GetSaveDir(), 0755); nil != err {
  50. ret.Code = -1
  51. ret.Msg = err.Error()
  52. return
  53. }
  54. if err := model.InitRepoKey(); nil != err {
  55. ret.Code = -1
  56. ret.Msg = model.Conf.Language(137)
  57. return
  58. }
  59. time.Sleep(1 * time.Second)
  60. util.PushMsg(model.Conf.Language(138), 3000)
  61. }