Share single torrent client across all services, eliminate triple qBittorrent login on startup
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user