From f85749b0300baf5738bb814010a4b5b7a833c8bf Mon Sep 17 00:00:00 2001 From: Seednode Date: Sun, 23 Oct 2022 16:29:58 -0500 Subject: [PATCH] Hopefully fixed Linux functionality --- cmd/files.go | 6 +++++- cmd/web.go | 39 ++++++++++++++++++++++++--------------- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/cmd/files.go b/cmd/files.go index a5173c0..a6ecf97 100644 --- a/cmd/files.go +++ b/cmd/files.go @@ -11,6 +11,7 @@ import ( "os" "path/filepath" "regexp" + "runtime" "strconv" "strings" "sync" @@ -79,7 +80,10 @@ func (p *Path) Decrement() { func preparePath(path string) string { path = filepath.Clean(path) - path = filepath.ToSlash(path) + + if runtime.GOOS == "windows" { + path = filepath.ToSlash(path) + } return path } diff --git a/cmd/web.go b/cmd/web.go index 81b34ce..8db372d 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -12,6 +12,7 @@ import ( "os" "path/filepath" "regexp" + "runtime" "strconv" "strings" "time" @@ -110,7 +111,11 @@ func stripQueryParams(inUrl string) (string, error) { url.RawQuery = "" - return strings.TrimPrefix(url.String(), "/"), nil + if runtime.GOOS == "windows" { + return strings.TrimPrefix(url.String(), "/"), nil + } + + return url.String(), nil } func refererToUri(referer string) string { @@ -155,7 +160,11 @@ func serveHtml(w http.ResponseWriter, r *http.Request, filePath string) error { default: htmlBody += ` ` @@ -287,9 +296,9 @@ func serveHtmlHandler(paths []string, re regexp.Regexp) appHandler { } } - newUrl := fmt.Sprintf("%v%v%v", - r.URL.Host, - url.PathEscape(filepath.Clean(filePath)), + newUrl := fmt.Sprintf("http://%v/%v%v", + r.Host, + preparePath(filePath), generateQueryParams(&filters, sortOrder), ) http.Redirect(w, r, newUrl, RedirectStatusCode) @@ -313,9 +322,9 @@ func serveHtmlHandler(paths []string, re regexp.Regexp) appHandler { return err } - newUrl := fmt.Sprintf("%v%v%v", - r.URL.Host, - url.PathEscape(filepath.Clean(filePath)), + newUrl := fmt.Sprintf("http://%v/%v%v", + r.Host, + preparePath(filePath), generateQueryParams(&filters, sortOrder), ) http.Redirect(w, r, newUrl, RedirectStatusCode) @@ -357,9 +366,9 @@ func serveHtmlHandler(paths []string, re regexp.Regexp) appHandler { } } - newUrl := fmt.Sprintf("%v%v%v", - r.URL.Host, - url.PathEscape(filepath.Clean(filePath)), + newUrl := fmt.Sprintf("http://%v/%v%v", + r.Host, + preparePath(filePath), generateQueryParams(&filters, sortOrder), ) http.Redirect(w, r, newUrl, RedirectStatusCode) @@ -383,9 +392,9 @@ func serveHtmlHandler(paths []string, re regexp.Regexp) appHandler { return err } - newUrl := fmt.Sprintf("%v%v%v", - r.URL.Host, - url.PathEscape(filepath.Clean(filePath)), + newUrl := fmt.Sprintf("http://%v/%v%v", + r.Host, + preparePath(filePath), generateQueryParams(&filters, sortOrder), ) http.Redirect(w, r, newUrl, RedirectStatusCode) @@ -453,8 +462,8 @@ func ServePage(args []string) error { re := regexp.MustCompile(`(.+)([0-9]{3})(\..+)`) - http.Handle(PREFIX+"/", http.StripPrefix(PREFIX, serveStaticFileHandler(paths))) http.Handle("/", serveHtmlHandler(paths, *re)) + http.Handle(PREFIX+"/", http.StripPrefix(PREFIX, serveStaticFileHandler(paths))) http.HandleFunc("/favicon.ico", doNothing) err = http.ListenAndServe(":"+strconv.FormatInt(int64(Port), 10), nil)