From 1bcc66add438b69cf8cd689c01884fcdb4601835 Mon Sep 17 00:00:00 2001 From: NielsAD Date: Mon, 13 Apr 2020 11:46:49 +0200 Subject: [PATCH] Fix serving live directories on Windows --- fs.go | 5 +++-- main.go | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/fs.go b/fs.go index 274cf0a..ca10de0 100644 --- a/fs.go +++ b/fs.go @@ -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 { diff --git a/main.go b/main.go index 28272a5..0c30576 100644 --- a/main.go +++ b/main.go @@ -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))))