diff --git a/internal/api/stremio_ttl_test.go b/internal/api/stremio_ttl_test.go new file mode 100644 index 000000000..fd38665bd --- /dev/null +++ b/internal/api/stremio_ttl_test.go @@ -0,0 +1,34 @@ +package api + +import ( + "encoding/json" + "strings" + "testing" + + "github.com/javi11/altmount/internal/config" +) + +// TestStremioNzbTTLHoursZeroRoundTrip verifies that an explicit NzbTTLHours of 0 +// ("cache forever / disable expiry") survives serialization to the API response. +// A dropped 0 causes the frontend to fall back to its default of 24, silently +// overwriting the user's choice on the next save. +func TestStremioNzbTTLHoursZeroRoundTrip(t *testing.T) { + enabled := true + cfg := &config.Config{ + Stremio: config.StremioConfig{ + Enabled: &enabled, + NzbTTLHours: 0, + }, + } + + resp := ToConfigAPIResponse(cfg, "") + + data, err := json.Marshal(resp.Stremio) + if err != nil { + t.Fatalf("marshal stremio response: %v", err) + } + + if !strings.Contains(string(data), `"nzb_ttl_hours":0`) { + t.Errorf("expected nzb_ttl_hours:0 to be present in response JSON, got: %s", data) + } +} diff --git a/internal/api/types.go b/internal/api/types.go index 19c5ef62f..7ea1cd25c 100644 --- a/internal/api/types.go +++ b/internal/api/types.go @@ -204,7 +204,7 @@ type ArrsInstanceAPIResponse struct { // StremioAPIResponse sanitizes Stremio config for API responses type StremioAPIResponse struct { Enabled bool `json:"enabled"` - NzbTTLHours int `json:"nzb_ttl_hours,omitempty"` + NzbTTLHours int `json:"nzb_ttl_hours"` BaseURL string `json:"base_url,omitempty"` Prowlarr ProwlarrAPIResponse `json:"prowlarr"` } diff --git a/internal/config/manager.go b/internal/config/manager.go index 2678d8343..5eac2054c 100644 --- a/internal/config/manager.go +++ b/internal/config/manager.go @@ -173,7 +173,7 @@ type StremioConfig struct { // NzbTTLHours controls how long a completed NZB result is cached before // the same NZB is re-processed on the next request. // Set to 0 to disable expiry (cache forever). Defaults to 24 hours. - NzbTTLHours int `yaml:"nzb_ttl_hours" mapstructure:"nzb_ttl_hours" json:"nzb_ttl_hours,omitempty"` + NzbTTLHours int `yaml:"nzb_ttl_hours" mapstructure:"nzb_ttl_hours" json:"nzb_ttl_hours"` // BaseURL is the public base URL used when building Stremio stream links // (e.g. "https://altmount.example.com"). Falls back to the auto-detected // request origin when not set.