Fix serving live directories on Windows

This commit is contained in:
NielsAD
2020-04-13 11:46:49 +02:00
parent 1b24308736
commit 1bcc66add4
2 changed files with 4 additions and 3 deletions

5
fs.go
View File

@@ -383,7 +383,8 @@ interr:
}
func (fs *CachedFS) serveLive(w http.ResponseWriter, r *http.Request) {
p := cleanPath(filepath.Join(fs.Root, r.URL.Path))
p := filepath.Join(fs.Root, filepath.FromSlash(r.URL.Path), "_")
p = p[:len(p)-1]
resp := make(Files, 0)
search, err := regexp.Compile(escapeRegex(r.URL.Query().Get("q")))
@@ -406,7 +407,7 @@ func (fs *CachedFS) serveLive(w http.ResponseWriter, r *http.Request) {
return nil
}
f := File{Name: r[trim:]}
f := File{Name: filepath.ToSlash(r[trim:])}
if e.IsDir() {
f.Type = "d"
} else {

View File

@@ -88,7 +88,7 @@ func main() {
srv := &http.Server{Addr: *addr}
handleDefault := func(p string, h http.Handler) { http.Handle(p, realIP(*forwarded, h)) }
handleLimited := func(p string, h http.Handler) { handleDefault(p, limit.Handler(logRequest(http.StripPrefix(p, fs)))) }
handleLimited := func(p string, h http.Handler) { handleDefault(p, limit.Handler(logRequest(http.StripPrefix(p, h)))) }
handleLimited("/idx/", fs)
handleLimited("/dl/", nodir(http.FileServer(http.Dir(fs.Root))))