Add a Files tab to the project page

This commit is contained in:
Ian Gulliver
2026-10-22 19:17:08 -07:00
parent 2aba745531
commit d8ce1cee41
12 changed files with 769 additions and 437 deletions
+17 -5
View File
@@ -26,14 +26,26 @@ func (s *Server) GetTaskImage(w http.ResponseWriter, r *http.Request, taskID str
if !ok {
return
}
serveImage(w, r, t.WorktreePath, params.Path)
}
path := params.Path
func (s *Server) GetProjectImage(w http.ResponseWriter, r *http.Request, projectID string, params api.GetProjectImageParams) {
p, err := s.store.GetProject(r.Context(), projectID)
if err != nil {
writeStoreError(w, err)
return
}
serveImage(w, r, p.RepoPath, params.Path)
}
func serveImage(w http.ResponseWriter, r *http.Request, root, rel string) {
path := rel
if !filepath.IsAbs(path) {
path = filepath.Join(t.WorktreePath, path)
path = filepath.Join(root, path)
}
real, err := filepath.EvalSymlinks(path)
if errors.Is(err, fs.ErrNotExist) {
writeError(w, http.StatusNotFound, fmt.Errorf("%s does not exist", params.Path))
writeError(w, http.StatusNotFound, fmt.Errorf("%s does not exist", rel))
return
}
if err != nil {
@@ -43,7 +55,7 @@ func (s *Server) GetTaskImage(w http.ResponseWriter, r *http.Request, taskID str
contentType := worktreeImageTypes[strings.ToLower(filepath.Ext(real))]
if contentType == "" {
writeError(w, http.StatusBadRequest, fmt.Errorf("%s is not a PNG, JPEG, GIF, WebP or SVG file", params.Path))
writeError(w, http.StatusBadRequest, fmt.Errorf("%s is not a PNG, JPEG, GIF, WebP or SVG file", rel))
return
}
@@ -60,7 +72,7 @@ func (s *Server) GetTaskImage(w http.ResponseWriter, r *http.Request, taskID str
return
}
if !info.Mode().IsRegular() {
writeError(w, http.StatusBadRequest, fmt.Errorf("%s is not a file", params.Path))
writeError(w, http.StatusBadRequest, fmt.Errorf("%s is not a file", rel))
return
}