process comment commands

This commit is contained in:
sawka 2022-06-20 21:57:23 -07:00
parent 859a1611b8
commit 4e18bbe44e
2 changed files with 33 additions and 7 deletions

View File

@ -382,7 +382,14 @@ func HandleRunCommand(w http.ResponseWriter, r *http.Request) {
WriteJsonError(w, fmt.Errorf("invalid emtpty command")) WriteJsonError(w, fmt.Errorf("invalid emtpty command"))
return return
} }
rtnLine := sstore.MakeNewLineCmd(params.SessionId, params.WindowId, commandStr) if strings.HasPrefix(commandStr, "/comment ") {
text := strings.TrimSpace(commandStr[9:])
rtnLine := sstore.MakeNewLineText(params.SessionId, params.WindowId, text)
WriteJsonSuccess(w, &runCommandResponse{Line: rtnLine})
return
}
rtnLine := sstore.MakeNewLineCmd(params.SessionId, params.WindowId)
rtnLine.CmdText = commandStr
runPacket := packet.MakeRunPacket() runPacket := packet.MakeRunPacket()
runPacket.SessionId = params.SessionId runPacket.SessionId = params.SessionId
runPacket.CmdId = rtnLine.CmdId runPacket.CmdId = rtnLine.CmdId

View File

@ -1,16 +1,29 @@
package sstore package sstore
import ( import (
"sync"
"time" "time"
"github.com/google/uuid" "github.com/google/uuid"
) )
var NextLineId = 10 var NextLineId = 10
var NextLineLock = &sync.Mutex{}
const LineTypeCmd = "cmd" const LineTypeCmd = "cmd"
const LineTypeText = "text" const LineTypeText = "text"
type SessionType struct {
SessionId string `json:"sessionid"`
Remote string `json:"remote"`
Cwd string `json:"cwd"`
}
type WindowType struct {
SessionId string `json:"sessionid"`
WindowId string `json:"windowid"`
}
type LineType struct { type LineType struct {
SessionId string `json:"sessionid"` SessionId string `json:"sessionid"`
WindowId string `json:"windowid"` WindowId string `json:"windowid"`
@ -22,19 +35,18 @@ type LineType struct {
CmdId string `json:"cmdid,omitempty"` CmdId string `json:"cmdid,omitempty"`
CmdText string `json:"cmdtext,omitempty"` CmdText string `json:"cmdtext,omitempty"`
CmdRemote string `json:"cmdremote,omitempty"` CmdRemote string `json:"cmdremote,omitempty"`
CmdCwd string `json:"cmdcwd,omitempty"`
} }
func MakeNewLineCmd(sessionId string, windowId string, cmdText string) *LineType { func MakeNewLineCmd(sessionId string, windowId string) *LineType {
rtn := &LineType{} rtn := &LineType{}
rtn.SessionId = sessionId rtn.SessionId = sessionId
rtn.WindowId = windowId rtn.WindowId = windowId
rtn.LineId = NextLineId rtn.LineId = GetNextLine()
NextLineId++
rtn.Ts = time.Now().UnixMilli() rtn.Ts = time.Now().UnixMilli()
rtn.UserId = "mike" rtn.UserId = "mike"
rtn.LineType = LineTypeCmd rtn.LineType = LineTypeCmd
rtn.CmdId = uuid.New().String() rtn.CmdId = uuid.New().String()
rtn.CmdText = cmdText
return rtn return rtn
} }
@ -42,11 +54,18 @@ func MakeNewLineText(sessionId string, windowId string, text string) *LineType {
rtn := &LineType{} rtn := &LineType{}
rtn.SessionId = sessionId rtn.SessionId = sessionId
rtn.WindowId = windowId rtn.WindowId = windowId
rtn.LineId = NextLineId rtn.LineId = GetNextLine()
NextLineId++
rtn.Ts = time.Now().UnixMilli() rtn.Ts = time.Now().UnixMilli()
rtn.UserId = "mike" rtn.UserId = "mike"
rtn.LineType = LineTypeText rtn.LineType = LineTypeText
rtn.Text = text rtn.Text = text
return rtn return rtn
} }
func GetNextLine() int {
NextLineLock.Lock()
defer NextLineLock.Unlock()
rtn := NextLineId
NextLineId++
return rtn
}