From c3961891ce33e3caa6b3df8b9fd04d43aa2a2e0f Mon Sep 17 00:00:00 2001 From: sawka Date: Sat, 3 Sep 2022 23:57:05 -0700 Subject: [PATCH] pass realoffset back in header for /api/ptyout --- cmd/main-server.go | 4 +++- pkg/sstore/fileops.go | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/cmd/main-server.go b/cmd/main-server.go index 65cbbe222..2cdea3693 100644 --- a/cmd/main-server.go +++ b/cmd/main-server.go @@ -9,6 +9,7 @@ import ( "net/http" "os" "runtime/debug" + "strconv" "strings" "sync" "time" @@ -216,7 +217,7 @@ func HandleGetPtyOut(w http.ResponseWriter, r *http.Request) { w.Write([]byte(fmt.Sprintf("invalid cmdid: %v", err))) return } - _, data, err := sstore.ReadFullPtyOutFile(r.Context(), sessionId, cmdId) + realOffset, data, err := sstore.ReadFullPtyOutFile(r.Context(), sessionId, cmdId) if err != nil { if errors.Is(err, fs.ErrNotExist) { w.WriteHeader(http.StatusOK) @@ -226,6 +227,7 @@ func HandleGetPtyOut(w http.ResponseWriter, r *http.Request) { w.Write([]byte(fmt.Sprintf("error reading ptyout file: %v", err))) return } + w.Header().Set("X-PtyDataOffset", strconv.FormatInt(realOffset, 10)) w.WriteHeader(http.StatusOK) w.Write(data) } diff --git a/pkg/sstore/fileops.go b/pkg/sstore/fileops.go index e55002600..f7de7a8b5 100644 --- a/pkg/sstore/fileops.go +++ b/pkg/sstore/fileops.go @@ -50,6 +50,7 @@ func AppendToCmdPtyBlob(ctx context.Context, sessionId string, cmdId string, dat return nil } +// returns (offset, data, err) func ReadFullPtyOutFile(ctx context.Context, sessionId string, cmdId string) (int64, []byte, error) { ptyOutFileName, err := scbase.PtyOutFile(sessionId, cmdId) if err != nil {