From 991fc86fa679c99a837f4d0b3d3d48933a7368d8 Mon Sep 17 00:00:00 2001 From: ljw <84855512@qq.com> Date: Mon, 28 Oct 2024 20:24:34 +0800 Subject: [PATCH] add last online ip #24 --- cmd/apimain.go | 2 +- http/controller/api/index.go | 7 +++---- model/peer.go | 1 + 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/apimain.go b/cmd/apimain.go index 15a1516..77791a8 100644 --- a/cmd/apimain.go +++ b/cmd/apimain.go @@ -101,7 +101,7 @@ func main() { } func DatabaseAutoUpdate() { - version := 240 + version := 241 db := global.DB diff --git a/http/controller/api/index.go b/http/controller/api/index.go index cb82009..5e98367 100644 --- a/http/controller/api/index.go +++ b/http/controller/api/index.go @@ -54,10 +54,9 @@ func (i *Index) Heartbeat(c *gin.Context) { c.JSON(http.StatusOK, gin.H{}) return } - //如果在一分钟以内则不更新 - if time.Now().Unix()-peer.LastOnlineTime > 60 { - peer.LastOnlineTime = time.Now().Unix() - upp := &model.Peer{RowId: peer.RowId, LastOnlineTime: peer.LastOnlineTime} + //如果在40s以内则不更新 + if time.Now().Unix()-peer.LastOnlineTime > 40 { + upp := &model.Peer{RowId: peer.RowId, LastOnlineTime: time.Now().Unix(), LastOnlineIp: c.ClientIP()} service.AllService.PeerService.Update(upp) } c.JSON(http.StatusOK, gin.H{}) diff --git a/model/peer.go b/model/peer.go index 4073da6..c5dfb11 100644 --- a/model/peer.go +++ b/model/peer.go @@ -13,6 +13,7 @@ type Peer struct { UserId uint `json:"user_id" gorm:"default:0;not null;index"` User *User `json:"user,omitempty"` LastOnlineTime int64 `json:"last_online_time" gorm:"default:0;not null;"` + LastOnlineIp string `json:"last_online_ip" gorm:"default:'';not null;"` TimeModel }