From 153eb3df53492953759b43ab8b374a852ed2a98a Mon Sep 17 00:00:00 2001 From: Ralph Slooten Date: Sat, 28 Oct 2023 17:33:11 +1300 Subject: [PATCH] Fix: Correctly display "About" modal when update check fails (resolves #199) --- internal/updater/updater.go | 22 +++++++++++++++++++--- server/apiv1/info.go | 2 +- server/ui-src/components/AboutMailpit.vue | 6 +++++- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/internal/updater/updater.go b/internal/updater/updater.go index 4ea6bea..f980550 100644 --- a/internal/updater/updater.go +++ b/internal/updater/updater.go @@ -1,3 +1,4 @@ +// package Updater checks and downloads new versions package updater import ( @@ -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" ) @@ -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 diff --git a/server/apiv1/info.go b/server/apiv1/info.go index d0dd123..85afe9e 100644 --- a/server/apiv1/info.go +++ b/server/apiv1/info.go @@ -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 diff --git a/server/ui-src/components/AboutMailpit.vue b/server/ui-src/components/AboutMailpit.vue index 4e7add9..4c6cdfc 100644 --- a/server/ui-src/components/AboutMailpit.vue +++ b/server/ui-src/components/AboutMailpit.vue @@ -159,8 +159,12 @@ export default {