Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] check for new release and show the version on the UI #893

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion internal/models/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ package models
// HTMLData is a list of HTML fields to be rendered.
// It is exported so that the HTML template engine can render it.
type HTMLData struct {
Rows []HTMLRow
Rows []HTMLRow
Version string
UpdateAvailable bool
LatestVersion string
}

// HTMLRow contains HTML fields to be rendered
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/providers/porkbun/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (p *Provider) HTML() models.HTMLRow {
return models.HTMLRow{
Domain: fmt.Sprintf("<a href=\"http://%s\">%s</a>", p.BuildDomainName(), p.BuildDomainName()),
Owner: p.Owner(),
Provider: "<a href=\"https://www.porkbun.com/\">Porkbun DNS</a>",
Provider: "<a href=\"https://www.porkbun.com/\">Porkbun</a>",
IPVersion: p.ipVersion.String(),
}
}
Expand Down
15 changes: 14 additions & 1 deletion internal/server/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,20 @@ func (h *handlers) index(w http.ResponseWriter, _ *http.Request) {
row := record.HTML(h.timeNow())
htmlData.Rows = append(htmlData.Rows, row)
}
err := h.indexTemplate.ExecuteTemplate(w, "index.html", htmlData)

currentVersion := getCurrentVersion()
latestVersion, err := getLatestRelease()
if err != nil {
httpError(w, http.StatusInternalServerError, "failed getting latest release: "+err.Error())
return
}
htmlData.Version = currentVersion
if currentVersion != latestVersion {
htmlData.UpdateAvailable = true
htmlData.LatestVersion = latestVersion
}

err = h.indexTemplate.ExecuteTemplate(w, "index.html", htmlData)
if err != nil {
httpError(w, http.StatusInternalServerError, "failed generating webpage: "+err.Error())
}
Expand Down
2 changes: 2 additions & 0 deletions internal/server/ui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
</svg>
</a>
</div>
<div>{{.Version}} {{if .UpdateAvailable}} (Update Available: <a
href="https://github.com/qdm12/ddns-updater/releases/latest">{{.LatestVersion}}</a>){{end}}</div>
<div>by <a href="https://github.com/qdm12">Quentin McGaw</a> / UI reworked by <a
href="https://github.com/fuse314">Gottfried Mayer</a></div>
</footer>
Expand Down
31 changes: 31 additions & 0 deletions internal/server/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package server

import (
"encoding/json"
"net/http"
)

type GitHubRelease struct {
TagName string `json:"tag_name"`
}

func getLatestRelease() (string, error) {
resp, err := http.Get("https://api.github.com/repos/qdm12/ddns-updater/releases/latest")
if err != nil {
return "", err
}
defer resp.Body.Close()

var release GitHubRelease
if err := json.NewDecoder(resp.Body).Decode(&release); err != nil {
return "", err
}

return release.TagName, nil
}

// Add a function to get the current version
func getCurrentVersion() string {
// Replace with actual logic to get the current version
return "v2.9.0"
}