Compare commits

...
2 Commits
Author SHA1 Message Date
dwrz 495c89de0e Replace string context keys with typed constants 2026-06-09 23:28:29 +00:00
dwrz c158283f3d Reformat JS and CSS 2026-06-09 23:27:12 +00:00
3 changed files with 32 additions and 13 deletions
+17 -8
View File
@@ -33,6 +33,15 @@ import (
openai "github.com/sashabaranov/go-openai"
)
// Context keys for request-scoped values.
type key string
const (
logKey key = "log"
idKey key = "id"
ipKey key = "ip"
)
//go:embed all:static/*
var static embed.FS
@@ -189,9 +198,9 @@ func (svc *Service) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// Enrich context with request-scoped values.
ctx := r.Context()
ctx = context.WithValue(ctx, "log", log)
ctx = context.WithValue(ctx, "id", id)
ctx = context.WithValue(ctx, "ip", ip)
ctx = context.WithValue(ctx, logKey, log)
ctx = context.WithValue(ctx, idKey, id)
ctx = context.WithValue(ctx, ipKey, ip)
r = r.WithContext(ctx)
log.InfoContext(ctx, "handling")
@@ -346,7 +355,7 @@ func (svc *Service) JobCount() int {
func (svc *Service) home(w http.ResponseWriter, r *http.Request) {
var (
ctx = r.Context()
log = ctx.Value("log").(*slog.Logger)
log = ctx.Value(logKey).(*slog.Logger)
)
if r.URL.Path != "/" {
@@ -408,7 +417,7 @@ type Response struct {
func (svc *Service) voice(w http.ResponseWriter, r *http.Request) {
var (
ctx = r.Context()
log = ctx.Value("log").(*slog.Logger)
log = ctx.Value(logKey).(*slog.Logger)
)
// Parse request.
@@ -619,7 +628,7 @@ type StreamMessage struct {
func (svc *Service) voiceStream(w http.ResponseWriter, r *http.Request) {
var (
ctx = r.Context()
log = ctx.Value("log").(*slog.Logger)
log = ctx.Value(logKey).(*slog.Logger)
)
// Check that the response writer supports flushing.
@@ -848,7 +857,7 @@ func (svc *Service) voiceStream(w http.ResponseWriter, r *http.Request) {
func (svc *Service) models(w http.ResponseWriter, r *http.Request) {
var (
ctx = r.Context()
log = ctx.Value("log").(*slog.Logger)
log = ctx.Value(logKey).(*slog.Logger)
)
models, err := svc.llm.ListModels(ctx)
@@ -886,7 +895,7 @@ func (svc *Service) models(w http.ResponseWriter, r *http.Request) {
func (svc *Service) voices(w http.ResponseWriter, r *http.Request) {
var (
ctx = r.Context()
log = ctx.Value("log").(*slog.Logger)
log = ctx.Value(logKey).(*slog.Logger)
)
voices, err := svc.tts.ListVoices(ctx)
+12 -4
View File
@@ -474,10 +474,18 @@ body {
height: 1rem;
}
.scroll-icon--up { display: inline; }
.scroll-icon--down { display: none; }
#scroll.scrolled-up .scroll-icon--up { display: none; }
#scroll.scrolled-up .scroll-icon--down { display: inline; }
.scroll-icon--up {
display: inline;
}
.scroll-icon--down {
display: none;
}
#scroll.scrolled-up .scroll-icon--up {
display: none;
}
#scroll.scrolled-up .scroll-icon--down {
display: inline;
}
.footer__toolbar-btn--muted {
color: var(--color-red);
+3 -1
View File
@@ -218,7 +218,9 @@ class Odidere {
);
// Wake lock: reacquire on visibility change
this.document.addEventListener('visibilitychange', () => this.#handleVisibilityChange());
this.document.addEventListener('visibilitychange', () =>
this.#handleVisibilityChange(),
);
}
/**