aboutsummaryrefslogtreecommitdiff
path: root/pkg/handler/git
diff options
context:
space:
mode:
authorGabriel A. Giovanini <mail@gabrielgio.me>2024-07-01 23:32:54 +0200
committerGabriel A. Giovanini <mail@gabrielgio.me>2024-07-01 23:32:54 +0200
commit1b1460c8d4fa358433c51fd5293fd1c79f32aeff (patch)
treeb87528374798941a89e07ead5b92c2842deb40b6 /pkg/handler/git
parent8f9853c8e26ffbad74e6414cec31104281a3860b (diff)
downloadcerrado-0.0.9.tar.gz
cerrado-0.0.9.tar.bz2
cerrado-0.0.9.zip
feat: Add pathing to the tree tabv0.0.9
Diffstat (limited to 'pkg/handler/git')
-rw-r--r--pkg/handler/git/handler.go20
1 files changed, 16 insertions, 4 deletions
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(),
},
}