Skip to content

Commit

Permalink
clock endpoint can cause a refresh on version mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
damongolding committed Sep 4, 2024
1 parent 384bb2a commit a235d2c
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 32 deletions.
6 changes: 4 additions & 2 deletions public/assets/js/kiosk.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"use strict";

(() => {
const kioskData = JSON.parse(
document.getElementById("kiosk-data").textContent,
);
Expand Down Expand Up @@ -100,4 +102,4 @@
startPolling();
}
});
}
})();
7 changes: 7 additions & 0 deletions routes/clock.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,18 @@ func Clock(baseConfig *config.Config) echo.HandlerFunc {
fmt.Println()
}

kioskVersionHeader := c.Request().Header.Get("kiosk-version")
requestId := utils.ColorizeRequestId(c.Response().Header().Get(echo.HeaderXRequestID))

// create a copy of the global config to use with this request
requestConfig := *baseConfig

// If kiosk version on client and server do not match refresh client.
if kioskVersionHeader != "" && KioskVersion != kioskVersionHeader {
c.Response().Header().Set("HX-Refresh", "true")
return c.String(http.StatusTemporaryRedirect, "")
}

err := requestConfig.ConfigWithOverrides(c)
if err != nil {
log.Error("err overriding config", "err", err)
Expand Down
7 changes: 4 additions & 3 deletions views/home.templ
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ templ paramForm(queries url.Values) {
</form>
}

templ clock(queries url.Values) {
templ clock(queries url.Values, kioskVersion string) {
<div
id="clock"
hx-get="/clock"
Expand All @@ -163,6 +163,7 @@ templ clock(queries url.Values) {
}
hx-trigger="load, every 13s"
hx-swap="innerHTML"
hx-headers={ fmt.Sprintf(`{"kiosk-version": "%s"}`, kioskVersion) }
></div>
}

Expand Down Expand Up @@ -191,7 +192,7 @@ templ Home(data PageData) {
<html lang="en">
<head>
<meta charset="UTF-8"/>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<meta name="version" content={ data.KioskVersion }/>
<title>Immich Kiosk</title>
Expand Down Expand Up @@ -235,7 +236,7 @@ templ Home(data PageData) {
@progressBar(data.Config.Refresh)
}
if !data.Config.DisableUi && data.Config.ShowTime {
@clock(data.Queries)
@clock(data.Queries, data.KioskVersion)
}
@menu()
@paramForm(data.Queries)
Expand Down
67 changes: 40 additions & 27 deletions views/home_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a235d2c

Please sign in to comment.