summaryrefslogtreecommitdiffstats
path: root/routes
diff options
context:
space:
mode:
authorLibravatar Anirudh Oppiliappan <x@icyphox.sh>2022-12-22 21:13:49 +0530
committerLibravatar Anirudh Oppiliappan <x@icyphox.sh>2022-12-22 21:13:49 +0530
commitf661e6e4ce1177352b5bc40238351920cc25a69b (patch)
tree602979b0ef6f931206686d435aa1aff93c5a6a57 /routes
parent2b57b6e0b1b936f45aa4ed8fd0ed2f57b7d370f3 (diff)
downloadlegit-f661e6e4ce1177352b5bc40238351920cc25a69b.tar.gz
legit-f661e6e4ce1177352b5bc40238351920cc25a69b.tar.bz2
legit-f661e6e4ce1177352b5bc40238351920cc25a69b.zip
config: add repo.ignore
Diffstat (limited to 'routes')
-rw-r--r--routes/routes.go39
-rw-r--r--routes/util.go26
2 files changed, 55 insertions, 10 deletions
diff --git a/routes/routes.go b/routes/routes.go
index c2d80dd..30f101a 100644
--- a/routes/routes.go
+++ b/routes/routes.go
@@ -35,6 +35,10 @@ func (d *deps) Index(w http.ResponseWriter, r *http.Request) {
infos := []info{}
for _, dir := range dirs {
+ if d.isIgnored(dir.Name()) {
+ continue
+ }
+
path := filepath.Join(d.c.Repo.ScanPath, dir.Name())
gr, err := git.Open(path, "")
if err != nil {
@@ -77,8 +81,13 @@ func (d *deps) Index(w http.ResponseWriter, r *http.Request) {
func (d *deps) RepoIndex(w http.ResponseWriter, r *http.Request) {
name := flow.Param(r.Context(), "name")
+ if d.isIgnored(name) {
+ d.Write404(w)
+ return
+ }
name = filepath.Clean(name)
path := filepath.Join(d.c.Repo.ScanPath, name)
+
gr, err := git.Open(path, "")
if err != nil {
d.Write404(w)
@@ -136,6 +145,10 @@ func (d *deps) RepoIndex(w http.ResponseWriter, r *http.Request) {
func (d *deps) RepoTree(w http.ResponseWriter, r *http.Request) {
name := flow.Param(r.Context(), "name")
+ if d.isIgnored(name) {
+ d.Write404(w)
+ return
+ }
treePath := flow.Param(r.Context(), "...")
ref := flow.Param(r.Context(), "ref")
@@ -166,6 +179,10 @@ func (d *deps) RepoTree(w http.ResponseWriter, r *http.Request) {
func (d *deps) FileContent(w http.ResponseWriter, r *http.Request) {
name := flow.Param(r.Context(), "name")
+ if d.isIgnored(name) {
+ d.Write404(w)
+ return
+ }
treePath := flow.Param(r.Context(), "...")
ref := flow.Param(r.Context(), "ref")
@@ -190,6 +207,10 @@ func (d *deps) FileContent(w http.ResponseWriter, r *http.Request) {
func (d *deps) Log(w http.ResponseWriter, r *http.Request) {
name := flow.Param(r.Context(), "name")
+ if d.isIgnored(name) {
+ d.Write404(w)
+ return
+ }
ref := flow.Param(r.Context(), "ref")
path := filepath.Join(d.c.Repo.ScanPath, name)
@@ -224,6 +245,10 @@ func (d *deps) Log(w http.ResponseWriter, r *http.Request) {
func (d *deps) Diff(w http.ResponseWriter, r *http.Request) {
name := flow.Param(r.Context(), "name")
+ if d.isIgnored(name) {
+ d.Write404(w)
+ return
+ }
ref := flow.Param(r.Context(), "ref")
path := filepath.Join(d.c.Repo.ScanPath, name)
@@ -261,6 +286,10 @@ func (d *deps) Diff(w http.ResponseWriter, r *http.Request) {
func (d *deps) Refs(w http.ResponseWriter, r *http.Request) {
name := flow.Param(r.Context(), "name")
+ if d.isIgnored(name) {
+ d.Write404(w)
+ return
+ }
path := filepath.Join(d.c.Repo.ScanPath, name)
gr, err := git.Open(path, "")
@@ -305,13 +334,3 @@ func (d *deps) ServeStatic(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, f)
}
-
-func getDescription(path string) (desc string) {
- db, err := os.ReadFile(filepath.Join(path, "description"))
- if err == nil {
- desc = string(db)
- } else {
- desc = ""
- }
- return
-}
diff --git a/routes/util.go b/routes/util.go
new file mode 100644
index 0000000..d3f80fe
--- /dev/null
+++ b/routes/util.go
@@ -0,0 +1,26 @@
+package routes
+
+import (
+ "os"
+ "path/filepath"
+)
+
+func getDescription(path string) (desc string) {
+ db, err := os.ReadFile(filepath.Join(path, "description"))
+ if err == nil {
+ desc = string(db)
+ } else {
+ desc = ""
+ }
+ return
+}
+
+func (d *deps) isIgnored(name string) bool {
+ for _, i := range d.c.Repo.Ignore {
+ if name == i {
+ return true
+ }
+ }
+
+ return false
+}