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"))
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.SessionId = params.SessionId
runPacket.CmdId = rtnLine.CmdId

View File

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