mirror of
https://github.com/lzh-1625/go_process_manager.git
synced 2025-10-19 06:14:32 +08:00
add ws share api
This commit is contained in:
@@ -97,7 +97,7 @@ func (w *wsApi) WebsocketShareHandle(ctx *gin.Context) {
|
|||||||
errCheck(ctx, data.ExpireTime.Unix() <= time.Now().Unix(), "Share expired!")
|
errCheck(ctx, data.ExpireTime.Unix() <= time.Now().Unix(), "Share expired!")
|
||||||
proc, err := logic.ProcessCtlLogic.GetProcess(data.Pid)
|
proc, err := logic.ProcessCtlLogic.GetProcess(data.Pid)
|
||||||
errCheck(ctx, err != nil, err)
|
errCheck(ctx, err != nil, err)
|
||||||
guestName := "guest-" + strconv.Itoa(data.Id) // 构造访客用户名
|
guestName := "guest-" + strconv.Itoa(int(data.ID)) // 构造访客用户名
|
||||||
errCheck(ctx, proc.HasWsConn(guestName), "A connection already exists; unable to establish a new one!")
|
errCheck(ctx, proc.HasWsConn(guestName), "A connection already exists; unable to establish a new one!")
|
||||||
errCheck(ctx, proc.State.State != 1, "The process is currently running.")
|
errCheck(ctx, proc.State.State != 1, "The process is currently running.")
|
||||||
errCheck(ctx, !proc.VerifyControl(), "Insufficient permissions; please check your access rights!")
|
errCheck(ctx, !proc.VerifyControl(), "Insufficient permissions; please check your access rights!")
|
||||||
@@ -105,6 +105,8 @@ func (w *wsApi) WebsocketShareHandle(ctx *gin.Context) {
|
|||||||
errCheck(ctx, err != nil, "WebSocket connection upgrade failed!")
|
errCheck(ctx, err != nil, "WebSocket connection upgrade failed!")
|
||||||
|
|
||||||
log.Logger.Infow("ws连接成功")
|
log.Logger.Infow("ws连接成功")
|
||||||
|
data.UpdatedAt = time.Now()
|
||||||
|
repository.WsShare.Edit(data)
|
||||||
|
|
||||||
proc.SetTerminalSize(utils.GetIntByString(ctx.Query("cols")), utils.GetIntByString(ctx.Query("rows")))
|
proc.SetTerminalSize(utils.GetIntByString(ctx.Query("cols")), utils.GetIntByString(ctx.Query("rows")))
|
||||||
wsCtx, cancel := context.WithCancel(context.Background())
|
wsCtx, cancel := context.WithCancel(context.Background())
|
||||||
@@ -174,3 +176,13 @@ func (w *wsApi) startWsConnect(wci *WsConnetInstance, cancel context.CancelFunc,
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetWsShareList(ctx *gin.Context) {
|
||||||
|
rOk(ctx, "Operation successful!", logic.WsSahreLogic.GetWsShareList())
|
||||||
|
}
|
||||||
|
|
||||||
|
func DeleteWsShareById(ctx *gin.Context) {
|
||||||
|
err := logic.WsSahreLogic.DeleteById(ctx.GetInt("id"))
|
||||||
|
errCheck(ctx, err != nil, err)
|
||||||
|
rOk(ctx, "Operation successful!", nil)
|
||||||
|
}
|
||||||
|
18
internal/app/logic/ws_share.go
Normal file
18
internal/app/logic/ws_share.go
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/lzh-1625/go_process_manager/internal/app/model"
|
||||||
|
"github.com/lzh-1625/go_process_manager/internal/app/repository"
|
||||||
|
)
|
||||||
|
|
||||||
|
type wsShareLogic struct{}
|
||||||
|
|
||||||
|
var WsSahreLogic = &wsShareLogic{}
|
||||||
|
|
||||||
|
func (w *wsShareLogic) GetWsShareList() []*model.WsShare {
|
||||||
|
return repository.WsShare.GetWsShareList()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *wsShareLogic) DeleteById(id int) error {
|
||||||
|
return repository.WsShare.Delete(id)
|
||||||
|
}
|
@@ -2,10 +2,12 @@ package model
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
type WsShare struct {
|
type WsShare struct {
|
||||||
Id int `gorm:"primaryKey;autoIncrement;column:id" json:"id"`
|
gorm.Model
|
||||||
Pid int `gorm:"column:pid" json:"pid"`
|
Pid int `gorm:"column:pid" json:"pid"`
|
||||||
Write bool `gorm:"column:write" json:"write"`
|
Write bool `gorm:"column:write" json:"write"`
|
||||||
ExpireTime time.Time `gorm:"column:expire_time" json:"expireTime"`
|
ExpireTime time.Time `gorm:"column:expire_time" json:"expireTime"`
|
||||||
|
@@ -17,3 +17,21 @@ func (p *wsShare) GetWsShareDataByToken(token string) (data *model.WsShare, err
|
|||||||
func (p *wsShare) AddShareData(data model.WsShare) error {
|
func (p *wsShare) AddShareData(data model.WsShare) error {
|
||||||
return db.Save(&data).Error
|
return db.Save(&data).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *wsShare) GetWsShareList() (data []*model.WsShare) {
|
||||||
|
ws := query.WsShare
|
||||||
|
data, _ = ws.Find()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *wsShare) Delete(id int) error {
|
||||||
|
ws := query.WsShare
|
||||||
|
_, err := ws.Where(ws.Id.Eq(id)).Delete()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *wsShare) Edit(data *model.WsShare) error {
|
||||||
|
ws := query.WsShare
|
||||||
|
_, err := ws.Where(ws.Id.Eq(int(data.ID))).Updates(data)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user