Simplify page view file loading to plain relative paths

This commit is contained in:
Ian Gulliver
2026-10-23 06:55:15 -07:00
parent c6da60f728
commit 5b69d2c639
6 changed files with 466 additions and 461 deletions
+9 -5
View File
@@ -226,12 +226,16 @@ func serveFile(w http.ResponseWriter, root, rel string) {
writeJSON(w, http.StatusOK, fc)
}
func (s *Server) GetRaw(w http.ResponseWriter, r *http.Request, params api.GetRawParams) {
full := filepath.Clean(filepath.FromSlash(params.Path))
if !filepath.IsAbs(full) {
writeError(w, http.StatusBadRequest, errors.New("path must be absolute"))
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, full := taskPath(t.WorktreePath, params.Path)
f, err := os.Open(full)
if err != nil {
@@ -250,7 +254,7 @@ func (s *Server) GetRaw(w http.ResponseWriter, r *http.Request, params api.GetRa
return
}
contentType := mime.TypeByExtension(filepath.Ext(full))
contentType := mime.TypeByExtension(path.Ext(name))
if contentType == "" {
contentType = "application/octet-stream"
}