peer.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package api
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "github.com/gin-gonic/gin/binding"
  5. requstform "github.com/lejianwen/rustdesk-api/http/request/api"
  6. "github.com/lejianwen/rustdesk-api/http/response"
  7. "github.com/lejianwen/rustdesk-api/service"
  8. "net/http"
  9. )
  10. type Peer struct {
  11. }
  12. // SysInfo
  13. // @Tags 地址
  14. // @Summary 提交系统信息
  15. // @Description 提交系统信息
  16. // @Accept json
  17. // @Produce json
  18. // @Param body body requstform.PeerForm true "系统信息表单"
  19. // @Success 200 {string} string "SYSINFO_UPDATED,ID_NOT_FOUND"
  20. // @Failure 500 {object} response.ErrorResponse
  21. // @Router /sysinfo [post]
  22. func (p *Peer) SysInfo(c *gin.Context) {
  23. f := &requstform.PeerForm{}
  24. err := c.ShouldBindBodyWith(f, binding.JSON)
  25. if err != nil {
  26. response.Error(c, response.TranslateMsg(c, "ParamsError")+err.Error())
  27. return
  28. }
  29. fpe := f.ToPeer()
  30. pe := service.AllService.PeerService.FindById(f.Id)
  31. if pe.RowId == 0 {
  32. pe = f.ToPeer()
  33. pe.UserId = service.AllService.UserService.FindLatestUserIdFromLoginLogByUuid(pe.Uuid)
  34. err = service.AllService.PeerService.Create(pe)
  35. if err != nil {
  36. response.Error(c, response.TranslateMsg(c, "OperationFailed")+err.Error())
  37. return
  38. }
  39. } else {
  40. if pe.UserId == 0 {
  41. pe.UserId = service.AllService.UserService.FindLatestUserIdFromLoginLogByUuid(pe.Uuid)
  42. }
  43. fpe.RowId = pe.RowId
  44. fpe.UserId = pe.UserId
  45. err = service.AllService.PeerService.Update(fpe)
  46. if err != nil {
  47. response.Error(c, response.TranslateMsg(c, "OperationFailed")+err.Error())
  48. return
  49. }
  50. }
  51. //SYSINFO_UPDATED 上传成功
  52. //ID_NOT_FOUND 下次心跳会上传
  53. //直接响应文本
  54. c.String(http.StatusOK, "SYSINFO_UPDATED")
  55. }