notification.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // SiYuan - Refactor your thinking
  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. "strings"
  20. "github.com/88250/gulu"
  21. "github.com/gin-gonic/gin"
  22. "github.com/siyuan-note/siyuan/kernel/util"
  23. )
  24. func pushMsg(c *gin.Context) {
  25. ret := gulu.Ret.NewResult()
  26. defer c.JSON(http.StatusOK, ret)
  27. arg, ok := util.JsonArg(c, ret)
  28. if !ok {
  29. return
  30. }
  31. msg := strings.TrimSpace(arg["msg"].(string))
  32. if "" == msg {
  33. ret.Code = -1
  34. ret.Msg = "msg can't be empty"
  35. return
  36. }
  37. timeout := 7000
  38. if nil != arg["timeout"] {
  39. timeout = int(arg["timeout"].(float64))
  40. }
  41. msgId := util.PushMsg(msg, timeout)
  42. ret.Data = map[string]interface{}{
  43. "id": msgId,
  44. }
  45. }
  46. func pushErrMsg(c *gin.Context) {
  47. ret := gulu.Ret.NewResult()
  48. defer c.JSON(http.StatusOK, ret)
  49. arg, ok := util.JsonArg(c, ret)
  50. if !ok {
  51. return
  52. }
  53. msg := arg["msg"].(string)
  54. timeout := 7000
  55. if nil != arg["timeout"] {
  56. timeout = int(arg["timeout"].(float64))
  57. }
  58. msgId := util.PushErrMsg(msg, timeout)
  59. ret.Data = map[string]interface{}{
  60. "id": msgId,
  61. }
  62. }