Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions internal/api/stremio_ttl_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
2 changes: 1 addition & 1 deletion internal/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand Down
2 changes: 1 addition & 1 deletion internal/config/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading