Change duration config types

This commit is contained in:
Deluan 2020-07-02 16:41:54 -04:00
parent 5021c0fd0c
commit d2e4cade62
3 changed files with 7 additions and 14 deletions

View file

@ -4,6 +4,7 @@ import (
"fmt"
"os"
"path/filepath"
"time"
"github.com/deluan/navidrome/consts"
"github.com/deluan/navidrome/log"
@ -15,10 +16,10 @@ type nd struct {
Port int
MusicFolder string
DataFolder string
ScanInterval string
DbPath string
LogLevel string
SessionTimeout string
ScanInterval time.Duration
SessionTimeout time.Duration
BaseURL string
UILoginBackgroundURL string
IgnoredArticles string
@ -65,8 +66,8 @@ func SetDefaults() {
viper.SetDefault("datafolder", "./")
viper.SetDefault("loglevel", "info")
viper.SetDefault("port", 4533)
viper.SetDefault("sessiontimeout", "1h")
viper.SetDefault("scaninterval", "1m")
viper.SetDefault("sessiontimeout", consts.DefaultSessionTimeout)
viper.SetDefault("scaninterval", time.Minute)
viper.SetDefault("baseurl", "")
viper.SetDefault("uiloginbackgroundurl", "")
viper.SetDefault("enabletranscodingconfig", false)

View file

@ -44,11 +44,7 @@ func CreateToken(u *model.User) (string, error) {
func getSessionTimeOut() time.Duration {
if sessionTimeOut == 0 {
if to, err := time.ParseDuration(conf.Server.SessionTimeout); err != nil {
sessionTimeOut = consts.DefaultSessionTimeout
} else {
sessionTimeOut = to
}
sessionTimeOut = conf.Server.SessionTimeout
log.Info("Setting Session Timeout", "value", sessionTimeOut)
}
return sessionTimeOut

View file

@ -75,11 +75,7 @@ func (a *Server) initRoutes() {
}
func (a *Server) initScanner() {
interval, err := time.ParseDuration(conf.Server.ScanInterval)
if err != nil {
log.Error("Invalid interval specification. Using default of 5m", "interval", conf.Server.ScanInterval, err)
interval = 5 * time.Minute
}
interval := conf.Server.ScanInterval
if interval == 0 {
log.Warn("Scanner is disabled", "interval", conf.Server.ScanInterval)
return