mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-30 05:37:05 +02:00
parent
0f4b04c641
commit
ed191d2f15
5 changed files with 68 additions and 22 deletions
|
@ -18,6 +18,7 @@ package scrobblerlog
|
|||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
|
@ -34,6 +35,7 @@ type ScrobblerLogBackend struct {
|
|||
includeSkipped bool
|
||||
append bool
|
||||
file *os.File
|
||||
timezone *time.Location
|
||||
log scrobblerlog.ScrobblerLog
|
||||
}
|
||||
|
||||
|
@ -53,6 +55,10 @@ func (b *ScrobblerLogBackend) Options() []models.BackendOption {
|
|||
Label: i18n.Tr("Append to file"),
|
||||
Type: models.Bool,
|
||||
Default: "true",
|
||||
}, {
|
||||
Name: "time-zone",
|
||||
Label: i18n.Tr("Specify a time zone for the listen timestamps"),
|
||||
Type: models.String,
|
||||
}}
|
||||
}
|
||||
|
||||
|
@ -60,6 +66,14 @@ func (b *ScrobblerLogBackend) InitConfig(config *config.ServiceConfig) error {
|
|||
b.filePath = config.GetString("file-path")
|
||||
b.includeSkipped = config.GetBool("include-skipped", false)
|
||||
b.append = config.GetBool("append", true)
|
||||
timezone := config.GetString("time-zone")
|
||||
if timezone != "" {
|
||||
location, err := time.LoadLocation(timezone)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Invalid time-zone %q: %w", timezone, err)
|
||||
}
|
||||
b.log.FallbackTimezone = location
|
||||
}
|
||||
b.log = scrobblerlog.ScrobblerLog{
|
||||
TZ: scrobblerlog.TZ_UTC,
|
||||
Client: "Rockbox unknown $Revision$",
|
||||
|
|
|
@ -33,3 +33,13 @@ func TestInitConfig(t *testing.T) {
|
|||
err := backend.InitConfig(&service)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestInitConfigInvalidTimezone(t *testing.T) {
|
||||
c := viper.New()
|
||||
configuredTimezone := "Invalid/Timezone"
|
||||
c.Set("time-zone", configuredTimezone)
|
||||
service := config.NewServiceConfig("test", c)
|
||||
backend := scrobblerlog.ScrobblerLogBackend{}
|
||||
err := backend.InitConfig(&service)
|
||||
assert.ErrorContains(t, err, `Invalid time-zone "Invalid/Timezone"`)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue