Add a Files tab to the project page
This commit is contained in:
@@ -29,11 +29,24 @@ func (s *Server) GetTaskDir(w http.ResponseWriter, r *http.Request, taskID strin
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
rel := ""
|
||||
if params.Path != nil {
|
||||
rel = *params.Path
|
||||
serveDir(w, r, t.WorktreePath, params.Path)
|
||||
}
|
||||
|
||||
func (s *Server) GetProjectDir(w http.ResponseWriter, r *http.Request, projectID string, params api.GetProjectDirParams) {
|
||||
p, err := s.store.GetProject(r.Context(), projectID)
|
||||
if err != nil {
|
||||
writeStoreError(w, err)
|
||||
return
|
||||
}
|
||||
name, full := taskPath(t.WorktreePath, rel)
|
||||
serveDir(w, r, p.RepoPath, params.Path)
|
||||
}
|
||||
|
||||
func serveDir(w http.ResponseWriter, r *http.Request, root string, p *string) {
|
||||
rel := ""
|
||||
if p != nil {
|
||||
rel = *p
|
||||
}
|
||||
name, full := taskPath(root, rel)
|
||||
|
||||
f, err := os.Open(full)
|
||||
if err != nil {
|
||||
@@ -84,7 +97,7 @@ func (s *Server) GetTaskDir(w http.ResponseWriter, r *http.Request, taskID strin
|
||||
listing.Truncated = true
|
||||
}
|
||||
|
||||
real, err := realDir(t.WorktreePath, full)
|
||||
real, err := realDir(root, full)
|
||||
if err != nil {
|
||||
writeError(w, http.StatusInternalServerError, err)
|
||||
return
|
||||
@@ -97,7 +110,7 @@ func (s *Server) GetTaskDir(w http.ResponseWriter, r *http.Request, taskID strin
|
||||
for _, e := range listing.Entries {
|
||||
paths = append(paths, path.Join(real, e.Name))
|
||||
}
|
||||
ignored, err := git.Ignored(r.Context(), t.WorktreePath, paths)
|
||||
ignored, err := git.Ignored(r.Context(), root, paths)
|
||||
if err != nil {
|
||||
writeError(w, http.StatusInternalServerError, err)
|
||||
return
|
||||
@@ -154,11 +167,24 @@ func (s *Server) GetTaskFile(w http.ResponseWriter, r *http.Request, taskID stri
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if params.Path == "" {
|
||||
serveFile(w, t.WorktreePath, params.Path)
|
||||
}
|
||||
|
||||
func (s *Server) GetProjectFile(w http.ResponseWriter, r *http.Request, projectID string, params api.GetProjectFileParams) {
|
||||
p, err := s.store.GetProject(r.Context(), projectID)
|
||||
if err != nil {
|
||||
writeStoreError(w, err)
|
||||
return
|
||||
}
|
||||
serveFile(w, p.RepoPath, params.Path)
|
||||
}
|
||||
|
||||
func serveFile(w http.ResponseWriter, root, rel string) {
|
||||
if rel == "" {
|
||||
writeError(w, http.StatusBadRequest, errors.New("path is required"))
|
||||
return
|
||||
}
|
||||
name, full := taskPath(t.WorktreePath, params.Path)
|
||||
name, full := taskPath(root, rel)
|
||||
|
||||
fi, err := os.Stat(full)
|
||||
if err != nil {
|
||||
@@ -166,7 +192,7 @@ func (s *Server) GetTaskFile(w http.ResponseWriter, r *http.Request, taskID stri
|
||||
return
|
||||
}
|
||||
if !fi.Mode().IsRegular() {
|
||||
writeError(w, http.StatusBadRequest, fmt.Errorf("%s is not a regular file", params.Path))
|
||||
writeError(w, http.StatusBadRequest, fmt.Errorf("%s is not a regular file", rel))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user