diff --git a/cmd/files.go b/cmd/files.go index 9b5c28d..c61fd35 100644 --- a/cmd/files.go +++ b/cmd/files.go @@ -277,6 +277,7 @@ func fileExists(path string) (bool, error) { func pathIsValid(filePath string, paths []string) bool { var matchesPrefix = false + for i := 0; i < len(paths); i++ { if strings.HasPrefix(filePath, paths[i]) { matchesPrefix = true diff --git a/cmd/version.go b/cmd/version.go index af69d4a..76fabfd 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -10,7 +10,7 @@ import ( "github.com/spf13/cobra" ) -var Version = "0.17.1" +var Version = "0.17.2" func init() { rootCmd.AddCommand(versionCmd) diff --git a/cmd/web.go b/cmd/web.go index 285fce1..8e15579 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -16,8 +16,11 @@ import ( "time" ) -const LOGDATE string = "2006-01-02T15:04:05.000-07:00" -const PREFIX string = "/src" +const ( + LOGDATE string = "2006-01-02T15:04:05.000-07:00" + PREFIX string = "/src" + RedirectStatusCode int = http.StatusSeeOther +) type Filters struct { Includes []string @@ -287,7 +290,7 @@ func serveHtmlHandler(paths []string) appHandler { filePath, generateQueryParams(&filters, sortOrder), ) - http.Redirect(w, r, newUrl, http.StatusTemporaryRedirect) + http.Redirect(w, r, newUrl, RedirectStatusCode) case r.URL.Path == "/" && sortOrder == "asc" && refererUri == "": filePath, err := pickFile(paths, &filters, sortOrder) if err != nil && err == ErrNoImagesFound { @@ -313,7 +316,7 @@ func serveHtmlHandler(paths []string) appHandler { filePath, generateQueryParams(&filters, sortOrder), ) - http.Redirect(w, r, newUrl, http.StatusTemporaryRedirect) + http.Redirect(w, r, newUrl, RedirectStatusCode) case r.URL.Path == "/" && sortOrder == "desc" && refererUri != "": query, err := url.QueryUnescape(refererUri) if err != nil { @@ -357,7 +360,7 @@ func serveHtmlHandler(paths []string) appHandler { filePath, generateQueryParams(&filters, sortOrder), ) - http.Redirect(w, r, newUrl, http.StatusTemporaryRedirect) + http.Redirect(w, r, newUrl, RedirectStatusCode) case r.URL.Path == "/" && sortOrder == "desc" && refererUri == "": filePath, err := pickFile(paths, &filters, sortOrder) if err != nil && err == ErrNoImagesFound { @@ -383,7 +386,7 @@ func serveHtmlHandler(paths []string) appHandler { filePath, generateQueryParams(&filters, sortOrder), ) - http.Redirect(w, r, newUrl, http.StatusTemporaryRedirect) + http.Redirect(w, r, newUrl, RedirectStatusCode) case r.URL.Path == "/": filePath, err := pickFile(paths, &filters, sortOrder) if err != nil && err == ErrNoImagesFound { @@ -399,7 +402,7 @@ func serveHtmlHandler(paths []string) appHandler { filePath, generateQueryParams(&filters, sortOrder), ) - http.Redirect(w, r, newUrl, http.StatusTemporaryRedirect) + http.Redirect(w, r, newUrl, RedirectStatusCode) default: filePath := r.URL.Path