From 8d50f5a088a4340fc89cf26908b4956830631844 Mon Sep 17 00:00:00 2001 From: Seednode Date: Sun, 23 Oct 2022 16:47:23 -0500 Subject: [PATCH] Second attempt at fixing Linux builds --- cmd/files.go | 2 +- cmd/version.go | 2 +- cmd/web.go | 17 +++++++++++------ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/cmd/files.go b/cmd/files.go index a6ecf97..0b9d93f 100644 --- a/cmd/files.go +++ b/cmd/files.go @@ -82,7 +82,7 @@ func preparePath(path string) string { path = filepath.Clean(path) if runtime.GOOS == "windows" { - path = filepath.ToSlash(path) + path = fmt.Sprintf("/%v", filepath.ToSlash(path)) } return path diff --git a/cmd/version.go b/cmd/version.go index 5b632b5..7659233 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -10,7 +10,7 @@ import ( "github.com/spf13/cobra" ) -var Version = "0.18.0" +var Version = "0.18.1" func init() { rootCmd.AddCommand(versionCmd) diff --git a/cmd/web.go b/cmd/web.go index 8db372d..1c96f2a 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -296,7 +296,7 @@ func serveHtmlHandler(paths []string, re regexp.Regexp) appHandler { } } - newUrl := fmt.Sprintf("http://%v/%v%v", + newUrl := fmt.Sprintf("http://%v%v%v", r.Host, preparePath(filePath), generateQueryParams(&filters, sortOrder), @@ -322,7 +322,7 @@ func serveHtmlHandler(paths []string, re regexp.Regexp) appHandler { return err } - newUrl := fmt.Sprintf("http://%v/%v%v", + newUrl := fmt.Sprintf("http://%v%v%v", r.Host, preparePath(filePath), generateQueryParams(&filters, sortOrder), @@ -366,7 +366,7 @@ func serveHtmlHandler(paths []string, re regexp.Regexp) appHandler { } } - newUrl := fmt.Sprintf("http://%v/%v%v", + newUrl := fmt.Sprintf("http://%v%v%v", r.Host, preparePath(filePath), generateQueryParams(&filters, sortOrder), @@ -392,11 +392,12 @@ func serveHtmlHandler(paths []string, re regexp.Regexp) appHandler { return err } - newUrl := fmt.Sprintf("http://%v/%v%v", + newUrl := fmt.Sprintf("http://%v%v%v", r.Host, preparePath(filePath), generateQueryParams(&filters, sortOrder), ) + fmt.Printf("New URL is %v\n", newUrl) http.Redirect(w, r, newUrl, RedirectStatusCode) case r.URL.Path == "/": filePath, err := pickFile(paths, &filters, sortOrder) @@ -408,14 +409,18 @@ func serveHtmlHandler(paths []string, re regexp.Regexp) appHandler { return err } - newUrl := fmt.Sprintf("http://%v/%v%v", + newUrl := fmt.Sprintf("http://%v%v%v", r.Host, preparePath(filePath), generateQueryParams(&filters, sortOrder), ) http.Redirect(w, r, newUrl, RedirectStatusCode) default: - filePath := strings.TrimPrefix(r.URL.Path, "/") + filePath := r.URL.Path + + if runtime.GOOS == "windows" { + filePath = strings.TrimPrefix(filePath, "/") + } exists, err := fileExists(filePath) if err != nil {