From dd1d3907b41f6a126403f1df2cc7aa3769db61ee Mon Sep 17 00:00:00 2001 From: Deluan Date: Wed, 21 May 2025 16:20:29 -0400 Subject: [PATCH] Revert "refactor(server): simplify lastfm agent initialization logic" This reverts commit 6f52c0201cdc6e92bf4e47394d79767db9c33640. Signed-off-by: Deluan --- core/agents/agents.go | 2 +- core/agents/lastfm/agent.go | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/core/agents/agents.go b/core/agents/agents.go index 9814c9f18..50a1e04ad 100644 --- a/core/agents/agents.go +++ b/core/agents/agents.go @@ -45,7 +45,7 @@ func createAgents(ds model.DataStore) *Agents { continue } enabled = append(enabled, name) - res = append(res, agent) + res = append(res, init(ds)) } log.Debug("List of agents enabled", "names", enabled) diff --git a/core/agents/lastfm/agent.go b/core/agents/lastfm/agent.go index 78ed96678..3f5f44d20 100644 --- a/core/agents/lastfm/agent.go +++ b/core/agents/lastfm/agent.go @@ -344,10 +344,22 @@ func (l *lastfmAgent) IsAuthorized(ctx context.Context, userId string) bool { func init() { conf.AddHook(func() { agents.Register(lastFMAgentName, func(ds model.DataStore) agents.Interface { - return lastFMConstructor(ds) + // This is a workaround for the fact that a (Interface)(nil) is not the same as a (*lastfmAgent)(nil) + // See https://go.dev/doc/faq#nil_error + a := lastFMConstructor(ds) + if a != nil { + return a + } + return nil }) scrobbler.Register(lastFMAgentName, func(ds model.DataStore) scrobbler.Scrobbler { - return lastFMConstructor(ds) + // Same as above - this is a workaround for the fact that a (Scrobbler)(nil) is not the same as a (*lastfmAgent)(nil) + // See https://go.dev/doc/faq#nil_error + a := lastFMConstructor(ds) + if a != nil { + return a + } + return nil }) }) }