Skip to content

Commit

Permalink
added error handling when getting user setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Mjaethers committed Dec 13, 2023
1 parent a07299c commit 410f772
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
8 changes: 4 additions & 4 deletions model/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,18 @@ type AutoSkipSetting struct {
}

// GetAutoSkipEnabled returns whether the user has enabled auto skip
func (u User) GetAutoSkipEnabled() AutoSkipSetting {
func (u User) GetAutoSkipEnabled() (AutoSkipSetting, error) {
for _, setting := range u.Settings {
if setting.Type == AutoSkip {
var a AutoSkipSetting
err := json.Unmarshal([]byte(setting.Value), &a)
if err != nil {
break
return AutoSkipSetting{Enabled: false}, err
}
return a
return a, nil
}
}
return AutoSkipSetting{Enabled: false}
return AutoSkipSetting{Enabled: false}, nil
}

type argonParams struct {
Expand Down
5 changes: 4 additions & 1 deletion web/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ func (r mainRoutes) WatchPage(c *gin.Context) {
}

// Check if user wants to skip first silence
if tumLiveContext.User.GetAutoSkipEnabled().Enabled {
autoSkip, err := tumLiveContext.User.GetAutoSkipEnabled()
if err != nil {
log.Printf("Couldn't decode user setting: %v\n", err)
} else if autoSkip.Enabled {
data.Progress.Progress = math.Max(data.Progress.Progress, tumLiveContext.Stream.FirstSilenceAsProgress())
}
}
Expand Down

0 comments on commit 410f772

Please sign in to comment.