Skip to content

Commit c87111d

Browse files
authored
Merge pull request #426 from damongolding/feature/about
Feature/about-latest-version
2 parents e870e4d + c3f57eb commit c87111d

2 files changed

Lines changed: 83 additions & 7 deletions

File tree

frontend/src/css/about.css

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ body {
3838
max-width: 31.25rem;
3939
width: 100%;
4040
margin: 0 auto;
41-
padding: 2rem;
41+
padding: 1.5rem;
4242
}
4343

4444
.logo {
@@ -57,12 +57,12 @@ body {
5757
position: relative;
5858
background-color: white;
5959
border-radius: 1rem;
60-
padding: 2rem;
60+
padding: 1.5rem;
6161
z-index: var(--z-base);
6262
}
6363

6464
h1 {
65-
font-size: 3rem;
65+
font-size: 2rem;
6666
font-weight: bold;
6767
color: #333;
6868
margin: 0.5rem 0 1.5rem 0;
@@ -75,25 +75,30 @@ h1 {
7575

7676
.stats > div {
7777
border-top: 1px solid #eee;
78-
padding: 1.3rem 0;
78+
padding: 1rem 0;
7979
}
8080

8181
.stats > div:last-child {
8282
padding-bottom: 0;
8383
}
8484

8585
.label {
86-
font-size: 1rem;
86+
font-size: 0.8rem;
8787
color: #6d727a;
8888
margin-bottom: 0.3rem;
8989
}
9090

9191
.value {
92-
font-size: 1.8rem;
92+
font-size: 1.5rem;
9393
font-weight: bold;
9494
color: black;
9595
}
9696

97+
.value a {
98+
color: black;
99+
text-underline-offset: 0.3rem;
100+
}
101+
97102
.value .service-online {
98103
margin-top: 0.3rem;
99104
padding: 0.5rem 1rem;

internal/templates/views/views_about.templ

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@ package views
22

33
import (
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

1519
templ About(viewData common.ViewData) {
@@ -36,6 +40,7 @@ css background(service string) {
3640
}
3741

3842
templ 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

Comments
 (0)