Hopefully fixed Linux functionality

This commit is contained in:
Seednode 2022-10-23 16:29:58 -05:00
parent 518affd8a4
commit f85749b030
2 changed files with 29 additions and 16 deletions

View File

@ -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)
if runtime.GOOS == "windows" {
path = filepath.ToSlash(path)
}
return path
}

View File

@ -12,6 +12,7 @@ import (
"os"
"path/filepath"
"regexp"
"runtime"
"strconv"
"strings"
"time"
@ -110,9 +111,13 @@ func stripQueryParams(inUrl string) (string, error) {
url.RawQuery = ""
if runtime.GOOS == "windows" {
return strings.TrimPrefix(url.String(), "/"), nil
}
return url.String(), nil
}
func refererToUri(referer string) string {
parts := strings.SplitAfterN(referer, "/", 4)
@ -155,7 +160,11 @@ func serveHtml(w http.ResponseWriter, r *http.Request, filePath string) error {
default:
htmlBody += `<a href="/"><img src="`
}
htmlBody += PREFIX + "/" + filePath
htmlBody += PREFIX
if runtime.GOOS == "windows" {
htmlBody += "/"
}
htmlBody += filePath
htmlBody += `"></img></a>
</body>
</html>`
@ -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)