mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-12-29 10:56:35 +08:00
feat: 新增linux文件上传成功后websocket通知
This commit is contained in:
@@ -6,8 +6,6 @@ import (
|
||||
"mayfly-go/base/captcha"
|
||||
"mayfly-go/base/ctx"
|
||||
"mayfly-go/base/ginx"
|
||||
"mayfly-go/base/global"
|
||||
"mayfly-go/base/httpclient"
|
||||
"mayfly-go/base/utils"
|
||||
"mayfly-go/server/sys/api/form"
|
||||
"mayfly-go/server/sys/api/vo"
|
||||
@@ -89,16 +87,16 @@ func (a *Account) saveLogin(account *entity.Account, ip string) {
|
||||
loginMsg.CreatorId = account.Id
|
||||
a.MsgApp.Create(loginMsg)
|
||||
|
||||
bodyMap, err := httpclient.NewRequest(fmt.Sprintf("http://ip-api.com/json/%s?lang=zh-CN", ip)).Get().BodyToMap()
|
||||
if err != nil {
|
||||
global.Log.Errorf("获取客户端ip地址信息失败:%s", err.Error())
|
||||
return
|
||||
}
|
||||
if bodyMap["status"].(string) == "fail" {
|
||||
return
|
||||
}
|
||||
msg := fmt.Sprintf("%s于%s-%s登录", account.Username, bodyMap["regionName"], bodyMap["city"])
|
||||
global.Log.Info(msg)
|
||||
// bodyMap, err := httpclient.NewRequest(fmt.Sprintf("http://ip-api.com/json/%s?lang=zh-CN", ip)).Get().BodyToMap()
|
||||
// if err != nil {
|
||||
// global.Log.Errorf("获取客户端ip地址信息失败:%s", err.Error())
|
||||
// return
|
||||
// }
|
||||
// if bodyMap["status"].(string) == "fail" {
|
||||
// return
|
||||
// }
|
||||
// msg := fmt.Sprintf("%s于%s-%s登录", account.Username, bodyMap["regionName"], bodyMap["city"])
|
||||
// global.Log.Info(msg)
|
||||
}
|
||||
|
||||
// 获取个人账号信息
|
||||
|
||||
36
server/sys/api/system.go
Normal file
36
server/sys/api/system.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"mayfly-go/base/biz"
|
||||
"mayfly-go/base/ctx"
|
||||
"mayfly-go/base/ws"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
type System struct {
|
||||
}
|
||||
|
||||
// 连接websocket
|
||||
func (s *System) ConnectWs(g *gin.Context) {
|
||||
wsConn, err := ws.Upgrader.Upgrade(g.Writer, g.Request, nil)
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
wsConn.WriteMessage(websocket.TextMessage, []byte(err.(error).Error()))
|
||||
wsConn.Close()
|
||||
}
|
||||
}()
|
||||
|
||||
if err != nil {
|
||||
panic(biz.NewBizErr("升级websocket失败"))
|
||||
}
|
||||
// 权限校验
|
||||
rc := ctx.NewReqCtxWithGin(g)
|
||||
if err = ctx.PermissionHandler(rc); err != nil {
|
||||
panic(biz.NewBizErr("没有权限"))
|
||||
}
|
||||
// 登录账号信息
|
||||
la := rc.LoginAccount
|
||||
ws.Put(la.Id, wsConn)
|
||||
}
|
||||
Reference in New Issue
Block a user