serveHtmlHandler could potentially return an empty response in default case

This commit is contained in:
Seednode 2022-09-18 13:17:29 -05:00
parent f3280a6b6c
commit 9e05a12fd7
2 changed files with 10 additions and 8 deletions

View File

@ -10,7 +10,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
var Version = "0.8.0" var Version = "0.8.1"
func init() { func init() {
rootCmd.AddCommand(versionCmd) rootCmd.AddCommand(versionCmd)

View File

@ -136,12 +136,12 @@ func serveHtmlHandler(paths []string) http.HandlerFunc {
switch { switch {
case r.RequestURI == "/" && Successive && refererUri != "": case r.RequestURI == "/" && Successive && refererUri != "":
f, err := url.QueryUnescape(refererUri) query, err := url.QueryUnescape(refererUri)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
filePath, err = getNextFile(f) filePath, err = getNextFile(query)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@ -189,17 +189,19 @@ func serveHtmlHandler(paths []string) http.HandlerFunc {
isImage, err := checkIfImage(filePath) isImage, err := checkIfImage(filePath)
if err != nil { if err != nil {
log.Fatal(err)
}
if !isImage {
http.NotFound(w, r) http.NotFound(w, r)
} }
if isImage { err = serveHtml(w, *r, filePath)
err := serveHtml(w, *r, filePath)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
} }
} }
}
} }
func doNothing(http.ResponseWriter, *http.Request) {} func doNothing(http.ResponseWriter, *http.Request) {}