From 4e18bbe44ef1aa5f0a364cc5bae323aaf005905d Mon Sep 17 00:00:00 2001 From: sawka Date: Mon, 20 Jun 2022 21:57:23 -0700 Subject: [PATCH] process comment commands --- cmd/main-server.go | 9 ++++++++- pkg/sstore/sstore.go | 31 +++++++++++++++++++++++++------ 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/cmd/main-server.go b/cmd/main-server.go index 8bc9072a4..473403726 100644 --- a/cmd/main-server.go +++ b/cmd/main-server.go @@ -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 diff --git a/pkg/sstore/sstore.go b/pkg/sstore/sstore.go index b9a4c417e..ddbbc10c8 100644 --- a/pkg/sstore/sstore.go +++ b/pkg/sstore/sstore.go @@ -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 +}