index.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package api
  2. import (
  3. "github.com/gin-gonic/gin"
  4. requstform "github.com/lejianwen/rustdesk-api/v2/http/request/api"
  5. "github.com/lejianwen/rustdesk-api/v2/http/response"
  6. "github.com/lejianwen/rustdesk-api/v2/model"
  7. "github.com/lejianwen/rustdesk-api/v2/service"
  8. "net/http"
  9. "time"
  10. )
  11. type Index struct {
  12. }
  13. // Index 首页
  14. // @Tags 首页
  15. // @Summary 首页
  16. // @Description 首页
  17. // @Accept json
  18. // @Produce json
  19. // @Success 200 {object} response.Response
  20. // @Failure 500 {object} response.Response
  21. // @Router / [get]
  22. func (i *Index) Index(c *gin.Context) {
  23. response.Success(
  24. c,
  25. "Hello Gwen",
  26. )
  27. }
  28. // Heartbeat 心跳
  29. // @Tags 首页
  30. // @Summary 心跳
  31. // @Description 心跳
  32. // @Accept json
  33. // @Produce json
  34. // @Success 200 {object} nil
  35. // @Failure 500 {object} response.Response
  36. // @Router /heartbeat [post]
  37. func (i *Index) Heartbeat(c *gin.Context) {
  38. info := &requstform.PeerInfoInHeartbeat{}
  39. err := c.ShouldBindJSON(info)
  40. if err != nil {
  41. c.JSON(http.StatusOK, gin.H{})
  42. return
  43. }
  44. if info.Uuid == "" {
  45. c.JSON(http.StatusOK, gin.H{})
  46. return
  47. }
  48. peer := service.AllService.PeerService.FindById(info.Id)
  49. if peer == nil || peer.RowId == 0 {
  50. c.JSON(http.StatusOK, gin.H{})
  51. return
  52. }
  53. //如果在40s以内则不更新
  54. if time.Now().Unix()-peer.LastOnlineTime >= 30 {
  55. upp := &model.Peer{RowId: peer.RowId, LastOnlineTime: time.Now().Unix(), LastOnlineIp: c.ClientIP()}
  56. service.AllService.PeerService.Update(upp)
  57. }
  58. c.JSON(http.StatusOK, gin.H{})
  59. }
  60. // Version 版本
  61. // @Tags 首页
  62. // @Summary 版本
  63. // @Description 版本
  64. // @Accept json
  65. // @Produce json
  66. // @Success 200 {object} response.Response
  67. // @Failure 500 {object} response.Response
  68. // @Router /version [get]
  69. func (i *Index) Version(c *gin.Context) {
  70. //读取resources/version文件
  71. v := service.AllService.AppService.GetAppVersion()
  72. response.Success(
  73. c,
  74. v,
  75. )
  76. }