From 2d73776198cbda37c95cd8b50f735d2b59cb5a45 Mon Sep 17 00:00:00 2001 From: Emile Date: Sun, 22 Mar 2020 15:52:45 +0100 Subject: is viewable filter updates --- src/http/http.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/http/http.go b/src/http/http.go index d7f4ac6..7f4eb60 100644 --- a/src/http/http.go +++ b/src/http/http.go @@ -216,7 +216,14 @@ func pathHandler(w http.ResponseWriter, r *http.Request) { item.IsDir = true dirCount++ } else { - item.Download = true + + // if the file extension is in the list of viewable extensions, + // define the file as viewable, else, flag it as downloadable + if filterIsViewable(f.Name()) == true { + item.Viewable = true + } else { + item.Download = true + } fileCount++ } @@ -328,3 +335,18 @@ func filterIsValid(name string) bool { return true } + +// filterIsViewable determines if the file with the given name is "viewable", +// this means that the link to the file contains a ?view suffix indicating that +// the file should not be downloaded but viewd in the browser +func filterIsViewable(name string) bool { + + extensions := viper.GetStringSlice("view.extensions") + for _, extension := range extensions { + if strings.HasSuffix(name, extension) { + return true + } + } + + return false +} -- cgit 1.4.1