From 0ee673c0973f729a6481b540362441ccf62f0309 Mon Sep 17 00:00:00 2001 From: Tim Van Wassenhove Date: Thu, 19 Feb 2026 09:30:30 +0100 Subject: [PATCH] feat: wire Spotify service into server --- cmd/soundtouch-service/main.go | 16 ++++++++++++++++ pkg/service/handlers/server.go | 10 ++++++++++ 2 files changed, 26 insertions(+) diff --git a/cmd/soundtouch-service/main.go b/cmd/soundtouch-service/main.go index df987fb..f637e07 100644 --- a/cmd/soundtouch-service/main.go +++ b/cmd/soundtouch-service/main.go @@ -23,6 +23,7 @@ import ( "github.com/gesellix/bose-soundtouch/pkg/service/handlers" "github.com/gesellix/bose-soundtouch/pkg/service/proxy" "github.com/gesellix/bose-soundtouch/pkg/service/setup" + "github.com/gesellix/bose-soundtouch/pkg/service/spotify" "github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5/middleware" "github.com/urfave/cli/v2" @@ -228,6 +229,21 @@ func main() { server.SetZeroconfEnabled(config.zeroconfEnabled) server.SetBaseURL(config.baseURL) + if config.spotifyClientID != "" { + spotifyService := spotify.NewSpotifyService( + config.spotifyClientID, + config.spotifyClientSecret, + config.spotifyRedirectURI, + config.dataDir, + ) + server.SetSpotifyService(spotifyService) + clientIDPrefix := config.spotifyClientID + if len(clientIDPrefix) > 8 { + clientIDPrefix = clientIDPrefix[:8] + } + log.Printf("Spotify service initialized (client ID: %s...)", clientIDPrefix) + } + // Load and set initial DNS discoveries dnsDiscoveries, err := ds.LoadDNSDiscoveries() if err == nil && len(dnsDiscoveries) > 0 { diff --git a/pkg/service/handlers/server.go b/pkg/service/handlers/server.go index 3dd25e6..8f534db 100644 --- a/pkg/service/handlers/server.go +++ b/pkg/service/handlers/server.go @@ -13,6 +13,7 @@ import ( "github.com/gesellix/bose-soundtouch/pkg/service/datastore" "github.com/gesellix/bose-soundtouch/pkg/service/proxy" "github.com/gesellix/bose-soundtouch/pkg/service/setup" + "github.com/gesellix/bose-soundtouch/pkg/service/spotify" ) // Server handles HTTP requests for the SoundTouch service. @@ -47,6 +48,7 @@ type Server struct { spotifyRedirectURI string zeroconfEnabled bool baseURL string + spotifyService *spotify.SpotifyService } // NewServer creates a new SoundTouch service server. @@ -257,6 +259,14 @@ func (s *Server) SetBaseURL(baseURL string) { s.baseURL = baseURL } +// SetSpotifyService sets the Spotify OAuth service. +func (s *Server) SetSpotifyService(ss *spotify.SpotifyService) { + s.mu.Lock() + defer s.mu.Unlock() + + s.spotifyService = ss +} + // GetRecordEnabled returns whether recording is enabled. func (s *Server) GetRecordEnabled() bool { s.mu.RLock()