diff --git a/lib/server/pages.go b/lib/server/pages.go index 99bd850..39db80c 100644 --- a/lib/server/pages.go +++ b/lib/server/pages.go @@ -24,6 +24,7 @@ func (app *App) handleIndex(ctx *gin.Context) { "UploadsEnabled": app.config.GuestUploadsEnabled && app.config.APIEnabled, "MaxFileSizeBytes": app.config.GlobalMaxFileSizeBytes, "MaxBoxSizeBytes": app.config.GlobalMaxBoxSizeBytes, + "AppVersion": app.appVersion, }) } diff --git a/lib/server/server.go b/lib/server/server.go index 3a85eb5..20f85ff 100644 --- a/lib/server/server.go +++ b/lib/server/server.go @@ -3,7 +3,9 @@ package server import ( "encoding/json" "html/template" + "os" "path/filepath" + "strings" "time" "github.com/gin-contrib/gzip" @@ -23,6 +25,7 @@ type App struct { activityStore *activity.Store alertStore *alerts.Store securityGuard *security.Guard + appVersion string } func Run(addr string) error { @@ -56,12 +59,14 @@ func Run(addr string) error { activityStore: activity.NewStore(filepath.Join(cfg.DBDir, "activity_log.json")), alertStore: alerts.NewStore(filepath.Join(cfg.DBDir, "alerts.json")), securityGuard: security.NewGuard(), + appVersion: currentAppVersion(), } if err := app.reloadSecurityConfig(); err != nil { return err } router := gin.Default() + router.Use(app.versionHeaderMiddleware()) router.Use(app.securityMiddleware()) router.NoRoute(app.handleNoRoute) htmlTemplates, err := loadHTMLTemplates() @@ -149,3 +154,18 @@ func (app *App) handleHealth(c *gin.Context) { "status": "healthy", }) } + +func (app *App) versionHeaderMiddleware() gin.HandlerFunc { + return func(ctx *gin.Context) { + ctx.Header("X-App-Version", app.appVersion) + ctx.Next() + } +} + +func currentAppVersion() string { + version := strings.TrimSpace(os.Getenv("APP_VERSION")) + if version == "" { + return "dev" + } + return version +} diff --git a/templates/index.html b/templates/index.html index f4dc05f..1290049 100644 --- a/templates/index.html +++ b/templates/index.html @@ -126,6 +126,7 @@
{{ if .UploadsEnabled }}Ready ยท drag files anywhere onto the window{{ else }}Guest uploads are disabled{{ end }} WarpBox + v{{ .AppVersion }}