diff --git a/cmd/main.go b/cmd/main.go index d058c894..2f6ede20 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -13,6 +13,7 @@ import ( _ "github.com/mickael-kerjean/filestash/server/pkg" _ "github.com/mickael-kerjean/filestash/server/plugin" + "github.com/mickael-kerjean/filestash/server/pkg/env" "github.com/mickael-kerjean/filestash/server/pkg/extension" "github.com/mickael-kerjean/filestash/server/pkg/workflow" @@ -40,7 +41,7 @@ func Run(router *mux.Router) { } server.Build(router) server.PluginRoutes(router) - if os.Getenv("DEBUG") == "true" { + if env.DEBUG { server.DebugRoutes(router) } server.CatchAll(router) diff --git a/embed.go b/embed.go index 450b52f9..2844b2f5 100644 --- a/embed.go +++ b/embed.go @@ -5,6 +5,8 @@ import ( "io/fs" "net/http" "os" + + . "github.com/mickael-kerjean/filestash/server/pkg/env" ) var ( @@ -17,7 +19,7 @@ var ( var EmbedPluginList []byte func init() { - if os.Getenv("DEBUG") != "true" { + if !DEBUG { fsPublic, _ := fs.Sub(wwwPublic, "public") WWWPublic = http.FS(fsPublic) } diff --git a/server/pkg/env/constants.go b/server/pkg/env/constants.go index 71162d85..6302e020 100644 --- a/server/pkg/env/constants.go +++ b/server/pkg/env/constants.go @@ -12,6 +12,7 @@ var ( APPNAME = "Filestash" BASE = strings.TrimSuffix(os.Getenv("FILESTASH_BASE"), "/") LICENSE = "agpl" + DEBUG = os.Getenv("DEBUG") == "true" CONFIG_PATH = fromPath("state/config/") CERT_PATH = fromPath("state/certs/") diff --git a/server/pkg/frontend/static.go b/server/pkg/frontend/static.go index f85f8908..973d08fd 100644 --- a/server/pkg/frontend/static.go +++ b/server/pkg/frontend/static.go @@ -20,13 +20,13 @@ import ( . "github.com/mickael-kerjean/filestash" + "github.com/mickael-kerjean/filestash/server/pkg/compress" . "github.com/mickael-kerjean/filestash/server/pkg/config" . "github.com/mickael-kerjean/filestash/server/pkg/core" . "github.com/mickael-kerjean/filestash/server/pkg/env" . "github.com/mickael-kerjean/filestash/server/pkg/kernel" . "github.com/mickael-kerjean/filestash/server/pkg/mime" . "github.com/mickael-kerjean/filestash/server/pkg/utils" - "github.com/mickael-kerjean/filestash/server/pkg/compress" "github.com/bluekeyes/go-gitdiff/gitdiff" ) @@ -400,7 +400,6 @@ var preload = [][]string{ } func ServeBundle() func(*App, http.ResponseWriter, *http.Request) { - isDebug := os.Getenv("DEBUG") == "true" buildChunks := func(quality int) (chunks [][]byte, chunksBr [][]byte, chunksGzip [][]byte, etags []string) { numChunks := len(preload) chunks = make([][]byte, numChunks+1) @@ -448,13 +447,13 @@ func ServeBundle() func(*App, http.ResponseWriter, *http.Request) { } quality := 11 - if isDebug || runtime.NumCPU() <= 4 { + if DEBUG || runtime.NumCPU() <= 4 { quality = 8 } chunks, chunksBr, chunksGzip, etags := buildChunks(quality) return func(ctx *App, res http.ResponseWriter, req *http.Request) { - if isDebug { + if DEBUG { chunks, chunksBr, chunksGzip, etags = buildChunks(quality) } chunkIndex := 0 @@ -507,6 +506,9 @@ func applyPatch(filePath string) (file *bytes.Buffer) { patchFiles, _, err := gitdiff.Parse(NewReadCloserFromBytes(patch)) if err != nil { Log.Debug("ctrl::static cannot parse patch file - %s", err.Error()) + if DEBUG { + os.Exit(1) + } return nil } for i := 0; i < len(patchFiles); i++ { @@ -522,6 +524,9 @@ func applyPatch(filePath string) (file *bytes.Buffer) { patchFiles[i], ); err != nil { Log.Debug("ctrl::static err=cannot_apply_patch path=%s err=%s", patchFiles[i].NewName, err.Error()) + if DEBUG { + os.Exit(1) + } return nil } outputBuffer = patched