pass realoffset back in header for /api/ptyout

This commit is contained in:
sawka 2022-09-03 23:57:05 -07:00
parent 3639e2454d
commit c3961891ce
2 changed files with 4 additions and 1 deletions

View File

@ -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)
}

View File

@ -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 {