Share single torrent client across all services, eliminate triple qBittorrent login on startup

This commit is contained in:
Alexander
2026-05-09 21:42:53 +02:00
parent 758a4b909a
commit ef75b9bfba
5 changed files with 19 additions and 46 deletions
+2 -20
View File
@@ -11,7 +11,6 @@ import (
"github.com/rs/zerolog/log"
pb "homelab.lan/music-agregator/gen/music_agregator/torrent/v1"
"homelab.lan/music-agregator/internal/config"
)
type TorrentService struct {
@@ -19,27 +18,10 @@ type TorrentService struct {
token string
}
func NewTorrentService(cfg config.Config) (*TorrentService, error) {
var client TorrentClient
switch cfg.Torrent.ClientType {
case config.TorrentClientQbittorrent:
client = NewQbittorrentClient(cfg.Torrent.Url)
default:
return nil, fmt.Errorf("unknown torrent client type: %s", cfg.Torrent.ClientType)
}
token, err := client.Login(cfg.Torrent.Username, cfg.Torrent.Password)
if err != nil {
return nil, fmt.Errorf("torrent client login failed: %w", err)
}
log.Info().Str("client", string(cfg.Torrent.ClientType)).Msg("torrent client connected")
func NewTorrentService(client TorrentClient) *TorrentService {
return &TorrentService{
client: client,
token: token,
}, nil
}
}
func (service *TorrentService) List(req *pb.ListRequest) (*pb.ListResponse, error) {