diff --git a/backend/app/api/bgrunner.go b/backend/app/api/bgrunner.go index ce4b7cca..9f56059b 100644 --- a/backend/app/api/bgrunner.go +++ b/backend/app/api/bgrunner.go @@ -23,8 +23,9 @@ func NewTask(name string, interval time.Duration, fn func(context.Context)) *Bac } func (tsk *BackgroundTask) Start(ctx context.Context) error { + tsk.Fn(ctx) + timer := time.NewTimer(tsk.Interval) - for { select { case <-ctx.Done(): diff --git a/backend/app/api/handlers/v1/controller.go b/backend/app/api/handlers/v1/controller.go index 43607113..aae9aee6 100644 --- a/backend/app/api/handlers/v1/controller.go +++ b/backend/app/api/handlers/v1/controller.go @@ -84,13 +84,14 @@ type ( } APISummary struct { - Healthy bool `json:"health"` - Versions []string `json:"versions"` - Title string `json:"title"` - Message string `json:"message"` - Build Build `json:"build"` - Demo bool `json:"demo"` - AllowRegistration bool `json:"allowRegistration"` + Healthy bool `json:"health"` + Versions []string `json:"versions"` + Title string `json:"title"` + Message string `json:"message"` + Build Build `json:"build"` + Latest services.Latest `json:"latest"` + Demo bool `json:"demo"` + AllowRegistration bool `json:"allowRegistration"` } ) @@ -123,6 +124,7 @@ func (ctrl *V1Controller) HandleBase(ready ReadyFunc, build Build) errchain.Hand Title: "Homebox", Message: "Track, Manage, and Organize your Things", Build: build, + Latest: ctrl.svc.BackgroundService.GetLatestVersion(), Demo: ctrl.isDemo, AllowRegistration: ctrl.allowRegistration, }) diff --git a/backend/app/api/main.go b/backend/app/api/main.go index 96d0fdab..6363296a 100644 --- a/backend/app/api/main.go +++ b/backend/app/api/main.go @@ -254,6 +254,18 @@ func run(cfg *config.Config) error { } })) + if cfg.Options.GithubReleaseCheck { + runner.AddPlugin(NewTask("get-latest-github-release", time.Hour, func(ctx context.Context) { + log.Debug().Msg("running get latest github release") + err := app.services.BackgroundService.GetLatestGithubRelease(context.Background()) + if err != nil { + log.Error(). + Err(err). + Msg("failed to get latest github release") + } + })) + } + if cfg.Debug.Enabled { runner.AddFunc("debug", func(ctx context.Context) error { debugserver := http.Server{ diff --git a/backend/app/api/static/docs/docs.go b/backend/app/api/static/docs/docs.go index f8840104..9cf65996 100644 --- a/backend/app/api/static/docs/docs.go +++ b/backend/app/api/static/docs/docs.go @@ -2950,6 +2950,17 @@ const docTemplate = `{ } } }, + "services.Latest": { + "type": "object", + "properties": { + "date": { + "type": "string" + }, + "version": { + "type": "string" + } + } + }, "services.UserRegistration": { "type": "object", "properties": { @@ -2982,6 +2993,9 @@ const docTemplate = `{ "health": { "type": "boolean" }, + "latest": { + "$ref": "#/definitions/services.Latest" + }, "message": { "type": "string" }, diff --git a/backend/app/api/static/docs/swagger.json b/backend/app/api/static/docs/swagger.json index 3077c6cc..8006ab90 100644 --- a/backend/app/api/static/docs/swagger.json +++ b/backend/app/api/static/docs/swagger.json @@ -2943,6 +2943,17 @@ } } }, + "services.Latest": { + "type": "object", + "properties": { + "date": { + "type": "string" + }, + "version": { + "type": "string" + } + } + }, "services.UserRegistration": { "type": "object", "properties": { @@ -2975,6 +2986,9 @@ "health": { "type": "boolean" }, + "latest": { + "$ref": "#/definitions/services.Latest" + }, "message": { "type": "string" }, diff --git a/backend/app/api/static/docs/swagger.yaml b/backend/app/api/static/docs/swagger.yaml index a46b6112..ee6ba80e 100644 --- a/backend/app/api/static/docs/swagger.yaml +++ b/backend/app/api/static/docs/swagger.yaml @@ -654,6 +654,13 @@ definitions: value: type: number type: object + services.Latest: + properties: + date: + type: string + version: + type: string + type: object services.UserRegistration: properties: email: @@ -675,6 +682,8 @@ definitions: type: boolean health: type: boolean + latest: + $ref: '#/definitions/services.Latest' message: type: string title: diff --git a/backend/internal/core/services/all.go b/backend/internal/core/services/all.go index 87cd3feb..0609080a 100644 --- a/backend/internal/core/services/all.go +++ b/backend/internal/core/services/all.go @@ -61,7 +61,7 @@ func New(repos *repo.AllRepos, opts ...OptionsFunc) *AllServices { repo: repos, autoIncrementAssetID: options.autoIncrementAssetID, }, - BackgroundService: &BackgroundService{repos}, + BackgroundService: &BackgroundService{repos, Latest{}}, Currencies: currencies.NewCurrencyService(options.currencies), } } diff --git a/backend/internal/core/services/service_background.go b/backend/internal/core/services/service_background.go index 1af8e1ba..5b0e60cf 100644 --- a/backend/internal/core/services/service_background.go +++ b/backend/internal/core/services/service_background.go @@ -2,6 +2,9 @@ package services import ( "context" + "encoding/json" + "fmt" + "net/http" "strings" "time" @@ -11,8 +14,13 @@ import ( "github.com/sysadminsmedia/homebox/backend/internal/data/types" ) +type Latest struct { + Version string `json:"version"` + Date string `json:"date"` +} type BackgroundService struct { repos *repo.AllRepos + latest Latest } func (svc *BackgroundService) SendNotifiersToday(ctx context.Context) error { @@ -79,3 +87,52 @@ func (svc *BackgroundService) SendNotifiersToday(ctx context.Context) error { return nil } + +func (svc *BackgroundService) GetLatestGithubRelease(ctx context.Context) error { + url := "https://api.github.com/repos/sysadminsmedia/homebox/releases/latest" + + req, err := http.NewRequestWithContext(ctx, "GET", url, nil) + if err != nil { + return fmt.Errorf("failed to create latest version request: %w", err) + } + + req.Header.Set("User-Agent", "Homebox-Version-Checker") + + client := &http.Client{} + resp, err := client.Do(req) + if err != nil { + return fmt.Errorf("failed to make latest version request: %w", err) + } + defer func() { + err := resp.Body.Close() + if err != nil { + log.Printf("error closing latest version response body: %v", err) + } + }() + + if resp.StatusCode != http.StatusOK { + return fmt.Errorf("latest version unexpected status code: %d", resp.StatusCode) + } + + // ignoring fields that are not relevant + type Release struct { + ReleaseVersion string `json:"tag_name"` + PublishedAt time.Time `json:"published_at"` + } + + var release Release + if err := json.NewDecoder(resp.Body).Decode(&release); err != nil { + return fmt.Errorf("failed to decode latest version response: %w", err) + } + + svc.latest = Latest{ + Version: release.ReleaseVersion, + Date: release.PublishedAt.String(), + } + + return nil +} + +func (svc *BackgroundService) GetLatestVersion() (Latest) { + return svc.latest +} \ No newline at end of file diff --git a/backend/internal/sys/config/conf.go b/backend/internal/sys/config/conf.go index 8b7b23c3..0d177716 100644 --- a/backend/internal/sys/config/conf.go +++ b/backend/internal/sys/config/conf.go @@ -32,6 +32,7 @@ type Options struct { AllowRegistration bool `yaml:"disable_registration" conf:"default:true"` AutoIncrementAssetID bool `yaml:"auto_increment_asset_id" conf:"default:true"` CurrencyConfig string `yaml:"currencies"` + GithubReleaseCheck bool `yaml:"check_github_release" conf:"default:true"` } type DebugConf struct { diff --git a/docs/en/configure-homebox.md b/docs/en/configure-homebox.md index c2d2db69..e014080f 100644 --- a/docs/en/configure-homebox.md +++ b/docs/en/configure-homebox.md @@ -25,7 +25,7 @@ | HBOX_MAILER_FROM | | email from address to use | | HBOX_SWAGGER_HOST | 7745 | swagger host to use, if not set swagger will be disabled | | HBOX_SWAGGER_SCHEMA | `http` | swagger schema to use, can be one of: `http`, `https` | - +| HBOX_OPTIONS_CHECK_GITHUB_RELEASE | true | check for new github releases | ::: tip "CLI Arguments" If you're deploying without docker you can use command line arguments to configure the application. Run `homebox --help` for more information. @@ -55,6 +55,7 @@ OPTIONS --options-allow-registration/$HBOX_OPTIONS_ALLOW_REGISTRATION (default: true) --options-auto-increment-asset-id/$HBOX_OPTIONS_AUTO_INCREMENT_ASSET_ID (default: true) --options-currency-config/$HBOX_OPTIONS_CURRENCY_CONFIG +--options-check-github-release/$HBOX_OPTIONS_CHECK_GITHUB_RELEASE (default: true) --help/-h display this help message ``` ::: diff --git a/frontend/components/App/OutdatedModal.vue b/frontend/components/App/OutdatedModal.vue new file mode 100644 index 00000000..79697d5d --- /dev/null +++ b/frontend/components/App/OutdatedModal.vue @@ -0,0 +1,41 @@ + + + diff --git a/frontend/layouts/default.vue b/frontend/layouts/default.vue index 79d20294..d6d917f1 100644 --- a/frontend/layouts/default.vue +++ b/frontend/layouts/default.vue @@ -6,6 +6,7 @@ up the tree --> + @@ -100,10 +101,9 @@