This commit is contained in:
Philip Peterson 2026-05-26 01:05:37 -07:00
parent 1e51831b5d
commit 0c30391f54
5 changed files with 71 additions and 7 deletions

View file

@ -332,21 +332,20 @@ func linuxFormatToggle(dl DownloadProps) Node {
appImageHref := fmt.Sprintf("/download?os=linux&arch=%s", dl.SelectedArch)
rpmHref := fmt.Sprintf("/download?os=linux-rpm&arch=%s", dl.SelectedArch)
activeCls := "font-mono text-xs font-semibold text-white"
inactiveCls := "font-mono text-xs text-zinc-500 hover:text-zinc-300 transition-colors"
selectedCls := "inline-flex items-center rounded-md bg-emerald-500 px-3 py-1.5 font-mono text-xs font-semibold text-black"
unselectedCls := "inline-flex items-center rounded-md border border-zinc-700 bg-zinc-900 px-3 py-1.5 font-mono text-xs text-zinc-300 hover:border-zinc-500 hover:text-white transition-colors"
appImageCls := activeCls
rpmCls := inactiveCls
appImageCls := selectedCls
rpmCls := unselectedCls
if isRPM {
appImageCls = inactiveCls
rpmCls = activeCls
appImageCls = unselectedCls
rpmCls = selectedCls
}
return Div(Class("mt-4"),
P(Class("font-mono text-xs uppercase tracking-widest text-zinc-500 mb-3"), Text("Format")),
Div(Class("flex items-center gap-2"),
A(Href(appImageHref), Class(appImageCls), Text("AppImage")),
Span(Class("font-mono text-xs text-zinc-700"), Text("|")),
A(Href(rpmHref), Class(rpmCls), Text("RPM")),
),
)

20
http/refresh.go Normal file
View file

@ -0,0 +1,20 @@
package http
import (
"fmt"
"net/http"
"github.com/go-chi/chi/v5"
)
// InternalRefresh registers POST /internal/refresh to force an immediate GitHub release cache refresh.
func (s *Server) InternalRefresh(r chi.Router) {
r.Post("/internal/refresh", func(w http.ResponseWriter, r *http.Request) {
if err := s.releases.ForceRefresh(r.Context()); err != nil {
http.Error(w, "refresh failed: "+err.Error(), http.StatusBadGateway)
return
}
w.Header().Set("Content-Type", "text/plain")
fmt.Fprintln(w, "ok")
})
}

View file

@ -34,6 +34,30 @@ func (c *ReleaseCache) Get() []html.Release {
return c.releases
}
// ForceRefresh does a blocking, unconditional fetch regardless of cache age.
// It waits for any in-progress fetch to finish before starting its own.
func (c *ReleaseCache) ForceRefresh(ctx context.Context) error {
c.fetchMu.Lock()
defer c.fetchMu.Unlock()
releases, err := fetchReleases(ctx)
if err != nil {
c.log.Warn("Force refresh failed", "error", err)
return err
}
if len(releases) == 0 {
return nil
}
c.mu.Lock()
c.releases = releases
c.lastFetched = time.Now()
c.mu.Unlock()
c.log.Info("Force-refreshed releases from GitHub", "count", len(releases))
return nil
}
// TryRefresh fetches fresh releases if the cache is older than minAge.
// If a fetch is already in progress it returns immediately (non-blocking).
func (c *ReleaseCache) TryRefresh(ctx context.Context, minAge time.Duration) {

View file

@ -8,6 +8,8 @@ import (
// setupRoutes for the server.
func (s *Server) setupRoutes() {
s.InternalRefresh(s.mux)
s.mux.Group(func(r chi.Router) {
r.Use(middleware.Compress(5))

19
scripts/refresh-releases.sh Executable file
View file

@ -0,0 +1,19 @@
#!/bin/sh
# Force an immediate re-fetch of GitHub release assets.
# Usage (from host): ./scripts/refresh-releases.sh [http://host:8081]
# Usage (in container): ./scripts/refresh-releases.sh
set -e
url="${1:-http://localhost:8081}/internal/refresh"
if command -v curl >/dev/null 2>&1; then
curl -fsS -X POST "$url"
elif command -v wget >/dev/null 2>&1; then
wget -q -O- --post-data='' "$url"
else
echo "error: curl or wget required" >&2
exit 1
fi
echo
echo "Releases refreshed."