diff options
| -rw-r--r-- | roseh.moe.go | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/roseh.moe.go b/roseh.moe.go index 6ad701f..063a08a 100644 --- a/roseh.moe.go +++ b/roseh.moe.go @@ -321,6 +321,31 @@ func favicon(w http.ResponseWriter, r *http.Request) { serveStaticFile(w, r, "static/favicon.ico") } +func sharedFileHandler(w http.ResponseWriter, r *http.Request) { + fp, err := filepath.Localize(path.Clean(strings.TrimPrefix(r.URL.Path, "/"))) + if err != nil { + notFound(w, r) + return + } + f, err := os.OpenInRoot(filepath.Join(*nezuko, "www"), fp) + if err != nil { + notFound(w, r) + return + } + defer f.Close() + stat, err := f.Stat() + if err != nil { + log.Printf("Warning: sharedFileHandler: %s", err) + notFound(w, r) + return + } + if stat.IsDir() { + notFound(w, r) + return + } + http.ServeContent(w, r, fp, stat.ModTime(), f) +} + func qrHandler(w http.ResponseWriter, r *http.Request) { sig, err := base64.RawURLEncoding.DecodeString(r.FormValue("s")) if err != nil { @@ -1218,7 +1243,7 @@ func main() { apiMux := http.NewServeMux() apiMux.HandleFunc("PUT /api/wormhole/{name}", wormholeAPIUpload) mux.Handle("/api/", apiMux) - mux.Handle("/", &timeoutHandler{h: http.HandlerFunc(notFound), timeout: 5 * time.Minute}) + mux.Handle("/", &timeoutHandler{h: http.HandlerFunc(sharedFileHandler), timeout: 5 * time.Minute}) serverMux := http.NewServeMux() serverMux.Handle(selfURL.Hostname()+"/", http.NewCrossOriginProtection().Handler(&gzipHandler{mux})) jellyfinURL, err := url.Parse("http://127.0.0.1:8096") |
