settings.go
⎇
Raw
1package service
2
3import (
4 "strconv"
5 "vidarchive/internal/models"
6 "vidarchive/internal/repository"
7)
8
9type SettingsService struct {
10 repo *repository.SettingsRepository
11}
12
13func NewSettingsService(repo *repository.SettingsRepository) *SettingsService {
14 return &SettingsService{repo: repo}
15}
16
17func (s *SettingsService) GetAll() (*models.Settings, error) {
18 return s.repo.GetAll()
19}
20
21func (s *SettingsService) SetRefreshInterval(interval string) error {
22 return s.repo.Set("refresh_interval", interval)
23}
24
25func (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
33func (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
41func (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
52func (s *SettingsService) SetCookies(cookies string) error {
53 return s.repo.Set("cookies", cookies)
54}
55
56func (s *SettingsService) GetCookies() (string, error) {
57 return s.repo.Get("cookies")
58}
59