Skip to content

Commit

Permalink
Fix: Correctly display "About" modal when update check fails (resolves
Browse files Browse the repository at this point in the history
  • Loading branch information
axllent committed Oct 28, 2023
1 parent f29016a commit 153eb3d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
22 changes: 19 additions & 3 deletions internal/updater/updater.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// package Updater checks and downloads new versions
package updater

import (
Expand All @@ -6,13 +7,14 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"os/exec"
"path/filepath"
"runtime"
"time"

"github.com/axllent/mailpit/config"
"github.com/axllent/mailpit/internal/logger"
"github.com/axllent/semver"
)
Expand Down Expand Up @@ -49,13 +51,27 @@ type Release struct {
func GithubLatest(repo, name string) (string, string, string, error) {
releaseURL := fmt.Sprintf("https://api.github.com/repos/%s/releases", repo)

resp, err := http.Get(releaseURL) // #nosec
timeout := time.Duration(5 * time.Second)

client := http.Client{
Timeout: timeout,
}

req, err := http.NewRequest("GET", releaseURL, nil)
if err != nil {
return "", "", "", err
}

req.Header.Set("User-Agent", "Mailpit/"+config.Version)

resp, err := client.Do(req)
if err != nil {
return "", "", "", err
}

defer resp.Body.Close()

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)

if err != nil {
return "", "", "", err
Expand Down
2 changes: 1 addition & 1 deletion server/apiv1/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type appInformation struct {
}

// AppInfo returns some basic details about the running app, and latest release.
func AppInfo(w http.ResponseWriter, r *http.Request) {
func AppInfo(w http.ResponseWriter, _ *http.Request) {
// swagger:route GET /api/v1/info application AppInformation
//
// # Get application information
Expand Down
6 changes: 5 additions & 1 deletion server/ui-src/components/AboutMailpit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,12 @@ export default {
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">

<div class="alert alert-warning mb-3" v-if="mailbox.appInfo.LatestVersion == ''">
There might be a newer version available. The check failed.
</div>
<a class="btn btn-warning d-block mb-3"
v-if="mailbox.appInfo.Version != mailbox.appInfo.LatestVersion"
v-else-if="mailbox.appInfo.Version != mailbox.appInfo.LatestVersion"
:href="'https://github.com/axllent/mailpit/releases/tag/' + mailbox.appInfo.LatestVersion">
A new version of Mailpit ({{ mailbox.appInfo.LatestVersion }}) is available.
</a>
Expand Down

0 comments on commit 153eb3d

Please sign in to comment.