From 7780b8eaa991a231265857ff597ed8acecc228fc Mon Sep 17 00:00:00 2001 From: Seednode Date: Sat, 3 Jun 2023 18:37:06 -0500 Subject: [PATCH] Added strings.TrimPrefix to refererUri so sorting works with the new setup --- cmd/root.go | 2 +- cmd/web.go | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 93c7371..5e43577 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -11,7 +11,7 @@ import ( ) const ( - Version string = "0.51.1" + Version string = "0.51.2" ) var ( diff --git a/cmd/web.go b/cmd/web.go index 95684f3..7c54003 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -795,9 +795,12 @@ func serveRoot(paths []string, Regexes *Regexes, index *Index) httprouter.Handle refererUri, err := stripQueryParams(refererToUri(r.Referer())) if err != nil { fmt.Println(err) + return } + strippedRefererUri := strings.TrimPrefix(refererUri, ImagePrefix) + filters := &Filters{ includes: splitQueryParams(r.URL.Query().Get("include"), Regexes), excludes: splitQueryParams(r.URL.Query().Get("exclude"), Regexes), @@ -810,9 +813,10 @@ func serveRoot(paths []string, Regexes *Regexes, index *Index) httprouter.Handle var filePath string if refererUri != "" { - filePath, err = nextFile(refererUri, sortOrder, Regexes) + filePath, err = nextFile(strippedRefererUri, sortOrder, Regexes) if err != nil { fmt.Println(err) + return } } @@ -837,6 +841,7 @@ func serveRoot(paths []string, Regexes *Regexes, index *Index) httprouter.Handle return case err != nil: fmt.Println(err) + return } } @@ -870,6 +875,7 @@ func serveImage(paths []string, Regexes *Regexes, index *Index) httprouter.Handl exists, err := fileExists(filePath) if err != nil { fmt.Println(err) + return } if !exists { @@ -881,6 +887,7 @@ func serveImage(paths []string, Regexes *Regexes, index *Index) httprouter.Handl image, err := isSupportedFileType(filePath) if err != nil { fmt.Println(err) + return } @@ -896,6 +903,7 @@ func serveImage(paths []string, Regexes *Regexes, index *Index) httprouter.Handl dimensions, err = imageDimensions(filePath) if err != nil { fmt.Println(err) + return } } @@ -942,6 +950,7 @@ func serveImage(paths []string, Regexes *Regexes, index *Index) httprouter.Handl _, err = io.WriteString(w, gohtml.Format(htmlBody.String())) if err != nil { fmt.Println(err) + return } } @@ -957,6 +966,7 @@ func serveFavicons() httprouter.Handle { } w.Header().Write(bytes.NewBufferString("Content-Length: " + strconv.Itoa(len(data)))) + w.Write(data) } } @@ -966,6 +976,7 @@ func serveVersion() httprouter.Handle { data := []byte(fmt.Sprintf("roulette v%s\n", Version)) w.Header().Write(bytes.NewBufferString("Content-Length: " + strconv.Itoa(len(data)))) + w.Write(data) } } @@ -1040,7 +1051,9 @@ func ServePage(args []string) error { go func() { <-gracefulShutdown + stats.Export(statisticsFile) + os.Exit(0) }() }