diff options
| author | Julian Hurst <ark@mansus.space> | 2025-04-10 02:03:33 +0200 |
|---|---|---|
| committer | Julian Hurst <ark@mansus.space> | 2025-04-10 02:03:33 +0200 |
| commit | caab30c96ba0ac436e0a6b8211ea32c2e396a8cf (patch) | |
| tree | 5e0883b2f39620a3bbc29e3e3b7a460259eb46bd /main.go | |
| parent | 3548e8f91c86170a29c2e6f20ede914c31358539 (diff) | |
| download | box-caab30c96ba0ac436e0a6b8211ea32c2e396a8cf.tar.gz | |
Add file listing support
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -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, "<span>Unauthorized: invalid token</span>") + return + } + http.ServeFile(w, r, filepath.Join(handler.filesPath)) } else { resourceId := path.Base(reqPath) resourcePath := filepath.Join(handler.filesPath, resourceId) |
