This commit is contained in:
ponzischeme89
2026-08-27 07:31:57 +12:00
parent 394a6d9b57
commit b0b8990f90
24 changed files with 388 additions and 477 deletions
+13 -1
View File
@@ -47,6 +47,9 @@ type Config struct {
// the header travels to whatever Emby does with its logs, and the product name has
// no business being the thing that identifies a client to a third party.
ClientName string
// IgnoredClientName records a legacy MEMBY_CLIENT_NAME override that no longer takes
// effect. It is logged at start-up so a stale deployment can be corrected deliberately.
IgnoredClientName string
// GatewayClientName is reported instead for a request the gateway makes on its own
// behalf — the library sync, the health probe, device cleanup, and an operator
@@ -229,7 +232,8 @@ func Load() (Config, error) {
EmbyMediaURL: strings.TrimRight(os.Getenv("MEMBY_EMBY_MEDIA_URL"), "/"),
DatabaseURL: os.Getenv("MEMBY_DATABASE_URL"),
RedisURL: env("MEMBY_REDIS_URL", "redis://localhost:6379/0"),
ClientName: env("MEMBY_CLIENT_NAME", "MbyATV"),
ClientName: emby.DefaultClientName,
IgnoredClientName: ignoredClientName(),
GatewayClientName: env("MEMBY_GATEWAY_CLIENT_NAME", emby.DefaultGatewayClientName),
HomeTTL: duration("MEMBY_HOME_TTL", 60*time.Second),
ItemTTL: duration("MEMBY_ITEM_TTL", 10*time.Minute),
@@ -369,6 +373,14 @@ func secret(key string) (string, error) {
return trimmed, nil
}
func ignoredClientName() string {
raw := strings.TrimSpace(os.Getenv("MEMBY_CLIENT_NAME"))
if raw == "" || raw == emby.DefaultClientName {
return ""
}
return raw
}
func boolean(key string, fallback bool) bool {
raw := strings.TrimSpace(os.Getenv(key))
if raw == "" {
+19
View File
@@ -5,6 +5,8 @@ import (
"path/filepath"
"testing"
"time"
"github.com/ponzischeme89/memby/server/internal/emby"
)
func TestReleasePublishTokenCanComeFromSecretFile(t *testing.T) {
@@ -109,3 +111,20 @@ func TestAnalyticsRetentionCannotDropBelowThirtyDays(t *testing.T) {
t.Fatalf("analytics retention = %v, want 30 days", cfg.AnalyticsRetention)
}
}
func TestLegacyClientNameOverrideIsIgnored(t *testing.T) {
t.Setenv("MEMBY_EMBY_URL", "http://emby")
t.Setenv("MEMBY_DATABASE_URL", "postgres://memby")
t.Setenv("MEMBY_CLIENT_NAME", "Memby")
cfg, err := Load()
if err != nil {
t.Fatal(err)
}
if cfg.ClientName != emby.DefaultClientName {
t.Fatalf("client name = %q, want %q", cfg.ClientName, emby.DefaultClientName)
}
if cfg.IgnoredClientName != "Memby" {
t.Fatalf("ignored client name = %q, want Memby", cfg.IgnoredClientName)
}
}