@@ -2,14 +2,18 @@ package views
22
33import (
44 " context"
5+ " encoding/json"
56 " fmt"
7+ " github.com/charmbracelet/log"
68 " github.com/damongolding/immich-kiosk/internal/common"
79 " github.com/damongolding/immich-kiosk/internal/config"
810 " github.com/damongolding/immich-kiosk/internal/immich"
911 " github.com/damongolding/immich-kiosk/internal/templates/partials"
1012 " golang.org/x/text/cases"
1113 " golang.org/x/text/language"
14+ " net/http"
1215 " strings"
16+ " time"
1317)
1418
1519templ About (viewData common.ViewData ) {
@@ -36,6 +40,7 @@ css background(service string) {
3640}
3741
3842templ Stats (service, version string , online bool ) {
43+ {{ tag , link := getLatestRelease (service, service) }}
3944 <section class ={ fmt.Sprintf (" about-container--%s " , service) }>
4045 <div class ={ fmt.Sprintf (" about-container--%s --content" , service) }>
4146 <div class ={ " background" , background (service) }></div >
@@ -47,7 +52,7 @@ templ Stats(service, version string, online bool) {
4752 <div class =" stats" >
4853 <div >
4954 <div class =" label" >
50- Version
55+ Current Version
5156 </div >
5257 <div class =" value" >
5358 if version == " " {
@@ -59,6 +64,22 @@ templ Stats(service, version string, online bool) {
5964 }
6065 </div >
6166 </div >
67+ <div >
68+ <div class =" label" >
69+ Latest Version
70+ </div >
71+ <div class =" value" >
72+ <a href ={ templ.SafeURL (link) }>
73+ if tag == " " {
74+ Unknown
75+ } else if strings.HasPrefix (tag, " v" ) {
76+ { tag }
77+ } else {
78+ v{ tag }
79+ }
80+ </a >
81+ </div >
82+ </div >
6283 <div >
6384 <div class =" label" >
6485 Online
@@ -86,3 +107,53 @@ func getImmichStats(immichUrl, immichApiKey string) (immich.ServerAboutResponse,
86107 a := immich.New (context.Background (), c)
87108 return a.AboutInfo ()
88109}
110+
111+ type GitHubRelease struct {
112+ TagName string ` json:"tag_name"`
113+ }
114+
115+ func getLatestRelease (owner , repo string ) (string , string ) {
116+
117+ switch repo {
118+ case " immich" :
119+ owner = " immich-app"
120+ repo = " immich"
121+ case " kiosk" :
122+ owner = " damongolding"
123+ repo = " immich-kiosk"
124+ }
125+
126+ url := fmt.Sprintf (" https://api.github.com/repos/%s /%s /releases/latest" , owner, repo)
127+ link := fmt.Sprintf (" https://github.com/%s /%s /releases/latest" , owner, repo)
128+
129+ client := &http.Client {
130+ Timeout: 10 * time.Second ,
131+ }
132+ req , err := http.NewRequest (" GET" , url, nil )
133+ if err != nil {
134+ log.Error (err)
135+ return " Unknown" , link
136+ }
137+
138+ resp , err := client.Do (req)
139+ if err != nil {
140+ log.Error (err)
141+ return " Unknown" , link
142+ }
143+ defer resp.Body .Close ()
144+
145+ if resp.StatusCode != 200 {
146+ log.Errorf (" GitHub API returned status code %d for %s " , resp.StatusCode , url)
147+ return " Unknown" , link
148+ }
149+
150+ var release GitHubRelease
151+ if err := json.NewDecoder (resp.Body ).Decode (&release); err != nil {
152+ log.Error (err)
153+ return " Unknown" , link
154+ }
155+
156+ link = fmt.Sprintf (" https://github.com/%s /%s /releases/tag/%s " , owner, repo, release.TagName )
157+
158+ return release.TagName , link
159+ }
0 commit comments