peer.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package api
  2. import (
  3. "fmt"
  4. "github.com/gin-gonic/gin"
  5. "github.com/gin-gonic/gin/binding"
  6. requstform "github.com/lejianwen/rustdesk-api/v2/http/request/api"
  7. "github.com/lejianwen/rustdesk-api/v2/http/response"
  8. "github.com/lejianwen/rustdesk-api/v2/service"
  9. "net/http"
  10. )
  11. type Peer struct {
  12. }
  13. // SysInfo
  14. // @Tags System
  15. // @Summary 提交系统信息
  16. // @Description 提交系统信息
  17. // @Accept json
  18. // @Produce json
  19. // @Param body body requstform.PeerForm true "系统信息表单"
  20. // @Success 200 {string} string "SYSINFO_UPDATED,ID_NOT_FOUND"
  21. // @Failure 500 {object} response.ErrorResponse
  22. // @Router /sysinfo [post]
  23. func (p *Peer) SysInfo(c *gin.Context) {
  24. f := &requstform.PeerForm{}
  25. err := c.ShouldBindBodyWith(f, binding.JSON)
  26. if err != nil {
  27. response.Error(c, response.TranslateMsg(c, "ParamsError")+err.Error())
  28. return
  29. }
  30. fpe := f.ToPeer()
  31. pe := service.AllService.PeerService.FindById(f.Id)
  32. if pe.RowId == 0 {
  33. pe = f.ToPeer()
  34. pe.UserId = service.AllService.UserService.FindLatestUserIdFromLoginLogByUuid(pe.Uuid, pe.Id)
  35. err = service.AllService.PeerService.Create(pe)
  36. if err != nil {
  37. response.Error(c, response.TranslateMsg(c, "OperationFailed")+err.Error())
  38. return
  39. }
  40. } else {
  41. if pe.UserId == 0 {
  42. pe.UserId = service.AllService.UserService.FindLatestUserIdFromLoginLogByUuid(pe.Uuid, pe.Id)
  43. }
  44. fpe.RowId = pe.RowId
  45. fpe.UserId = pe.UserId
  46. err = service.AllService.PeerService.Update(fpe)
  47. if err != nil {
  48. response.Error(c, response.TranslateMsg(c, "OperationFailed")+err.Error())
  49. return
  50. }
  51. }
  52. //SYSINFO_UPDATED 上传成功
  53. //ID_NOT_FOUND 下次心跳会上传
  54. //直接响应文本
  55. c.String(http.StatusOK, "SYSINFO_UPDATED")
  56. }
  57. // SysInfoVer
  58. // @Tags System
  59. // @Summary 获取系统版本信息
  60. // @Description 获取系统版本信息
  61. // @Accept json
  62. // @Produce json
  63. // @Success 200 {string} string ""
  64. // @Failure 500 {object} response.ErrorResponse
  65. // @Router /sysinfo_ver [post]
  66. func (p *Peer) SysInfoVer(c *gin.Context) {
  67. //读取resources/version文件
  68. v := service.AllService.AppService.GetAppVersion()
  69. // 加上启动时间,方便client上传信息
  70. v = fmt.Sprintf("%s\n%s", v, service.AllService.AppService.GetStartTime())
  71. c.String(http.StatusOK, v)
  72. }