about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEmile <hanemile@protonmail.com>2020-03-22 15:52:45 +0100
committerEmile <hanemile@protonmail.com>2020-03-22 15:52:45 +0100
commit2d73776198cbda37c95cd8b50f735d2b59cb5a45 (patch)
treef8533d599fa17984fcc63da9b39246490e413cc8
parentc9e53a04c5db80a3dcd600a4984cac935926fc3f (diff)
is viewable filter updates
-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
+}