add: DB-backed settings UI for live-editable tunables
Add a settings page (/settings) and API (/api/settings GET/PUT) to edit encoding profiles (crf/preset per media type), lp, OMDb key, log retention, and delete-originals from the browser, persisted to a settings table in logs.db. config.yaml seeds the store on first run; afterwards the DB is the source of truth (paths.* and http_addr stay config-only). Each job snapshots the current settings, so changes apply to the next encode with no restart. PUT validates ranges (crf 0-63, preset 0-13, lp >=0, retention >=1) before persisting. No auth, by design for now (isolated network) — see #2. Closes #1
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
package settings
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"av1dae/pkg/types"
|
||||
)
|
||||
|
||||
func valid() Settings {
|
||||
return Settings{
|
||||
DVD: Profile{30, 2}, Bluray: Profile{29, 3}, WebDL: Profile{30, 3}, TVRip: Profile{32, 2},
|
||||
LP: 0, LogRetentionDays: 7,
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidate(t *testing.T) {
|
||||
if err := valid().Validate(); err != nil {
|
||||
t.Fatalf("valid settings rejected: %v", err)
|
||||
}
|
||||
bad := func(mut func(*Settings)) Settings { s := valid(); mut(&s); return s }
|
||||
cases := map[string]Settings{
|
||||
"crf too high": bad(func(s *Settings) { s.DVD.CRF = 64 }),
|
||||
"crf negative": bad(func(s *Settings) { s.Bluray.CRF = -1 }),
|
||||
"preset too high": bad(func(s *Settings) { s.WebDL.Preset = 14 }),
|
||||
"lp negative": bad(func(s *Settings) { s.LP = -1 }),
|
||||
"retention zero": bad(func(s *Settings) { s.LogRetentionDays = 0 }),
|
||||
}
|
||||
for name, s := range cases {
|
||||
if err := s.Validate(); err == nil {
|
||||
t.Errorf("%s: expected validation error, got nil", name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestProfileFor(t *testing.T) {
|
||||
s := valid()
|
||||
if s.ProfileFor(types.MediaTypeBluRay) != s.Bluray {
|
||||
t.Error("bluray profile mismatch")
|
||||
}
|
||||
if s.ProfileFor(types.MediaTypeWebDL) != s.WebDL {
|
||||
t.Error("webdl profile mismatch")
|
||||
}
|
||||
if s.ProfileFor(types.MediaType("anything-else")) != s.DVD {
|
||||
t.Error("unknown media type should fall back to DVD")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user