package service import ( "time" "vidarchive/internal/models" "vidarchive/internal/repository" ) type SettingsService struct { repo *repository.SettingsRepository } func NewSettingsService(repo *repository.SettingsRepository) *SettingsService { return &SettingsService{repo: repo} } func (s *SettingsService) GetAll() (*models.Settings, error) { return s.repo.GetAll() } func (s *SettingsService) SetRefreshInterval(interval string) error { return s.repo.Set("refresh_interval", interval) } func (s *SettingsService) SetAutoRefreshLibrary(enabled bool) error { return s.repo.Set("auto_refresh_library", boolValue(enabled)) } func (s *SettingsService) SetAutoRefreshDownloads(enabled bool) error { return s.repo.Set("auto_refresh_downloads", boolValue(enabled)) } func boolValue(b bool) string { if b { return "1" } return "0" } func (s *SettingsService) SetToolAutoUpdate(enabled bool) error { return s.repo.Set("tool_auto_update", boolValue(enabled)) } func (s *SettingsService) SetJSRuntimeEnabled(enabled bool) error { return s.repo.Set("js_runtime_enabled", boolValue(enabled)) } // SetToolsCheckedAt is written before the update runs, not after: a crash mid // update must not make the scheduler retry on every tick. func (s *SettingsService) SetToolsCheckedAt(t time.Time) error { return s.repo.Set("tools_checked_at", t.Format(time.RFC3339)) } func (s *SettingsService) SetCookies(cookies string) error { return s.repo.Set("cookies", cookies) } func (s *SettingsService) GetCookies() (string, error) { return s.repo.Get("cookies") } // GetSessionSecret returns the secret that signs login cookies, "" when none has // been generated. It lives in the database so sessions survive a restart. func (s *SettingsService) GetSessionSecret() (string, error) { return s.repo.Get("session_secret") } func (s *SettingsService) SetSessionSecret(secret string) error { return s.repo.Set("session_secret", secret) }