2024-09-13 15:57:29 +08:00
|
|
|
package api
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/gin-gonic/gin"
|
2025-02-12 19:46:39 +08:00
|
|
|
requstform "github.com/lejianwen/rustdesk-api/v2/http/request/api"
|
|
|
|
|
"github.com/lejianwen/rustdesk-api/v2/http/response"
|
|
|
|
|
"github.com/lejianwen/rustdesk-api/v2/model"
|
|
|
|
|
"github.com/lejianwen/rustdesk-api/v2/service"
|
2024-09-13 15:57:29 +08:00
|
|
|
"net/http"
|
2024-09-29 11:53:58 +08:00
|
|
|
"time"
|
2024-09-13 15:57:29 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Index struct {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Index 首页
|
|
|
|
|
// @Tags 首页
|
|
|
|
|
// @Summary 首页
|
|
|
|
|
// @Description 首页
|
|
|
|
|
// @Accept json
|
|
|
|
|
// @Produce json
|
|
|
|
|
// @Success 200 {object} response.Response
|
|
|
|
|
// @Failure 500 {object} response.Response
|
|
|
|
|
// @Router / [get]
|
|
|
|
|
func (i *Index) Index(c *gin.Context) {
|
|
|
|
|
response.Success(
|
|
|
|
|
c,
|
|
|
|
|
"Hello Gwen",
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Heartbeat 心跳
|
|
|
|
|
// @Tags 首页
|
|
|
|
|
// @Summary 心跳
|
|
|
|
|
// @Description 心跳
|
|
|
|
|
// @Accept json
|
|
|
|
|
// @Produce json
|
|
|
|
|
// @Success 200 {object} nil
|
|
|
|
|
// @Failure 500 {object} response.Response
|
|
|
|
|
// @Router /heartbeat [post]
|
|
|
|
|
func (i *Index) Heartbeat(c *gin.Context) {
|
2024-09-29 11:53:58 +08:00
|
|
|
info := &requstform.PeerInfoInHeartbeat{}
|
|
|
|
|
err := c.ShouldBindJSON(info)
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.JSON(http.StatusOK, gin.H{})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if info.Uuid == "" {
|
|
|
|
|
c.JSON(http.StatusOK, gin.H{})
|
|
|
|
|
return
|
|
|
|
|
}
|
2025-08-31 12:46:54 +08:00
|
|
|
peer := service.AllService.PeerService.FindById(info.Id)
|
2024-10-28 14:19:30 +08:00
|
|
|
if peer == nil || peer.RowId == 0 {
|
2024-09-29 11:53:58 +08:00
|
|
|
c.JSON(http.StatusOK, gin.H{})
|
|
|
|
|
return
|
|
|
|
|
}
|
2024-10-28 20:24:34 +08:00
|
|
|
//如果在40s以内则不更新
|
2025-03-15 21:02:08 +08:00
|
|
|
if time.Now().Unix()-peer.LastOnlineTime >= 30 {
|
2024-10-28 20:24:34 +08:00
|
|
|
upp := &model.Peer{RowId: peer.RowId, LastOnlineTime: time.Now().Unix(), LastOnlineIp: c.ClientIP()}
|
2024-10-16 21:32:55 +08:00
|
|
|
service.AllService.PeerService.Update(upp)
|
|
|
|
|
}
|
2024-09-13 15:57:29 +08:00
|
|
|
c.JSON(http.StatusOK, gin.H{})
|
|
|
|
|
}
|
2025-01-20 20:04:22 +08:00
|
|
|
|
|
|
|
|
// Version 版本
|
|
|
|
|
// @Tags 首页
|
|
|
|
|
// @Summary 版本
|
|
|
|
|
// @Description 版本
|
|
|
|
|
// @Accept json
|
|
|
|
|
// @Produce json
|
|
|
|
|
// @Success 200 {object} response.Response
|
|
|
|
|
// @Failure 500 {object} response.Response
|
|
|
|
|
// @Router /version [get]
|
|
|
|
|
func (i *Index) Version(c *gin.Context) {
|
|
|
|
|
//读取resources/version文件
|
2025-04-07 16:38:21 +08:00
|
|
|
v := service.AllService.AppService.GetAppVersion()
|
2025-01-20 20:04:22 +08:00
|
|
|
response.Success(
|
|
|
|
|
c,
|
2025-04-07 16:38:21 +08:00
|
|
|
v,
|
2025-01-20 20:04:22 +08:00
|
|
|
)
|
|
|
|
|
}
|