From 82f4077b6fcfb051cef9df3d3a1809477a2e2c4a Mon Sep 17 00:00:00 2001 From: Emile Date: Sun, 15 Mar 2020 23:16:07 +0100 Subject: filters --- src/http/http.go | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'src/http') 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 +} -- cgit 1.4.1