Skip to content

Commit e04882b

Browse files
author
Piotr
committed
new version update send to frontend
1 parent 7ddb7ed commit e04882b

File tree

3 files changed

+37
-15
lines changed

3 files changed

+37
-15
lines changed

http/client_handlers.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ func handleStatus(config *Config) func(w http.ResponseWriter, r *http.Request) {
4747
configStr = utils.LoadFile(config.ConfigFilePath)
4848
}
4949

50+
newVersion, _ := utils.IsNewVersionAvailable()
51+
5052
initMsg, _ := json.Marshal(models.InitMessage{
5153
BaseMessage: models.BaseMessage{
5254
MessageType: models.MessageTypeInit,
@@ -55,6 +57,7 @@ func handleStatus(config *Config) func(w http.ResponseWriter, r *http.Request) {
5557
AuthRequired: config.UiPass != "",
5658
ConfigStr: configStr,
5759
ApiPrefix: config.HttpPathPrefix,
60+
UpdateVersion: newVersion,
5861
})
5962

6063
w.Header().Add("content-type", "application/json")

models/message.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package models
22

3-
import "encoding/json"
3+
import (
4+
"encoding/json"
5+
)
46

57
type LogType int
68

@@ -51,10 +53,21 @@ type ClientMsgStatus struct {
5153
Stats Stats `json:"stats"`
5254
}
5355

56+
type LogdyVersionUpdateResponse struct {
57+
Checked bool `json:"checked"` // whether the new version was checked
58+
LocalVersion string `json:"local_version"`
59+
CurrentVersion string `json:"current_version"`
60+
CurrentVersionPublishedAt string `json:"current_version_published"`
61+
DownloadLink string `json:"download_link"`
62+
BlogLink string `json:"blog_link"`
63+
Excerpt string `json:"excerpt"`
64+
}
65+
5466
type InitMessage struct {
5567
BaseMessage
56-
AnalyticsEnabled bool `json:"analyticsEnabled"`
57-
AuthRequired bool `json:"authRequired"`
58-
ConfigStr string `json:"configStr"`
59-
ApiPrefix string `json:"apiPrefix"`
68+
AnalyticsEnabled bool `json:"analyticsEnabled"`
69+
AuthRequired bool `json:"authRequired"`
70+
ConfigStr string `json:"configStr"`
71+
ApiPrefix string `json:"apiPrefix"`
72+
UpdateVersion LogdyVersionUpdateResponse `json:"updateVersion"`
6073
}

utils/update.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"net/http"
77
"runtime"
88

9+
"github.com/logdyhq/logdy-core/models"
910
"github.com/sirupsen/logrus"
1011
)
1112

@@ -18,16 +19,8 @@ import (
1819
};
1920
*/
2021

21-
type UpdateResponse struct {
22-
CurrentVersion string `json:"current_version"`
23-
CurrentVersionPublishedAt string `json:"current_version_published"`
24-
DownloadLink string `json:"download_link"`
25-
BlogLink string `json:"blog_link"`
26-
Excerpt string `json:"excerpt"`
27-
}
28-
29-
func checkUpdates(version string) (UpdateResponse, error) {
30-
update := UpdateResponse{}
22+
func checkUpdates(version string) (models.LogdyVersionUpdateResponse, error) {
23+
update := models.LogdyVersionUpdateResponse{}
3124
resp, err := http.Get("https://update.logdy.dev?version=" + version)
3225
if err != nil {
3326
return update, err
@@ -59,7 +52,16 @@ func init() {
5952
}
6053
}
6154

55+
var UpdateVersionChecked = false
56+
var UpdateVersion models.LogdyVersionUpdateResponse
57+
58+
func IsNewVersionAvailable() (models.LogdyVersionUpdateResponse, bool) {
59+
return UpdateVersion, UpdateVersionChecked
60+
}
61+
6262
func CheckUpdatesAndPrintInfo(currentVersion string) {
63+
UpdateVersionChecked = true
64+
6365
update, err := checkUpdates(currentVersion)
6466

6567
if err != nil {
@@ -99,6 +101,10 @@ func CheckUpdatesAndPrintInfo(currentVersion string) {
99101
return
100102
}
101103

104+
UpdateVersion = update
105+
UpdateVersion.Checked = true
106+
UpdateVersion.LocalVersion = currentVersion
107+
102108
Logger.WithFields(logrus.Fields{
103109
"response": update,
104110
"current_version": currentVersion,

0 commit comments

Comments
 (0)