mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 16:59:12 +00:00
fix(downloadclient): qBittorrent url parse err handling (#1832)
* fix(downloadclient): qBittorrent url parse err handling * fix(downloadclient): qBittorrent url parse err handling test
This commit is contained in:
parent
a18284ecc6
commit
f54c51fa06
4 changed files with 22 additions and 8 deletions
|
@ -158,17 +158,20 @@ func (c DownloadClient) Validate() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c DownloadClient) BuildLegacyHost() string {
|
func (c DownloadClient) BuildLegacyHost() (string, error) {
|
||||||
if c.Type == DownloadClientTypeQbittorrent {
|
if c.Type == DownloadClientTypeQbittorrent {
|
||||||
return c.qbitBuildLegacyHost()
|
return c.qbitBuildLegacyHost()
|
||||||
}
|
}
|
||||||
return ""
|
return c.Host, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// qbitBuildLegacyHost exists to support older configs
|
// qbitBuildLegacyHost exists to support older configs
|
||||||
func (c DownloadClient) qbitBuildLegacyHost() string {
|
func (c DownloadClient) qbitBuildLegacyHost() (string, error) {
|
||||||
// parse url
|
// parse url
|
||||||
u, _ := url.Parse(c.Host)
|
u, err := url.Parse(c.Host)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
// reset Opaque
|
// reset Opaque
|
||||||
u.Opaque = ""
|
u.Opaque = ""
|
||||||
|
@ -200,5 +203,5 @@ func (c DownloadClient) qbitBuildLegacyHost() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// make into new string and return
|
// make into new string and return
|
||||||
return u.String()
|
return u.String(), nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -153,7 +153,8 @@ func TestDownloadClient_qbitBuildLegacyHost(t *testing.T) {
|
||||||
Password: tt.fields.Password,
|
Password: tt.fields.Password,
|
||||||
Settings: tt.fields.Settings,
|
Settings: tt.fields.Settings,
|
||||||
}
|
}
|
||||||
assert.Equalf(t, tt.want, c.qbitBuildLegacyHost(), "qbitBuildLegacyHost()")
|
got, _ := c.qbitBuildLegacyHost()
|
||||||
|
assert.Equalf(t, tt.want, got, "qbitBuildLegacyHost()")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,8 +71,13 @@ func (s *service) testConnection(ctx context.Context, client domain.DownloadClie
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) testQbittorrentConnection(ctx context.Context, client domain.DownloadClient) error {
|
func (s *service) testQbittorrentConnection(ctx context.Context, client domain.DownloadClient) error {
|
||||||
|
clientHost, err := client.BuildLegacyHost()
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "error building qBittorrent host url: %s", client.Host)
|
||||||
|
}
|
||||||
|
|
||||||
qbtSettings := qbittorrent.Config{
|
qbtSettings := qbittorrent.Config{
|
||||||
Host: client.BuildLegacyHost(),
|
Host: clientHost,
|
||||||
TLSSkipVerify: client.TLSSkipVerify,
|
TLSSkipVerify: client.TLSSkipVerify,
|
||||||
Username: client.Username,
|
Username: client.Username,
|
||||||
Password: client.Password,
|
Password: client.Password,
|
||||||
|
|
|
@ -181,8 +181,13 @@ func (s *service) GetClient(ctx context.Context, clientId int32) (*domain.Downlo
|
||||||
|
|
||||||
switch client.Type {
|
switch client.Type {
|
||||||
case domain.DownloadClientTypeQbittorrent:
|
case domain.DownloadClientTypeQbittorrent:
|
||||||
|
clientHost, err := client.BuildLegacyHost()
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "error building qBittorrent host url: %v", client.Host)
|
||||||
|
}
|
||||||
|
|
||||||
client.Client = qbittorrent.NewClient(qbittorrent.Config{
|
client.Client = qbittorrent.NewClient(qbittorrent.Config{
|
||||||
Host: client.BuildLegacyHost(),
|
Host: clientHost,
|
||||||
Username: client.Username,
|
Username: client.Username,
|
||||||
Password: client.Password,
|
Password: client.Password,
|
||||||
TLSSkipVerify: client.TLSSkipVerify,
|
TLSSkipVerify: client.TLSSkipVerify,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue