feat(downloadclients): rtorrent improve basic auth handling (#914)

* feat: wrap rtorrent client with custom transport

* refactor: move to autobrr/go-rtorrent

* feat: wrap rtorrent client with custom transport

* refactor: move to autobrr/go-rtorrent

* feat(web): update forms
This commit is contained in:
ze0s 2023-05-06 18:16:34 +02:00 committed by GitHub
parent 605ceaf5f4
commit 96e38e649a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 58 additions and 24 deletions

View file

@ -10,7 +10,7 @@ import (
"github.com/autobrr/autobrr/internal/domain"
"github.com/autobrr/autobrr/pkg/errors"
"github.com/mrobinsn/go-rtorrent/rtorrent"
"github.com/autobrr/go-rtorrent"
)
func (s *service) rtorrent(ctx context.Context, action *domain.Action, release domain.Release) ([]string, error) {
@ -31,8 +31,16 @@ func (s *service) rtorrent(ctx context.Context, action *domain.Action, release d
var rejections []string
// create config
cfg := rtorrent.Config{
Addr: client.Host,
TLSSkipVerify: client.TLSSkipVerify,
BasicUser: client.Settings.Basic.Username,
BasicPass: client.Settings.Basic.Password,
}
// create client
rt := rtorrent.New(client.Host, true)
rt := rtorrent.NewClient(cfg)
if release.HasMagnetUri() {
var args []*rtorrent.FieldValue
@ -57,14 +65,14 @@ func (s *service) rtorrent(ctx context.Context, action *domain.Action, release d
}
}
var addTorrentMagnet func(string, ...*rtorrent.FieldValue) error
var addTorrentMagnet func(context.Context, string, ...*rtorrent.FieldValue) error
if action.Paused {
addTorrentMagnet = rt.AddStopped
} else {
addTorrentMagnet = rt.Add
}
if err := addTorrentMagnet(release.MagnetURI, args...); err != nil {
if err := addTorrentMagnet(ctx, release.MagnetURI, args...); err != nil {
return nil, errors.Wrap(err, "could not add torrent from magnet: %s", release.MagnetURI)
}
@ -107,14 +115,14 @@ func (s *service) rtorrent(ctx context.Context, action *domain.Action, release d
}
}
var addTorrentFile func([]byte, ...*rtorrent.FieldValue) error
var addTorrentFile func(context.Context, []byte, ...*rtorrent.FieldValue) error
if action.Paused {
addTorrentFile = rt.AddTorrentStopped
} else {
addTorrentFile = rt.AddTorrent
}
if err := addTorrentFile(tmpFile, args...); err != nil {
if err := addTorrentFile(ctx, tmpFile, args...); err != nil {
return nil, errors.Wrap(err, "could not add torrent file: %s", release.TorrentTmpFile)
}