Added ?sort=asc when opening link via HTML debug page

This commit is contained in:
Seednode 2023-05-08 20:21:39 -05:00
parent 3e1fb6be6a
commit f6ac4b6e2b
2 changed files with 9 additions and 4 deletions

View File

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

View File

@ -561,7 +561,12 @@ func serveDebugHtml(args []string, index *Index) http.HandlerFunc {
htmlBody.WriteString(`<style>a{display:block;height:100%;width:100%;text-decoration:none;color:inherit;cursor:auto;}</style>`) htmlBody.WriteString(`<style>a{display:block;height:100%;width:100%;text-decoration:none;color:inherit;cursor:auto;}</style>`)
htmlBody.WriteString(`<title>Debug</title></head><body>`) htmlBody.WriteString(`<title>Debug</title></head><body>`)
for _, v := range indexDump { for _, v := range indexDump {
htmlBody.WriteString(fmt.Sprintf("<a href=%q>%s</a>\n", v, v)) var shouldSort = ""
if sorting {
shouldSort = "?sort=asc"
}
htmlBody.WriteString(fmt.Sprintf("<a href=\"%s%s\">%s</a>\n", v, shouldSort, v))
} }
htmlBody.WriteString(`</body></html>`) htmlBody.WriteString(`</body></html>`)
@ -672,7 +677,7 @@ func serveStaticFile(paths []string, stats *ServeStats) http.HandlerFunc {
} }
} }
func serveImage(paths []string, Regexes *Regexes, index *Index) http.HandlerFunc { func serveMedia(paths []string, Regexes *Regexes, index *Index) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
refererUri, err := stripQueryParams(refererToUri(r.Referer())) refererUri, err := stripQueryParams(refererToUri(r.Referer()))
if err != nil { if err != nil {
@ -907,7 +912,7 @@ func ServePage(args []string) error {
}() }()
} }
http.Handle("/", serveImage(paths, Regexes, index)) http.Handle("/", serveMedia(paths, Regexes, index))
http.Handle(Prefix+"/", http.StripPrefix(Prefix, serveStaticFile(paths, stats))) http.Handle(Prefix+"/", http.StripPrefix(Prefix, serveStaticFile(paths, stats)))
http.HandleFunc("/favicon.ico", doNothing) http.HandleFunc("/favicon.ico", doNothing)