Show HTML pages in a task view beside the transcript
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"mime"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
@@ -215,6 +216,55 @@ func (s *Server) GetTaskFile(w http.ResponseWriter, r *http.Request, taskID stri
|
||||
writeJSON(w, http.StatusOK, fc)
|
||||
}
|
||||
|
||||
func (s *Server) GetTaskRaw(w http.ResponseWriter, r *http.Request, taskID string, params api.GetTaskRawParams) {
|
||||
t, ok := s.activeTask(w, r, taskID)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if params.Path == "" {
|
||||
writeError(w, http.StatusBadRequest, errors.New("path is required"))
|
||||
return
|
||||
}
|
||||
name, ok := worktreeName(w, params.Path)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
root, err := os.OpenRoot(t.WorktreePath)
|
||||
if err != nil {
|
||||
writeError(w, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
defer root.Close()
|
||||
|
||||
f, err := root.Open(name)
|
||||
if err != nil {
|
||||
writePathError(w, err)
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
fi, err := f.Stat()
|
||||
if err != nil {
|
||||
writeError(w, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
if !fi.Mode().IsRegular() {
|
||||
writeError(w, http.StatusBadRequest, fmt.Errorf("%s is not a regular file", params.Path))
|
||||
return
|
||||
}
|
||||
|
||||
contentType := mime.TypeByExtension(path.Ext(name))
|
||||
if contentType == "" {
|
||||
contentType = "application/octet-stream"
|
||||
}
|
||||
w.Header().Set("Content-Type", contentType)
|
||||
w.Header().Set("X-Content-Type-Options", "nosniff")
|
||||
w.Header().Set("Content-Security-Policy", "sandbox")
|
||||
w.Header().Set("Cache-Control", "private, no-cache")
|
||||
http.ServeContent(w, r, "", fi.ModTime(), f)
|
||||
}
|
||||
|
||||
func worktreeName(w http.ResponseWriter, rel string) (string, bool) {
|
||||
if rel == "" {
|
||||
return ".", true
|
||||
|
||||
Reference in New Issue
Block a user