From caab30c96ba0ac436e0a6b8211ea32c2e396a8cf Mon Sep 17 00:00:00 2001 From: Julian Hurst Date: Thu, 10 Apr 2025 02:03:33 +0200 Subject: Add file listing support --- main.go | 14 ++++++++++++++ templates/index.html | 22 +++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index df415b8..a08467d 100644 --- a/main.go +++ b/main.go @@ -23,6 +23,9 @@ import ( //go:embed templates var tmplFS embed.FS +//go:embed static +var staticFS embed.FS + //go:embed favicon.ico var favicon []byte @@ -61,6 +64,17 @@ func (handler BoxHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } if reqPath == "/" { serve(w, handler.token, "templates/index.html") + } else if strings.HasPrefix(reqPath, "/static") { + http.ServeFileFS(w, r, staticFS, reqPath) + } else if strings.HasPrefix(reqPath, "/getindex") { + token := r.Header.Get("X-Token") + if bcrypt.CompareHashAndPassword(handler.token, []byte(token)) != nil { + log.Println("unauthorized") + w.WriteHeader(http.StatusUnauthorized) + fmt.Fprint(w, "Unauthorized: invalid token") + return + } + http.ServeFile(w, r, filepath.Join(handler.filesPath)) } else { resourceId := path.Base(reqPath) resourcePath := filepath.Join(handler.filesPath, resourceId) diff --git a/templates/index.html b/templates/index.html index c06b6ec..7c77e8e 100644 --- a/templates/index.html +++ b/templates/index.html @@ -3,6 +3,7 @@ Box + + + +
  _
 | |__   _____  __
-- 
cgit v1.2.3