Added strings.TrimPrefix to refererUri so sorting works with the new setup

This commit is contained in:
Seednode 2023-06-03 18:37:06 -05:00
parent 3d8d4c3869
commit 7780b8eaa9
2 changed files with 15 additions and 2 deletions

View File

@ -11,7 +11,7 @@ import (
) )
const ( const (
Version string = "0.51.1" Version string = "0.51.2"
) )
var ( var (

View File

@ -795,9 +795,12 @@ func serveRoot(paths []string, Regexes *Regexes, index *Index) httprouter.Handle
refererUri, err := stripQueryParams(refererToUri(r.Referer())) refererUri, err := stripQueryParams(refererToUri(r.Referer()))
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
return return
} }
strippedRefererUri := strings.TrimPrefix(refererUri, ImagePrefix)
filters := &Filters{ filters := &Filters{
includes: splitQueryParams(r.URL.Query().Get("include"), Regexes), includes: splitQueryParams(r.URL.Query().Get("include"), Regexes),
excludes: splitQueryParams(r.URL.Query().Get("exclude"), 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 var filePath string
if refererUri != "" { if refererUri != "" {
filePath, err = nextFile(refererUri, sortOrder, Regexes) filePath, err = nextFile(strippedRefererUri, sortOrder, Regexes)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
return return
} }
} }
@ -837,6 +841,7 @@ func serveRoot(paths []string, Regexes *Regexes, index *Index) httprouter.Handle
return return
case err != nil: case err != nil:
fmt.Println(err) fmt.Println(err)
return return
} }
} }
@ -870,6 +875,7 @@ func serveImage(paths []string, Regexes *Regexes, index *Index) httprouter.Handl
exists, err := fileExists(filePath) exists, err := fileExists(filePath)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
return return
} }
if !exists { if !exists {
@ -881,6 +887,7 @@ func serveImage(paths []string, Regexes *Regexes, index *Index) httprouter.Handl
image, err := isSupportedFileType(filePath) image, err := isSupportedFileType(filePath)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
return return
} }
@ -896,6 +903,7 @@ func serveImage(paths []string, Regexes *Regexes, index *Index) httprouter.Handl
dimensions, err = imageDimensions(filePath) dimensions, err = imageDimensions(filePath)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
return return
} }
} }
@ -942,6 +950,7 @@ func serveImage(paths []string, Regexes *Regexes, index *Index) httprouter.Handl
_, err = io.WriteString(w, gohtml.Format(htmlBody.String())) _, err = io.WriteString(w, gohtml.Format(htmlBody.String()))
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
return return
} }
} }
@ -957,6 +966,7 @@ func serveFavicons() httprouter.Handle {
} }
w.Header().Write(bytes.NewBufferString("Content-Length: " + strconv.Itoa(len(data)))) w.Header().Write(bytes.NewBufferString("Content-Length: " + strconv.Itoa(len(data))))
w.Write(data) w.Write(data)
} }
} }
@ -966,6 +976,7 @@ func serveVersion() httprouter.Handle {
data := []byte(fmt.Sprintf("roulette v%s\n", Version)) data := []byte(fmt.Sprintf("roulette v%s\n", Version))
w.Header().Write(bytes.NewBufferString("Content-Length: " + strconv.Itoa(len(data)))) w.Header().Write(bytes.NewBufferString("Content-Length: " + strconv.Itoa(len(data))))
w.Write(data) w.Write(data)
} }
} }
@ -1040,7 +1051,9 @@ func ServePage(args []string) error {
go func() { go func() {
<-gracefulShutdown <-gracefulShutdown
stats.Export(statisticsFile) stats.Export(statisticsFile)
os.Exit(0) os.Exit(0)
}() }()
} }