From ac0983a89692534daa3d36dba528461b5bb32dbc Mon Sep 17 00:00:00 2001 From: cel 🌸 Date: Mon, 19 Feb 2024 23:49:34 +0000 Subject: support categories --- routes/routes.go | 86 ++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 68 insertions(+), 18 deletions(-) (limited to 'routes/routes.go') 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() -- cgit