mirror of
https://github.com/gtsteffaniak/filebrowser.git
synced 2026-11-26 08:29:41 -05:00
+10








3c02eedca6
Co-authored-by: Kevin B. <kurami32_kbm@proton.me> Co-authored-by: Gabriel Górski <me@glaeqen.eu> Co-authored-by: Joel Godfrey <82655889+BaccanoMob@users.noreply.github.com> Co-authored-by: Shane Chiu <71911511+pwn2ooown@users.noreply.github.com> Co-authored-by: carloda <35763669+carloda@users.noreply.github.com> Co-authored-by: Taufik Hidayat <taufikdev88@gmail.com> Co-authored-by: Stephan Paternotte <Stephan-P@users.noreply.github.com> Co-authored-by: SIDDHU SINGH <siddhu3116@gmail.com> Co-authored-by: Gaurav Kalal <117557391+Gorupa@users.noreply.github.com> Co-authored-by: Nebula <40148908+nebula-it@users.noreply.github.com> Co-authored-by: Juan Soler <juansoler@gmail.com> Co-authored-by: codacy-production[bot] <61871480+codacy-production[bot]@users.noreply.github.com> Co-authored-by: Anatolii Prylutskyi <anpryl@gmail.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Co-authored-by: Graham Steffaniak <graham@debian-lake.ghome.net> Co-authored-by: Neil <kylelzzz02@icloud.com> Co-authored-by: Graham <info@quantumx-apps.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Cursor <cursoragent@cursor.com>
65 lines
1.3 KiB
Go
65 lines
1.3 KiB
Go
package settings
|
|
|
|
import (
|
|
"github.com/gtsteffaniak/filebrowser/backend/internal/errors"
|
|
)
|
|
|
|
// StorageBackend is a settings storage backend.
|
|
type StorageBackend interface {
|
|
Get() (*Settings, error)
|
|
Save(*Settings) error
|
|
GetServer() (*Server, error)
|
|
SaveServer(*Server) error
|
|
}
|
|
|
|
// Storage is a settings storage.
|
|
type Storage struct {
|
|
back StorageBackend
|
|
}
|
|
|
|
// NewStorage creates a settings storage from a backend.
|
|
func NewStorage(back StorageBackend) *Storage {
|
|
return &Storage{back: back}
|
|
}
|
|
|
|
// Get returns the settings for the current instance.
|
|
func (s *Storage) Get() (*Settings, error) {
|
|
set, err := s.back.Get()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return set, nil
|
|
}
|
|
|
|
// Save saves the settings for the current instance.
|
|
func (s *Storage) Save(set *Settings) error {
|
|
if len(set.Auth.Key) == 0 {
|
|
return errors.ErrEmptyKey
|
|
}
|
|
|
|
if set.UserDefaults.UI.Locale == "" {
|
|
set.UserDefaults.UI.Locale = "en"
|
|
}
|
|
|
|
if set.UserDefaults.Listing.ViewMode == "" {
|
|
set.UserDefaults.Listing.ViewMode = "normal"
|
|
}
|
|
|
|
err := s.back.Save(set)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// GetServer wraps StorageBackend.GetServer.
|
|
func (s *Storage) GetServer() (*Server, error) {
|
|
return s.back.GetServer()
|
|
}
|
|
|
|
// SaveServer wraps StorageBackend.SaveServer and adds some verification.
|
|
func (s *Storage) SaveServer(ser *Server) error {
|
|
return s.back.SaveServer(ser)
|
|
}
|