Hopefully fixed Linux functionality
This commit is contained in:
parent
518affd8a4
commit
f85749b030
|
@ -11,6 +11,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -79,7 +80,10 @@ func (p *Path) Decrement() {
|
||||||
|
|
||||||
func preparePath(path string) string {
|
func preparePath(path string) string {
|
||||||
path = filepath.Clean(path)
|
path = filepath.Clean(path)
|
||||||
path = filepath.ToSlash(path)
|
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
path = filepath.ToSlash(path)
|
||||||
|
}
|
||||||
|
|
||||||
return path
|
return path
|
||||||
}
|
}
|
||||||
|
|
39
cmd/web.go
39
cmd/web.go
|
@ -12,6 +12,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -110,7 +111,11 @@ func stripQueryParams(inUrl string) (string, error) {
|
||||||
|
|
||||||
url.RawQuery = ""
|
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 {
|
func refererToUri(referer string) string {
|
||||||
|
@ -155,7 +160,11 @@ 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
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
htmlBody += "/"
|
||||||
|
}
|
||||||
|
htmlBody += filePath
|
||||||
htmlBody += `"></img></a>
|
htmlBody += `"></img></a>
|
||||||
</body>
|
</body>
|
||||||
</html>`
|
</html>`
|
||||||
|
@ -287,9 +296,9 @@ func serveHtmlHandler(paths []string, re regexp.Regexp) appHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
newUrl := fmt.Sprintf("%v%v%v",
|
newUrl := fmt.Sprintf("http://%v/%v%v",
|
||||||
r.URL.Host,
|
r.Host,
|
||||||
url.PathEscape(filepath.Clean(filePath)),
|
preparePath(filePath),
|
||||||
generateQueryParams(&filters, sortOrder),
|
generateQueryParams(&filters, sortOrder),
|
||||||
)
|
)
|
||||||
http.Redirect(w, r, newUrl, RedirectStatusCode)
|
http.Redirect(w, r, newUrl, RedirectStatusCode)
|
||||||
|
@ -313,9 +322,9 @@ 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,
|
||||||
url.PathEscape(filepath.Clean(filePath)),
|
preparePath(filePath),
|
||||||
generateQueryParams(&filters, sortOrder),
|
generateQueryParams(&filters, sortOrder),
|
||||||
)
|
)
|
||||||
http.Redirect(w, r, newUrl, RedirectStatusCode)
|
http.Redirect(w, r, newUrl, RedirectStatusCode)
|
||||||
|
@ -357,9 +366,9 @@ func serveHtmlHandler(paths []string, re regexp.Regexp) appHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
newUrl := fmt.Sprintf("%v%v%v",
|
newUrl := fmt.Sprintf("http://%v/%v%v",
|
||||||
r.URL.Host,
|
r.Host,
|
||||||
url.PathEscape(filepath.Clean(filePath)),
|
preparePath(filePath),
|
||||||
generateQueryParams(&filters, sortOrder),
|
generateQueryParams(&filters, sortOrder),
|
||||||
)
|
)
|
||||||
http.Redirect(w, r, newUrl, RedirectStatusCode)
|
http.Redirect(w, r, newUrl, RedirectStatusCode)
|
||||||
|
@ -383,9 +392,9 @@ 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,
|
||||||
url.PathEscape(filepath.Clean(filePath)),
|
preparePath(filePath),
|
||||||
generateQueryParams(&filters, sortOrder),
|
generateQueryParams(&filters, sortOrder),
|
||||||
)
|
)
|
||||||
http.Redirect(w, r, newUrl, RedirectStatusCode)
|
http.Redirect(w, r, newUrl, RedirectStatusCode)
|
||||||
|
@ -453,8 +462,8 @@ func ServePage(args []string) error {
|
||||||
|
|
||||||
re := regexp.MustCompile(`(.+)([0-9]{3})(\..+)`)
|
re := regexp.MustCompile(`(.+)([0-9]{3})(\..+)`)
|
||||||
|
|
||||||
http.Handle(PREFIX+"/", http.StripPrefix(PREFIX, serveStaticFileHandler(paths)))
|
|
||||||
http.Handle("/", serveHtmlHandler(paths, *re))
|
http.Handle("/", serveHtmlHandler(paths, *re))
|
||||||
|
http.Handle(PREFIX+"/", http.StripPrefix(PREFIX, serveStaticFileHandler(paths)))
|
||||||
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)
|
||||||
|
|
Loading…
Reference in New Issue