Testing initial Windows support

This commit is contained in:
Seednode 2022-10-23 16:16:40 -05:00
parent aa2413eafc
commit 8dbecba77e
4 changed files with 19 additions and 12 deletions

View File

@ -77,6 +77,13 @@ func (p *Path) Decrement() {
p.Number = p.Number - 1 p.Number = p.Number - 1
} }
func preparePath(path string) string {
path = filepath.Clean(path)
path = filepath.ToSlash(path)
return path
}
func appendPath(directory, path string, files *Files, stats *Stats) { func appendPath(directory, path string, files *Files, stats *Stats) {
files.Mutex.Lock() files.Mutex.Lock()
files.List[directory] = append(files.List[directory], path) files.List[directory] = append(files.List[directory], path)

View File

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

View File

@ -110,7 +110,7 @@ func stripQueryParams(inUrl string) (string, error) {
url.RawQuery = "" url.RawQuery = ""
return url.String(), nil return strings.TrimPrefix(url.String(), "/"), nil
} }
func refererToUri(referer string) string { func refererToUri(referer string) string {
@ -155,7 +155,7 @@ func serveHtml(w http.ResponseWriter, r *http.Request, filePath string) error {
default: default:
htmlBody += `<a href="/"><img src="` htmlBody += `<a href="/"><img src="`
} }
htmlBody += PREFIX + filePath htmlBody += PREFIX + "/" + filePath
htmlBody += `"></img></a> htmlBody += `"></img></a>
</body> </body>
</html>` </html>`
@ -289,7 +289,7 @@ func serveHtmlHandler(paths []string, re regexp.Regexp) appHandler {
newUrl := fmt.Sprintf("%v%v%v", newUrl := fmt.Sprintf("%v%v%v",
r.URL.Host, r.URL.Host,
filePath, url.PathEscape(filepath.Clean(filePath)),
generateQueryParams(&filters, sortOrder), generateQueryParams(&filters, sortOrder),
) )
http.Redirect(w, r, newUrl, RedirectStatusCode) http.Redirect(w, r, newUrl, RedirectStatusCode)
@ -315,7 +315,7 @@ func serveHtmlHandler(paths []string, re regexp.Regexp) appHandler {
newUrl := fmt.Sprintf("%v%v%v", newUrl := fmt.Sprintf("%v%v%v",
r.URL.Host, r.URL.Host,
filePath, url.PathEscape(filepath.Clean(filePath)),
generateQueryParams(&filters, sortOrder), generateQueryParams(&filters, sortOrder),
) )
http.Redirect(w, r, newUrl, RedirectStatusCode) http.Redirect(w, r, newUrl, RedirectStatusCode)
@ -359,7 +359,7 @@ func serveHtmlHandler(paths []string, re regexp.Regexp) appHandler {
newUrl := fmt.Sprintf("%v%v%v", newUrl := fmt.Sprintf("%v%v%v",
r.URL.Host, r.URL.Host,
filePath, url.PathEscape(filepath.Clean(filePath)),
generateQueryParams(&filters, sortOrder), generateQueryParams(&filters, sortOrder),
) )
http.Redirect(w, r, newUrl, RedirectStatusCode) http.Redirect(w, r, newUrl, RedirectStatusCode)
@ -385,7 +385,7 @@ func serveHtmlHandler(paths []string, re regexp.Regexp) appHandler {
newUrl := fmt.Sprintf("%v%v%v", newUrl := fmt.Sprintf("%v%v%v",
r.URL.Host, r.URL.Host,
filePath, url.PathEscape(filepath.Clean(filePath)),
generateQueryParams(&filters, sortOrder), generateQueryParams(&filters, sortOrder),
) )
http.Redirect(w, r, newUrl, RedirectStatusCode) http.Redirect(w, r, newUrl, RedirectStatusCode)
@ -399,14 +399,14 @@ func serveHtmlHandler(paths []string, re regexp.Regexp) appHandler {
return err return err
} }
newUrl := fmt.Sprintf("%v%v%v", newUrl := fmt.Sprintf("http://%v/%v%v",
r.URL.Host, r.Host,
filePath, preparePath(filePath),
generateQueryParams(&filters, sortOrder), generateQueryParams(&filters, sortOrder),
) )
http.Redirect(w, r, newUrl, RedirectStatusCode) http.Redirect(w, r, newUrl, RedirectStatusCode)
default: default:
filePath := r.URL.Path filePath := strings.TrimPrefix(r.URL.Path, "/")
exists, err := fileExists(filePath) exists, err := fileExists(filePath)
if err != nil { if err != nil {
@ -453,8 +453,8 @@ func ServePage(args []string) error {
re := regexp.MustCompile(`(.+)([0-9]{3})(\..+)`) re := regexp.MustCompile(`(.+)([0-9]{3})(\..+)`)
http.Handle("/", serveHtmlHandler(paths, *re))
http.Handle(PREFIX+"/", http.StripPrefix(PREFIX, serveStaticFileHandler(paths))) http.Handle(PREFIX+"/", http.StripPrefix(PREFIX, serveStaticFileHandler(paths)))
http.Handle("/", serveHtmlHandler(paths, *re))
http.HandleFunc("/favicon.ico", doNothing) http.HandleFunc("/favicon.ico", doNothing)
err = http.ListenAndServe(":"+strconv.FormatInt(int64(Port), 10), nil) err = http.ListenAndServe(":"+strconv.FormatInt(int64(Port), 10), nil)

BIN
roulette.exe Normal file

Binary file not shown.