Switched redirect status code back from 307 to 303, and defined it as a const.

This commit is contained in:
Seednode 2022-10-20 17:12:29 -05:00
parent 8e4c9c5e32
commit e39950de68
3 changed files with 12 additions and 8 deletions

View File

@ -277,6 +277,7 @@ func fileExists(path string) (bool, error) {
func pathIsValid(filePath string, paths []string) bool { func pathIsValid(filePath string, paths []string) bool {
var matchesPrefix = false var matchesPrefix = false
for i := 0; i < len(paths); i++ { for i := 0; i < len(paths); i++ {
if strings.HasPrefix(filePath, paths[i]) { if strings.HasPrefix(filePath, paths[i]) {
matchesPrefix = true matchesPrefix = true

View File

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

View File

@ -16,8 +16,11 @@ import (
"time" "time"
) )
const LOGDATE string = "2006-01-02T15:04:05.000-07:00" const (
const PREFIX string = "/src" LOGDATE string = "2006-01-02T15:04:05.000-07:00"
PREFIX string = "/src"
RedirectStatusCode int = http.StatusSeeOther
)
type Filters struct { type Filters struct {
Includes []string Includes []string
@ -287,7 +290,7 @@ func serveHtmlHandler(paths []string) appHandler {
filePath, filePath,
generateQueryParams(&filters, sortOrder), generateQueryParams(&filters, sortOrder),
) )
http.Redirect(w, r, newUrl, http.StatusTemporaryRedirect) http.Redirect(w, r, newUrl, RedirectStatusCode)
case r.URL.Path == "/" && sortOrder == "asc" && refererUri == "": case r.URL.Path == "/" && sortOrder == "asc" && refererUri == "":
filePath, err := pickFile(paths, &filters, sortOrder) filePath, err := pickFile(paths, &filters, sortOrder)
if err != nil && err == ErrNoImagesFound { if err != nil && err == ErrNoImagesFound {
@ -313,7 +316,7 @@ func serveHtmlHandler(paths []string) appHandler {
filePath, filePath,
generateQueryParams(&filters, sortOrder), generateQueryParams(&filters, sortOrder),
) )
http.Redirect(w, r, newUrl, http.StatusTemporaryRedirect) http.Redirect(w, r, newUrl, RedirectStatusCode)
case r.URL.Path == "/" && sortOrder == "desc" && refererUri != "": case r.URL.Path == "/" && sortOrder == "desc" && refererUri != "":
query, err := url.QueryUnescape(refererUri) query, err := url.QueryUnescape(refererUri)
if err != nil { if err != nil {
@ -357,7 +360,7 @@ func serveHtmlHandler(paths []string) appHandler {
filePath, filePath,
generateQueryParams(&filters, sortOrder), generateQueryParams(&filters, sortOrder),
) )
http.Redirect(w, r, newUrl, http.StatusTemporaryRedirect) http.Redirect(w, r, newUrl, RedirectStatusCode)
case r.URL.Path == "/" && sortOrder == "desc" && refererUri == "": case r.URL.Path == "/" && sortOrder == "desc" && refererUri == "":
filePath, err := pickFile(paths, &filters, sortOrder) filePath, err := pickFile(paths, &filters, sortOrder)
if err != nil && err == ErrNoImagesFound { if err != nil && err == ErrNoImagesFound {
@ -383,7 +386,7 @@ func serveHtmlHandler(paths []string) appHandler {
filePath, filePath,
generateQueryParams(&filters, sortOrder), generateQueryParams(&filters, sortOrder),
) )
http.Redirect(w, r, newUrl, http.StatusTemporaryRedirect) http.Redirect(w, r, newUrl, RedirectStatusCode)
case r.URL.Path == "/": case r.URL.Path == "/":
filePath, err := pickFile(paths, &filters, sortOrder) filePath, err := pickFile(paths, &filters, sortOrder)
if err != nil && err == ErrNoImagesFound { if err != nil && err == ErrNoImagesFound {
@ -399,7 +402,7 @@ func serveHtmlHandler(paths []string) appHandler {
filePath, filePath,
generateQueryParams(&filters, sortOrder), generateQueryParams(&filters, sortOrder),
) )
http.Redirect(w, r, newUrl, http.StatusTemporaryRedirect) http.Redirect(w, r, newUrl, RedirectStatusCode)
default: default:
filePath := r.URL.Path filePath := r.URL.Path