mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 16:59:12 +00:00
fix(download-clients): qbit nil logger panic (#344)
The logger wasn't set, so it was always nil. Change to always initialize and override if one is passed.
This commit is contained in:
parent
33e3691737
commit
401c93a657
5 changed files with 72 additions and 39 deletions
|
@ -6,6 +6,9 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/dcarbone/zadapters/zstdlog"
|
||||
"github.com/rs/zerolog"
|
||||
|
||||
"github.com/autobrr/autobrr/internal/domain"
|
||||
"github.com/autobrr/autobrr/pkg/errors"
|
||||
"github.com/autobrr/autobrr/pkg/qbittorrent"
|
||||
|
@ -30,15 +33,18 @@ func (s *service) qbittorrent(action domain.Action, release domain.Release) ([]s
|
|||
qbt, exists := s.qbitClients[qbitKey{client.ID, client.Name}]
|
||||
if !exists {
|
||||
qbtSettings := qbittorrent.Settings{
|
||||
Name: client.Name,
|
||||
Hostname: client.Host,
|
||||
Port: uint(client.Port),
|
||||
Username: client.Username,
|
||||
Password: client.Password,
|
||||
TLS: client.TLS,
|
||||
TLSSkipVerify: client.TLSSkipVerify,
|
||||
Log: s.subLogger,
|
||||
}
|
||||
|
||||
// setup sub logger adapter which is compatible with *log.Logger
|
||||
qbtSettings.Log = zstdlog.NewStdLoggerWithLevel(s.log.With().Str("type", "qBittorrent").Str("client", client.Name).Logger(), zerolog.TraceLevel)
|
||||
|
||||
// only set basic auth if enabled
|
||||
if client.Settings.Basic.Auth {
|
||||
qbtSettings.BasicAuth = client.Settings.Basic.Auth
|
||||
|
@ -47,7 +53,6 @@ func (s *service) qbittorrent(action domain.Action, release domain.Release) ([]s
|
|||
}
|
||||
|
||||
qbt = qbittorrent.NewClient(qbtSettings)
|
||||
qbt.Name = client.Name
|
||||
|
||||
s.qbitClients[qbitKey{client.ID, client.Name}] = qbt
|
||||
|
||||
|
@ -87,7 +92,7 @@ func (s *service) qbittorrent(action domain.Action, release domain.Release) ([]s
|
|||
s.log.Trace().Msgf("action qBittorrent options: %+v", options)
|
||||
|
||||
if err = qbt.AddTorrentFromFile(release.TorrentTmpFile, options); err != nil {
|
||||
return nil, errors.Wrap(err, "could not add torrent %v to client: %v", release.TorrentTmpFile, qbt.Name)
|
||||
return nil, errors.Wrap(err, "could not add torrent %v to client: %v", release.TorrentTmpFile, client.Name)
|
||||
}
|
||||
|
||||
if !action.Paused && !action.ReAnnounceSkip && release.TorrentHash != "" {
|
||||
|
@ -96,7 +101,7 @@ func (s *service) qbittorrent(action domain.Action, release domain.Release) ([]s
|
|||
}
|
||||
}
|
||||
|
||||
s.log.Info().Msgf("torrent with hash %v successfully added to client: '%v'", release.TorrentHash, qbt.Name)
|
||||
s.log.Info().Msgf("torrent with hash %v successfully added to client: '%v'", release.TorrentHash, client.Name)
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
@ -152,7 +157,7 @@ func (s *service) prepareQbitOptions(action domain.Action, m Macro) (map[string]
|
|||
return options, nil
|
||||
}
|
||||
|
||||
func (s *service) qbittorrentCheckRulesCanDownload(action domain.Action, client *domain.DownloadClient, qbt *qbittorrent.Client) ([]string, error) {
|
||||
func (s *service) qbittorrentCheckRulesCanDownload(action domain.Action, client *domain.DownloadClient, qbt qbittorrent.Client) ([]string, error) {
|
||||
s.log.Trace().Msgf("action qBittorrent: %v check rules", action.Name)
|
||||
|
||||
// check for active downloads and other rules
|
||||
|
@ -197,7 +202,7 @@ func (s *service) qbittorrentCheckRulesCanDownload(action domain.Action, client
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *service) reannounceTorrent(qb *qbittorrent.Client, action domain.Action, hash string) error {
|
||||
func (s *service) reannounceTorrent(qb qbittorrent.Client, action domain.Action, hash string) error {
|
||||
announceOK := false
|
||||
attempts := 0
|
||||
|
||||
|
|
|
@ -20,6 +20,14 @@ func (s *service) RunAction(action *domain.Action, release domain.Release) ([]st
|
|||
rejections []string
|
||||
)
|
||||
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
s.log.Error().Msgf("recovering from panic in run action %v error: %v", action.Name, r)
|
||||
err = errors.New("panic in action: %v", action.Name)
|
||||
return
|
||||
}
|
||||
}()
|
||||
|
||||
switch action.Type {
|
||||
case domain.ActionTypeTest:
|
||||
s.test(action.Name)
|
||||
|
|
|
@ -36,7 +36,7 @@ type service struct {
|
|||
clientSvc download_client.Service
|
||||
bus EventBus.Bus
|
||||
|
||||
qbitClients map[qbitKey]*qbittorrent.Client
|
||||
qbitClients map[qbitKey]qbittorrent.Client
|
||||
}
|
||||
|
||||
func NewService(log logger.Logger, repo domain.ActionRepo, clientSvc download_client.Service, bus EventBus.Bus) Service {
|
||||
|
@ -45,7 +45,7 @@ func NewService(log logger.Logger, repo domain.ActionRepo, clientSvc download_cl
|
|||
repo: repo,
|
||||
clientSvc: clientSvc,
|
||||
bus: bus,
|
||||
qbitClients: map[qbitKey]*qbittorrent.Client{},
|
||||
qbitClients: map[qbitKey]qbittorrent.Client{},
|
||||
}
|
||||
|
||||
s.subLogger = zstdlog.NewStdLoggerWithLevel(s.log.With().Logger(), zerolog.TraceLevel)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue