settings.go
⎇
Raw
1package service
2
3import (
4 "vidarchive/internal/models"
5 "vidarchive/internal/repository"
6)
7
8type SettingsService struct {
9 repo *repository.SettingsRepository
10}
11
12func NewSettingsService(repo *repository.SettingsRepository) *SettingsService {
13 return &SettingsService{repo: repo}
14}
15
16func (s *SettingsService) GetAll() (*models.Settings, error) {
17 return s.repo.GetAll()
18}
19
20func (s *SettingsService) SetRefreshInterval(interval string) error {
21 return s.repo.Set("refresh_interval", interval)
22}
23
24func (s *SettingsService) SetAutoRefreshLibrary(enabled bool) error {
25 val := "0"
26 if enabled {
27 val = "1"
28 }
29 return s.repo.Set("auto_refresh_library", val)
30}
31
32func (s *SettingsService) SetAutoRefreshDownloads(enabled bool) error {
33 val := "0"
34 if enabled {
35 val = "1"
36 }
37 return s.repo.Set("auto_refresh_downloads", val)
38}
39
40func (s *SettingsService) SetCookies(cookies string) error {
41 return s.repo.Set("cookies", cookies)
42}
43
44func (s *SettingsService) GetCookies() (string, error) {
45 return s.repo.Get("cookies")
46}
47
48// GetSessionSecret returns the secret that signs login cookies, or "" when none
49// has been generated yet. It lives in the database so sessions survive a
50// restart, and is rotated on sign-out so cookies issued earlier stop verifying.
51func (s *SettingsService) GetSessionSecret() (string, error) {
52 return s.repo.Get("session_secret")
53}
54
55func (s *SettingsService) SetSessionSecret(secret string) error {
56 return s.repo.Set("session_secret", secret)
57}
58