From febe6c217a18442af9bd9407e08e4a2323c60789 Mon Sep 17 00:00:00 2001 From: Turboman3000 <42318382+Turboman3000@users.noreply.github.com> Date: Thu, 7 Dec 2023 13:26:07 +0100 Subject: [PATCH] feat: download mode --- README.md | 1 + main.go | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 37d9524..1574b3e 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ Additionally, you can add the following flags: -log-requests # Log requests (this will slow down the server by ~40%) -index # The file to serve when the path ends in `/` (default=index.html) -spa # Make all 404 pages the index file, useful for SPA apps that use client side routing +-download # Enable downloading files ``` You can just add these to the end of the `docker run` command. diff --git a/main.go b/main.go index 426c0ac..e3ea544 100644 --- a/main.go +++ b/main.go @@ -19,6 +19,7 @@ var ( fLogRequests = flag.Bool("log-requests", false, "Log requests to stdout") fSPA = flag.Bool("spa", false, "Serve index.html for 404 pages (for SPA apps)") fIndex = flag.String("index", "index.html", "Index file relative from the files path") + fDownload = flag.Bool("download", false, "Enables direct Download for Served Files") ) func main() { @@ -49,6 +50,10 @@ func main() { app.Use(logger.New()) } + if *fDownload { + log.Printf("Enabling downloads") + } + if *fCompressLevel > 0 { log.Printf("Enabling compression: %d", *fCompressLevel) @@ -65,7 +70,7 @@ func main() { app.Static("/", *fFilePath, fiber.Static{ Compress: true, - Download: false, + Download: *fDownload, CacheDuration: *fCacheDuration, MaxAge: int((*fCacheDuration).Seconds()), ByteRange: true,