summaryrefslogtreecommitdiffstats
path: root/routes/routes.go
diff options
context:
space:
mode:
authorLibravatar cel 🌸 <cel@blos.sm>2024-02-19 23:49:34 +0000
committerLibravatar cel 🌸 <cel@blos.sm>2024-02-19 23:49:34 +0000
commitac0983a89692534daa3d36dba528461b5bb32dbc (patch)
treecc1ced6b3098192f9009cc4f1337da7014b49bd0 /routes/routes.go
parent3c1b8007b6d5992e6bffc701ad06e0adec717145 (diff)
downloadlegit-ac0983a89692534daa3d36dba528461b5bb32dbc.tar.gz
legit-ac0983a89692534daa3d36dba528461b5bb32dbc.tar.bz2
legit-ac0983a89692534daa3d36dba528461b5bb32dbc.zip
support categories
Diffstat (limited to 'routes/routes.go')
-rw-r--r--routes/routes.go86
1 files changed, 68 insertions, 18 deletions
diff --git a/routes/routes.go b/routes/routes.go
index ca2e729..6c6df6c 100644
--- a/routes/routes.go
+++ b/routes/routes.go
@@ -159,12 +159,22 @@ func (d *deps) RepoIndex(w http.ResponseWriter, r *http.Request) {
return
}
name = filepath.Clean(name)
- path := filepath.Join(d.c.Repo.ScanPath, name)
+ path := d.c.Repo.ScanPath
+ category := flow.Param(r.Context(), "category")
+ if category != "" {
+ path = filepath.Join(path, category)
+ log.Println(category)
+ }
+ path = filepath.Join(path, name)
+ log.Println(path)
gr, err := git.Open(path, "")
if err != nil {
- d.Write404(w)
- return
+ gr, err = git.Open(path+".git", "")
+ if err != nil {
+ d.Write404(w)
+ return
+ }
}
commits, err := gr.Commits()
@@ -242,11 +252,19 @@ func (d *deps) RepoTree(w http.ResponseWriter, r *http.Request) {
ref := flow.Param(r.Context(), "ref")
name = filepath.Clean(name)
- path := filepath.Join(d.c.Repo.ScanPath, name)
+ path := d.c.Repo.ScanPath
+ category := flow.Param(r.Context(), "category")
+ if category != "" {
+ path = filepath.Join(path, category)
+ }
+ path = filepath.Join(path, name)
gr, err := git.Open(path, ref)
if err != nil {
- d.Write404(w)
- return
+ gr, err = git.Open(path+".git", ref)
+ if err != nil {
+ d.Write404(w)
+ return
+ }
}
files, err := gr.FileTree(treePath)
@@ -277,11 +295,19 @@ func (d *deps) FileContent(w http.ResponseWriter, r *http.Request) {
ref := flow.Param(r.Context(), "ref")
name = filepath.Clean(name)
- path := filepath.Join(d.c.Repo.ScanPath, name)
+ path := d.c.Repo.ScanPath
+ category := flow.Param(r.Context(), "category")
+ if category != "" {
+ path = filepath.Join(path, category)
+ }
+ path = filepath.Join(path, name)
gr, err := git.Open(path, ref)
if err != nil {
- d.Write404(w)
- return
+ gr, err = git.Open(path+".git", ref)
+ if err != nil {
+ d.Write404(w)
+ return
+ }
}
contents, err := gr.FileContent(treePath)
@@ -303,11 +329,19 @@ func (d *deps) Log(w http.ResponseWriter, r *http.Request) {
}
ref := flow.Param(r.Context(), "ref")
- path := filepath.Join(d.c.Repo.ScanPath, name)
+ path := d.c.Repo.ScanPath
+ category := flow.Param(r.Context(), "category")
+ if category != "" {
+ path = filepath.Join(path, category)
+ }
+ path = filepath.Join(path, name)
gr, err := git.Open(path, ref)
if err != nil {
- d.Write404(w)
- return
+ gr, err = git.Open(path+".git", ref)
+ if err != nil {
+ d.Write404(w)
+ return
+ }
}
commits, err := gr.Commits()
@@ -342,11 +376,19 @@ func (d *deps) Diff(w http.ResponseWriter, r *http.Request) {
}
ref := flow.Param(r.Context(), "ref")
- path := filepath.Join(d.c.Repo.ScanPath, name)
+ path := d.c.Repo.ScanPath
+ category := flow.Param(r.Context(), "category")
+ if category != "" {
+ path = filepath.Join(path, category)
+ }
+ path = filepath.Join(path, name)
gr, err := git.Open(path, ref)
if err != nil {
- d.Write404(w)
- return
+ gr, err = git.Open(path+".git", ref)
+ if err != nil {
+ d.Write404(w)
+ return
+ }
}
diff, err := gr.Diff()
@@ -382,11 +424,19 @@ func (d *deps) Refs(w http.ResponseWriter, r *http.Request) {
return
}
- path := filepath.Join(d.c.Repo.ScanPath, name)
+ path := d.c.Repo.ScanPath
+ category := flow.Param(r.Context(), "category")
+ if category != "" {
+ path = filepath.Join(path, category)
+ }
+ path = filepath.Join(path, name)
gr, err := git.Open(path, "")
if err != nil {
- d.Write404(w)
- return
+ gr, err = git.Open(path+".git", "")
+ if err != nil {
+ d.Write404(w)
+ return
+ }
}
tags, err := gr.Tags()