mirror of
https://github.com/usememos/memos.git
synced 2025-02-19 12:50:41 +01:00
fix: version checker
This commit is contained in:
parent
363c107359
commit
342d1aeefb
@ -110,7 +110,7 @@ func NewServer(ctx context.Context, profile *profile.Profile, store *store.Store
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) Start(ctx context.Context) error {
|
func (s *Server) Start(ctx context.Context) error {
|
||||||
go versionchecker.NewVersionChecker(s.Store).Start(ctx)
|
go versionchecker.NewVersionChecker(s.Store, s.Profile).Start(ctx)
|
||||||
go s.telegramBot.Start(ctx)
|
go s.telegramBot.Start(ctx)
|
||||||
go s.backupRunner.Run(ctx)
|
go s.backupRunner.Run(ctx)
|
||||||
|
|
||||||
|
@ -11,18 +11,21 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
storepb "github.com/usememos/memos/proto/gen/store"
|
storepb "github.com/usememos/memos/proto/gen/store"
|
||||||
|
"github.com/usememos/memos/server/profile"
|
||||||
"github.com/usememos/memos/server/version"
|
"github.com/usememos/memos/server/version"
|
||||||
"github.com/usememos/memos/store"
|
"github.com/usememos/memos/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
// nolint
|
// nolint
|
||||||
type VersionChecker struct {
|
type VersionChecker struct {
|
||||||
Store *store.Store
|
Store *store.Store
|
||||||
|
Profile *profile.Profile
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewVersionChecker(store *store.Store) *VersionChecker {
|
func NewVersionChecker(store *store.Store, profile *profile.Profile) *VersionChecker {
|
||||||
return &VersionChecker{
|
return &VersionChecker{
|
||||||
Store: store,
|
Store: store,
|
||||||
|
Profile: profile,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,20 +50,11 @@ func (*VersionChecker) GetLatestVersion() (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *VersionChecker) Check(ctx context.Context) {
|
func (c *VersionChecker) Check(ctx context.Context) {
|
||||||
migrationHistories, err := c.Store.FindMigrationHistoryList(ctx, &store.FindMigrationHistory{})
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if len(migrationHistories) == 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
lastVersion := migrationHistories[0].Version
|
|
||||||
latestVersion, err := c.GetLatestVersion()
|
latestVersion, err := c.GetLatestVersion()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !version.IsVersionGreaterThan(latestVersion, lastVersion) {
|
if !version.IsVersionGreaterThan(latestVersion, version.GetCurrentVersion(c.Profile.Mode)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,15 +65,16 @@ func (c *VersionChecker) Check(ctx context.Context) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if len(list) == 0 {
|
|
||||||
return
|
shouldNotify := true
|
||||||
|
if len(list) > 0 {
|
||||||
|
latestVersionUpdateActivity := list[0]
|
||||||
|
if latestVersionUpdateActivity.Payload != nil && version.IsVersionGreaterOrEqualThan(latestVersionUpdateActivity.Payload.VersionUpdate.Version, latestVersion) {
|
||||||
|
shouldNotify = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
latestVersionUpdateActivity := list[0]
|
if !shouldNotify {
|
||||||
if latestVersionUpdateActivity.Payload == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if version.IsVersionGreaterOrEqualThan(latestVersionUpdateActivity.Payload.VersionUpdate.Version, latestVersion) {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestGetLatestVersion(t *testing.T) {
|
func TestGetLatestVersion(t *testing.T) {
|
||||||
_, err := NewVersionChecker(nil).GetLatestVersion()
|
_, err := NewVersionChecker(nil, nil).GetLatestVersion()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user