Skip to content

High performance, self-hosted, newsletter and mailing list manager with a modern dashboard. Single binary app.

Refactor update check.

Kailash Nadh4eabd967d819
diff --git a/cmd/updates.go b/cmd/updates.go
index 3f792a3b..18996172 100644
--- a/cmd/updates.go
+++ b/cmd/updates.go
@@ -10,18 +10,25 @@ import (
"golang.org/x/mod/semver"
)
-const updateCheckURL = "https://api.github.com/repos/knadh/listmonk/releases/latest"
+const updateCheckURL = "https://update.listmonk.app/update.json"
-type remoteUpdateResp struct {
- Version string `json:"tag_name"`
- URL string `json:"html_url"`
-}
-
-// AppUpdate contains information of a new update available to the app that
-// is sent to the frontend.
type AppUpdate struct {
- Version string `json:"version"`
- URL string `json:"url"`
+ Update struct {
+ ReleaseVersion string `json:"release_version"`
+ ReleaseDate string `json:"release_date"`
+ URL string `json:"url"`
+ Description string `json:"description"`
+
+ // This is computed and set locally based on the local version.
+ IsNew bool `json:"is_new"`
+ } `json:"update"`
+ Messages []struct {
+ Date string `json:"date"`
+ Title string `json:"title"`
+ Description string `json:"description"`
+ URL string `json:"url"`
+ Priority string `json:"priority"`
+ } `json:"messages"`
}
var reSemver = regexp.MustCompile(`-(.*)`)
@@ -32,11 +39,12 @@ var reSemver = regexp.MustCompile(`-(.*)`)
func checkUpdates(curVersion string, interval time.Duration, app *App) {
// Strip -* suffix.
curVersion = reSemver.ReplaceAllString(curVersion, "")
- time.Sleep(time.Second * 1)
- ticker := time.NewTicker(interval)
- defer ticker.Stop()
- for range ticker.C {
+ // Give a 15 minute buffer after app start in case the admin wants to disable
+ // update checks entirely and not make a request to upstream.
+ time.Sleep(time.Minute * 1)
+
+ for {
resp, err := http.Get(updateCheckURL)
if err != nil {
app.log.Printf("error checking for remote update: %v", err)
@@ -55,25 +63,25 @@ func checkUpdates(curVersion string, interval time.Duration, app *App) {
}
resp.Body.Close()
- var up remoteUpdateResp
- if err := json.Unmarshal(b, &up); err != nil {
+ var out AppUpdate
+ if err := json.Unmarshal(b, &out); err != nil {
app.log.Printf("error unmarshalling remote update payload: %v", err)
continue
}
// There is an update. Set it on the global app state.
- if semver.IsValid(up.Version) {
- v := reSemver.ReplaceAllString(up.Version, "")
+ if semver.IsValid(out.Update.ReleaseVersion) {
+ v := reSemver.ReplaceAllString(out.Update.ReleaseVersion, "")
if semver.Compare(v, curVersion) > 0 {
- app.Lock()
- app.update = &AppUpdate{
- Version: up.Version,
- URL: up.URL,
- }
- app.Unlock()
-
- app.log.Printf("new update %s found", up.Version)
+ out.Update.IsNew = true
+ app.log.Printf("new update %s found", out.Update.ReleaseVersion)
}
}
+
+ app.Lock()
+ app.update = &out
+ app.Unlock()
+
+ time.Sleep(interval)
}
}
diff --git a/frontend/.eslintrc.js b/frontend/.eslintrc.js
index ce9a9faf..54e014fd 100644
--- a/frontend/.eslintrc.js
+++ b/frontend/.eslintrc.js
@@ -21,6 +21,7 @@ module.exports = {
'vue/max-attributes-per-line': 'off',
'vue/html-indent': 'off',
'vue/html-closing-bracket-newline': 'off',
+ 'vue/singleline-html-element-content-newline': 'off',
'vue/max-len': ['error', {
code: 200,
template: 200,
diff --git a/frontend/src/App.vue b/frontend/src/App.vue
index 7ce1ba3a..d5e1f488 100644
--- a/frontend/src/App.vue
+++ b/frontend/src/App.vue
@@ -58,10 +58,24 @@
{{ $t('settings.restart') }}
</b-button>
</div>
- <div v-if="serverConfig.update" class="notification is-success">
- {{ $t('settings.updateAvailable', { version: serverConfig.update.version }) }}
- <a :href="serverConfig.update.url" target="_blank" rel="noopener noreferer">View</a>
+
+ <div v-if="serverConfig.update.update.is_new" class="notification is-success">
+ {{ $t('settings.updateAvailable', {
+ version: `${serverConfig.update.update.release_version}
+ (${$utils.getDate(serverConfig.update.update.release_date).format('DD MMM YY')})`,
+ }) }}
+ <a :href="serverConfig.update.update.url" target="_blank" rel="noopener noreferer">View</a>
</div>
+
+ <template v-if="serverConfig.update.messages && serverConfig.update.messages.length > 0">
+ <div v-for="m in serverConfig.update.messages" class="notification"
+ :class="{ [m.priority === 'high' ? 'is-danger' : 'is-info']: true }" :key="m.title">
+ <h3 class="is-size-5" v-if="m.title"><strong>{{ m.title }}</strong></h3>
+ <p v-if="m.description">{{ m.description }}</p>
+ <a v-if="m.url" :href="m.url" target="_blank" rel="noopener noreferer">View</a>
+ </div>
+ </template>
+
<div v-if="serverConfig.has_legacy_user" class="notification is-danger">
<b-icon icon="warning-empty" />
Remove the <code>admin_username</code> and <code>admin_password</code> fields from the TOML
diff --git a/frontend/src/assets/style.scss b/frontend/src/assets/style.scss
index 6c760609..b6a1d9ea 100644
--- a/frontend/src/assets/style.scss
+++ b/frontend/src/assets/style.scss
@@ -252,7 +252,7 @@ body.is-noscroll {
}
.notification {
padding: 10px 15px;
- border-left: 5px solid #eee;
+ border-left: 10px solid #eee;
&.is-danger {
background: $white-ter;
@@ -264,6 +264,11 @@ body.is-noscroll {
color: $black;
border-left-color: $green;
}
+ &.is-info {
+ background: $white-ter;
+ border-left-color: $primary;
+ color: $grey-dark;
+ }
}
/* WYSIWYG / HTML code editor */