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

@ -1,6 +1,12 @@
package domain
import "context"
import (
"context"
"fmt"
"net/url"
"github.com/autobrr/go-qbittorrent"
)
type DownloadClientRepo interface {
List(ctx context.Context) ([]DownloadClient, error)
@ -24,6 +30,11 @@ type DownloadClient struct {
Settings DownloadClientSettings `json:"settings,omitempty"`
}
type DownloadClientCached struct {
Dc *DownloadClient
Qbt *qbittorrent.Client
}
type DownloadClientSettings struct {
APIKey string `json:"apikey,omitempty"`
Basic BasicAuth `json:"basic,omitempty"`
@ -57,3 +68,48 @@ const (
DownloadClientTypeWhisparr DownloadClientType = "WHISPARR"
DownloadClientTypeReadarr DownloadClientType = "READARR"
)
func (c DownloadClient) BuildLegacyHost() string {
if c.Type == DownloadClientTypeQbittorrent {
return c.qbitBuildLegacyHost()
}
return ""
}
// qbitBuildLegacyHost exists to support older configs
func (c DownloadClient) qbitBuildLegacyHost() string {
// parse url
u, _ := url.Parse(c.Host)
// reset Opaque
u.Opaque = ""
// set scheme
scheme := "http"
if c.TLS {
scheme = "https"
}
u.Scheme = scheme
// if host is empty lets use one from settings
if u.Host == "" {
u.Host = c.Host
}
// reset Path
if u.Host == u.Path {
u.Path = ""
}
// handle ports
if c.Port > 0 {
if c.Port == 80 || c.Port == 443 {
// skip for regular http and https
} else {
u.Host = fmt.Sprintf("%v:%v", u.Host, c.Port)
}
}
// make into new string and return
return u.String()
}