remote get-history-items, add show param and session/window ids to history command

This commit is contained in:
sawka
2022-08-30 23:11:06 -07:00
parent c03bbe8715
commit 76854b6079
3 changed files with 9 additions and 35 deletions
-33
View File
@@ -9,7 +9,6 @@ import (
"net/http"
"os"
"runtime/debug"
"strconv"
"strings"
"sync"
"time"
@@ -163,37 +162,6 @@ func HandleGetRemotes(w http.ResponseWriter, r *http.Request) {
return
}
// params: sessionid
func HandleGetHistory(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", r.Header.Get("Origin"))
w.Header().Set("Access-Control-Allow-Credentials", "true")
w.Header().Set("Vary", "Origin")
w.Header().Set("Cache-Control", "no-cache")
qvals := r.URL.Query()
sessionId := qvals.Get("sessionid")
if _, err := uuid.Parse(sessionId); err != nil {
WriteJsonError(w, fmt.Errorf("invalid sessionid: %w", err))
return
}
numItems := 1000
numStr := qvals.Get("num")
if numStr != "" {
parsedNum, err := strconv.Atoi(numStr)
if err == nil {
numItems = parsedNum
}
}
hitems, err := sstore.GetHistoryItems(r.Context(), sessionId, "", sstore.HistoryQueryOpts{MaxItems: numItems})
if err != nil {
WriteJsonError(w, err)
return
}
rtnMap := make(map[string]interface{})
rtnMap["history"] = hitems
WriteJsonSuccess(w, rtnMap)
return
}
// params: sessionid, windowid
func HandleGetWindow(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", r.Header.Get("Origin"))
@@ -466,7 +434,6 @@ func main() {
gr.HandleFunc("/api/get-all-sessions", HandleGetAllSessions)
gr.HandleFunc("/api/get-window", HandleGetWindow)
gr.HandleFunc("/api/get-remotes", HandleGetRemotes)
gr.HandleFunc("/api/get-history", HandleGetHistory)
gr.HandleFunc("/api/run-command", HandleRunCommand).Methods("GET", "POST", "OPTIONS")
server := &http.Server{
Addr: MainServerAddr,
+5 -1
View File
@@ -951,9 +951,13 @@ func HistoryCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (ssto
buf.WriteString(hstr)
}
}
show := !resolveBool(pk.Kwargs["noshow"], false)
update := &sstore.ModelUpdate{}
update.History = &sstore.HistoryInfoType{
Items: filteredItems,
SessionId: ids.SessionId,
WindowId: ids.WindowId,
Items: filteredItems,
Show: show,
}
return update, nil
}
+4 -1
View File
@@ -76,7 +76,10 @@ type InfoMsgType struct {
}
type HistoryInfoType struct {
Items []*HistoryItemType `json:"items"`
SessionId string `json:"sessionid,omitempty"`
WindowId string `json:"windowid,omitempty"`
Items []*HistoryItemType `json:"items"`
Show bool `json:"show"`
}
type CmdLineType struct {