From d55b9f1279a40fcf2d4d87b777ae3178c572e969 Mon Sep 17 00:00:00 2001 From: Hans-Petter Fjeld Date: Tue, 1 Oct 2024 20:48:57 +0200 Subject: [PATCH] Attempted to implement --disable-dir-list --- cmd/serve/http/http.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/cmd/serve/http/http.go b/cmd/serve/http/http.go index 4a5d8da5a..5a74870af 100644 --- a/cmd/serve/http/http.go +++ b/cmd/serve/http/http.go @@ -114,6 +114,16 @@ type HTTP struct { ctx context.Context // for global config } +// Empty template for use with --disable-dir-list +const emptyDirListTemplate = ` + + + + + +` + + // Gets the VFS in use for this request func (s *HTTP) getVFS(ctx context.Context) (VFS *vfs.VFS, err error) { if s._vfs != nil { @@ -215,6 +225,17 @@ func (s *HTTP) serveDir(w http.ResponseWriter, r *http.Request, dirRemote string serve.Error(ctx, dirRemote, w, "Failed to list directory", err) return } + if Opt.DisableDirList { + // Render the empty template + w.Header().Set("Content-Type", "text/html; charset=utf-8") + _, err := w.Write([]byte(emptyDirListTemplate)) + if err != nil { + // Handle write error + http.Error(w, "Internal Server Error", http.StatusInternalServerError) + } + return + } else { + // Make the entries for display directory := serve.NewDirectory(dirRemote, s.server.HTMLTemplate())