about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/http/http.go24
1 files changed, 23 insertions, 1 deletions
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
+}