about summary refs log tree commit diff
path: root/src/http
diff options
context:
space:
mode:
Diffstat (limited to 'src/http')
-rw-r--r--src/http/http.go35
1 files changed, 34 insertions, 1 deletions
diff --git a/src/http/http.go b/src/http/http.go
index 195a0f6..cdfdf68 100644
--- a/src/http/http.go
+++ b/src/http/http.go
@@ -98,6 +98,11 @@ func pathHandler(w http.ResponseWriter, r *http.Request) {
 	for _, f := range files {
 		logrus.Tracef("f: %s", f.Name())
 
+		filterResult := filterIsValid(f.Name())
+		if filterResult == true {
+			continue
+		}
+
 		// get the file or dirs modtime and format it in a readable way as
 		// described in the config
 		modTime := f.ModTime()
@@ -180,7 +185,6 @@ func pathHandler(w http.ResponseWriter, r *http.Request) {
 
 	err = t.ExecuteTemplate(w, "index", content)
 	logrus.Warn(err)
-	w.WriteHeader(http.StatusInternalServerError)
 	return
 }
 
@@ -218,3 +222,32 @@ func breadcrumbs(r *http.Request) structs.Breadcrumbs {
 
 	return breadcrumbs
 }
+
+// filter filters files returning true if they should be displayed and false if
+// not. The descision is made using the hide config from the config file
+func filterIsValid(name string) bool {
+
+	// hide files starting with a dot if the "hide.file" directive is set
+	if viper.GetBool("hide.files") == true {
+		logrus.Info("checking hide")
+		if name[0] != '.' {
+			logrus.Info("hide")
+			return false
+		}
+	}
+
+	extensions := viper.GetStringSlice("hide.extensions")
+
+	splitFileName := strings.Split(name, ".")
+	fileExtension := splitFileName[len(splitFileName)-1]
+
+	for _, extension := range extensions {
+		if fileExtension == extension {
+			logrus.Info("extension")
+			logrus.Info(extension)
+			return false
+		}
+	}
+
+	return true
+}