settings.go
| 1 | package service |
| 2 | |
| 3 | import ( |
| 4 | "strconv" |
| 5 | "vidarchive/internal/models" |
| 6 | "vidarchive/internal/repository" |
| 7 | ) |
| 8 | |
| 9 | type SettingsService struct { |
| 10 | repo *repository.SettingsRepository |
| 11 | } |
| 12 | |
| 13 | func NewSettingsService(repo *repository.SettingsRepository) *SettingsService { |
| 14 | return &SettingsService{repo: repo} |
| 15 | } |
| 16 | |
| 17 | func (s *SettingsService) GetAll() (*models.Settings, error) { |
| 18 | return s.repo.GetAll() |
| 19 | } |
| 20 | |
| 21 | func (s *SettingsService) SetRefreshInterval(interval string) error { |
| 22 | return s.repo.Set("refresh_interval", interval) |
| 23 | } |
| 24 | |
| 25 | func (s *SettingsService) SetAutoRefreshLibrary(enabled bool) error { |
| 26 | val := "0" |
| 27 | if enabled { |
| 28 | val = "1" |
| 29 | } |
| 30 | return s.repo.Set("auto_refresh_library", val) |
| 31 | } |
| 32 | |
| 33 | func (s *SettingsService) SetAutoRefreshDownloads(enabled bool) error { |
| 34 | val := "0" |
| 35 | if enabled { |
| 36 | val = "1" |
| 37 | } |
| 38 | return s.repo.Set("auto_refresh_downloads", val) |
| 39 | } |
| 40 | |
| 41 | func (s *SettingsService) GetRefreshInterval() (int, error) { |
| 42 | val, err := s.repo.Get("refresh_interval") |
| 43 | if err != nil { |
| 44 | return 5, err |
| 45 | } |
| 46 | if val == "" { |
| 47 | return 5, nil |
| 48 | } |
| 49 | return strconv.Atoi(val) |
| 50 | } |
| 51 | |
| 52 | func (s *SettingsService) SetCookies(cookies string) error { |
| 53 | return s.repo.Set("cookies", cookies) |
| 54 | } |
| 55 | |
| 56 | func (s *SettingsService) GetCookies() (string, error) { |
| 57 | return s.repo.Get("cookies") |
| 58 | } |
| 59 |