feat(clients): add support for qBittorrent 4.4.0+ (#558)

* refactor: move client to go-qbittorrent

* refactor: move client to go-qbittorrent

* feat(downloadclient): cache qbittorrent client

* feat(downloadclient): update qbit

* feat(downloadclient): client test and remove pkg qbit

* feat(downloadclient): update pkg qbit

* fix(release): method

* feat(release): make GetCachedClient concurrent safe

* feat(release): add additional tests for buildLegacyHost

* feat(release): remove branching

* chore: update pkg autobrr/go-qbittorrent to v.1.2.0
This commit is contained in:
ze0s 2022-12-10 19:25:04 +01:00 committed by GitHub
parent 6ad4abe296
commit 29da2416ec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 379 additions and 1764 deletions

View file

@ -2,6 +2,7 @@ package action
import (
"bytes"
"context"
"crypto/tls"
"io"
"net/http"
@ -14,7 +15,7 @@ import (
"github.com/autobrr/autobrr/pkg/errors"
)
func (s *service) RunAction(action *domain.Action, release domain.Release) ([]string, error) {
func (s *service) RunAction(ctx context.Context, action *domain.Action, release domain.Release) ([]string, error) {
var (
err error
@ -40,13 +41,13 @@ func (s *service) RunAction(action *domain.Action, release domain.Release) ([]st
err = s.watchFolder(*action, release)
case domain.ActionTypeWebhook:
err = s.webhook(*action, release)
err = s.webhook(ctx, *action, release)
case domain.ActionTypeDelugeV1, domain.ActionTypeDelugeV2:
rejections, err = s.deluge(*action, release)
case domain.ActionTypeQbittorrent:
rejections, err = s.qbittorrent(*action, release)
rejections, err = s.qbittorrent(ctx, *action, release)
case domain.ActionTypeRTorrent:
rejections, err = s.rtorrent(*action, release)
@ -86,12 +87,12 @@ func (s *service) RunAction(action *domain.Action, release domain.Release) ([]st
}
payload := &domain.NotificationPayload{
Event: domain.NotificationEventPushApproved,
ReleaseName: release.TorrentName,
Filter: release.Filter.Name,
Indexer: release.Indexer,
InfoHash: release.TorrentHash,
Event: domain.NotificationEventPushApproved,
ReleaseName: release.TorrentName,
Filter: release.Filter.Name,
Indexer: release.Indexer,
InfoHash: release.TorrentHash,
Size: release.Size,
Status: domain.ReleasePushStatusApproved,
Action: action.Name,
@ -208,10 +209,10 @@ func (s *service) watchFolder(action domain.Action, release domain.Release) erro
return nil
}
func (s *service) webhook(action domain.Action, release domain.Release) error {
func (s *service) webhook(ctx context.Context, action domain.Action, release domain.Release) error {
// if webhook data contains TorrentPathName or TorrentDataRawBytes, lets download the torrent file
if release.TorrentTmpFile == "" && (strings.Contains(action.WebhookData, "TorrentPathName") || strings.Contains(action.WebhookData, "TorrentDataRawBytes")) {
if err := release.DownloadTorrentFile(); err != nil {
if err := release.DownloadTorrentFileCtx(ctx); err != nil {
return errors.Wrap(err, "webhook: could not download torrent file for release: %v", release.TorrentName)
}
}
@ -245,7 +246,7 @@ func (s *service) webhook(action domain.Action, release domain.Release) error {
client := http.Client{Transport: t, Timeout: 15 * time.Second}
req, err := http.NewRequest(http.MethodPost, action.WebhookHost, bytes.NewBufferString(dataArgs))
req, err := http.NewRequestWithContext(ctx, http.MethodPost, action.WebhookHost, bytes.NewBufferString(dataArgs))
if err != nil {
return errors.Wrap(err, "could not build request for webhook")
}