mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 00:39:13 +00:00
feat: show new updates in dashboard (#690)
* feat: show new update banner * feat(http): add request logger * refactor: updates checker * feat: make update check optional * fix: empty releases * add toggle switch for update checks * feat: toggle updates check from settings * feat: toggle updates check from settings * feat: check on toggle enabled --------- Co-authored-by: soup <soup@r4tio.dev>
This commit is contained in:
parent
3fdd7cf5e4
commit
2917a7d42d
24 changed files with 687 additions and 121 deletions
|
@ -6,46 +6,42 @@ import (
|
|||
|
||||
"github.com/autobrr/autobrr/internal/domain"
|
||||
"github.com/autobrr/autobrr/internal/notification"
|
||||
"github.com/autobrr/autobrr/pkg/version"
|
||||
"github.com/autobrr/autobrr/internal/update"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
)
|
||||
|
||||
type CheckUpdatesJob struct {
|
||||
Name string
|
||||
Log zerolog.Logger
|
||||
Version string
|
||||
NotifSvc notification.Service
|
||||
Name string
|
||||
Log zerolog.Logger
|
||||
Version string
|
||||
NotifSvc notification.Service
|
||||
updateService *update.Service
|
||||
|
||||
lastCheckVersion string
|
||||
}
|
||||
|
||||
func (j *CheckUpdatesJob) Run() {
|
||||
v := version.Checker{
|
||||
Owner: "autobrr",
|
||||
Repo: "autobrr",
|
||||
}
|
||||
|
||||
newAvailable, newVersion, err := v.CheckNewVersion(context.TODO(), j.Version)
|
||||
newRelease, err := j.updateService.CheckUpdateAvailable(context.TODO())
|
||||
if err != nil {
|
||||
j.Log.Error().Err(err).Msg("could not check for new release")
|
||||
return
|
||||
}
|
||||
|
||||
if newAvailable {
|
||||
j.Log.Info().Msgf("a new release has been found: %v Consider updating.", newVersion)
|
||||
|
||||
if newRelease != nil {
|
||||
// this is not persisted so this can trigger more than once
|
||||
// lets check if we have different versions between runs
|
||||
if newVersion != j.lastCheckVersion {
|
||||
if newRelease.TagName != j.lastCheckVersion {
|
||||
j.Log.Info().Msgf("a new release has been found: %v Consider updating.", newRelease.TagName)
|
||||
|
||||
j.NotifSvc.Send(domain.NotificationEventAppUpdateAvailable, domain.NotificationPayload{
|
||||
Subject: "New update available!",
|
||||
Message: newVersion,
|
||||
Message: newRelease.TagName,
|
||||
Event: domain.NotificationEventAppUpdateAvailable,
|
||||
Timestamp: time.Now(),
|
||||
})
|
||||
}
|
||||
|
||||
j.lastCheckVersion = newVersion
|
||||
j.lastCheckVersion = newRelease.TagName
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue