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:
Ludvig Lundgren 2022-07-08 22:12:19 +02:00 committed by GitHub
parent 33e3691737
commit 401c93a657
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 72 additions and 39 deletions

View file

@ -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