From 1b1460c8d4fa358433c51fd5293fd1c79f32aeff Mon Sep 17 00:00:00 2001 From: "Gabriel A. Giovanini" Date: Mon, 1 Jul 2024 23:32:54 +0200 Subject: feat: Add pathing to the tree tab --- pkg/handler/git/handler.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'pkg/handler/git') diff --git a/pkg/handler/git/handler.go b/pkg/handler/git/handler.go index fd62e44..5e50122 100644 --- a/pkg/handler/git/handler.go +++ b/pkg/handler/git/handler.go @@ -233,6 +233,12 @@ func (g *GitHandler) Tree(w http.ResponseWriter, r *http.Request) error { name := r.PathValue("name") ref := r.PathValue("ref") rest := r.PathValue("rest") + paths := []string{} + + // this is avoid Split from generating a len 1 array with empty string + if rest != "" { + paths = strings.Split(rest, "/") + } tree, err := g.gitService.GetTree(name, ref, rest) if err != nil { @@ -243,8 +249,8 @@ func (g *GitHandler) Tree(w http.ResponseWriter, r *http.Request) error { Name: name, Ref: ref, GitItemBase: &templates.GitItemTreePage{ - CurrentPath: rest, - Tree: tree, + Path: paths, + Tree: tree, }, } templates.WritePageTemplate(w, gitList) @@ -256,6 +262,12 @@ func (g *GitHandler) Blob(w http.ResponseWriter, r *http.Request) error { name := r.PathValue("name") ref := r.PathValue("ref") rest := r.PathValue("rest") + paths := []string{} + + // this is avoid Split from generating a len 1 array with empty string + if rest != "" { + paths = strings.Split(rest, "/") + } isBin, err := g.gitService.IsBinary(name, ref, rest) if err != nil { @@ -268,7 +280,7 @@ func (g *GitHandler) Blob(w http.ResponseWriter, r *http.Request) error { Name: name, Ref: ref, GitItemBase: &templates.GitItemBlobPage{ - File: rest, + Path: paths, Content: []byte("Binary file"), }, } @@ -303,7 +315,7 @@ func (g *GitHandler) Blob(w http.ResponseWriter, r *http.Request) error { Name: name, Ref: ref, GitItemBase: &templates.GitItemBlobPage{ - File: rest, + Path: paths, Content: code.Bytes(), }, } -- cgit v1.2.3