mirror of
https://github.com/idanoo/autobrr
synced 2025-07-22 16:29:12 +00:00
refactor: download client addr parsing (#108)
* refactor: client addr parsing * feat: add logging to client test * feat: imrpove help for download client forms
This commit is contained in:
parent
26f558859a
commit
fe25cdec28
7 changed files with 50 additions and 14 deletions
|
@ -50,6 +50,8 @@ func (s *service) testQbittorrentConnection(client domain.DownloadClient) error
|
|||
return err
|
||||
}
|
||||
|
||||
log.Debug().Msgf("test client connection for qBittorrent: success")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -92,7 +94,7 @@ func (s *service) testDelugeConnection(client domain.DownloadClient) error {
|
|||
return err
|
||||
}
|
||||
|
||||
log.Debug().Msgf("daemon version: %v", ver)
|
||||
log.Debug().Msgf("test client connection for Deluge: success - daemon version: %v", ver)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -112,6 +114,8 @@ func (s *service) testRadarrConnection(client domain.DownloadClient) error {
|
|||
return err
|
||||
}
|
||||
|
||||
log.Debug().Msgf("test client connection for Radarr: success")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -130,6 +134,8 @@ func (s *service) testSonarrConnection(client domain.DownloadClient) error {
|
|||
return err
|
||||
}
|
||||
|
||||
log.Debug().Msgf("test client connection for Sonarr: success")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -148,5 +154,7 @@ func (s *service) testLidarrConnection(client domain.DownloadClient) error {
|
|||
return err
|
||||
}
|
||||
|
||||
log.Debug().Msgf("test client connection for Lidarr: success")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -4,14 +4,17 @@ import (
|
|||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func (c *client) get(endpoint string) (*http.Response, error) {
|
||||
reqUrl := fmt.Sprintf("%v/api/v1/%v", c.config.Hostname, endpoint)
|
||||
u, err := url.Parse(c.config.Hostname)
|
||||
u.Path = path.Join(u.Path, "/api/v1/", endpoint)
|
||||
reqUrl := u.String()
|
||||
|
||||
req, err := http.NewRequest(http.MethodGet, reqUrl, http.NoBody)
|
||||
if err != nil {
|
||||
|
@ -40,7 +43,9 @@ func (c *client) get(endpoint string) (*http.Response, error) {
|
|||
}
|
||||
|
||||
func (c *client) post(endpoint string, data interface{}) (*http.Response, error) {
|
||||
reqUrl := fmt.Sprintf("%v/api/v1/%v", c.config.Hostname, endpoint)
|
||||
u, err := url.Parse(c.config.Hostname)
|
||||
u.Path = path.Join(u.Path, "/api/v1/", endpoint)
|
||||
reqUrl := u.String()
|
||||
|
||||
jsonData, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
|
|
|
@ -4,14 +4,17 @@ import (
|
|||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func (c *client) get(endpoint string) (*http.Response, error) {
|
||||
reqUrl := fmt.Sprintf("%v/api/v3/%v", c.config.Hostname, endpoint)
|
||||
u, err := url.Parse(c.config.Hostname)
|
||||
u.Path = path.Join(u.Path, "/api/v3/", endpoint)
|
||||
reqUrl := u.String()
|
||||
|
||||
req, err := http.NewRequest(http.MethodGet, reqUrl, http.NoBody)
|
||||
if err != nil {
|
||||
|
@ -40,7 +43,9 @@ func (c *client) get(endpoint string) (*http.Response, error) {
|
|||
}
|
||||
|
||||
func (c *client) post(endpoint string, data interface{}) (*http.Response, error) {
|
||||
reqUrl := fmt.Sprintf("%v/api/v3/%v", c.config.Hostname, endpoint)
|
||||
u, err := url.Parse(c.config.Hostname)
|
||||
u.Path = path.Join(u.Path, "/api/v3/", endpoint)
|
||||
reqUrl := u.String()
|
||||
|
||||
jsonData, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
|
|
|
@ -171,6 +171,19 @@ func Test_client_Test(t *testing.T) {
|
|||
wantErr: true,
|
||||
err: errors.New("unauthorized: bad credentials"),
|
||||
},
|
||||
{
|
||||
name: "fetch_subfolder",
|
||||
cfg: Config{
|
||||
Hostname: srv.URL + "/radarr",
|
||||
APIKey: key,
|
||||
BasicAuth: false,
|
||||
Username: "",
|
||||
Password: "",
|
||||
},
|
||||
want: &SystemStatusResponse{Version: "3.2.2.5080"},
|
||||
err: nil,
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
|
|
@ -4,14 +4,17 @@ import (
|
|||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func (c *client) get(endpoint string) (*http.Response, error) {
|
||||
reqUrl := fmt.Sprintf("%v/api/v3/%v", c.config.Hostname, endpoint)
|
||||
u, err := url.Parse(c.config.Hostname)
|
||||
u.Path = path.Join(u.Path, "/api/v3/", endpoint)
|
||||
reqUrl := u.String()
|
||||
|
||||
req, err := http.NewRequest(http.MethodGet, reqUrl, http.NoBody)
|
||||
if err != nil {
|
||||
|
@ -40,7 +43,9 @@ func (c *client) get(endpoint string) (*http.Response, error) {
|
|||
}
|
||||
|
||||
func (c *client) post(endpoint string, data interface{}) (*http.Response, error) {
|
||||
reqUrl := fmt.Sprintf("%v/api/v3/%v", c.config.Hostname, endpoint)
|
||||
u, err := url.Parse(c.config.Hostname)
|
||||
u.Path = path.Join(u.Path, "/api/v3/", endpoint)
|
||||
reqUrl := u.String()
|
||||
|
||||
jsonData, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
|
|
|
@ -150,7 +150,7 @@ const NumberFieldWide: React.FC<NumberFieldWideProps> = ({
|
|||
)}
|
||||
</Field>
|
||||
{help && (
|
||||
<p className="mt-2 text-sm text-gray-500 dark:text-gray-200" id={`${name}-description`}>{help}</p>
|
||||
<p className="mt-2 text-sm text-gray-500 dark:text-gray-500" id={`${name}-description`}>{help}</p>
|
||||
)}
|
||||
<ErrorField name={name} classNames="block text-red-500 mt-2" />
|
||||
</div>
|
||||
|
|
|
@ -46,9 +46,9 @@ interface InitialValues {
|
|||
function FormFieldsDefault() {
|
||||
return (
|
||||
<Fragment>
|
||||
<TextFieldWide name="host" label="Host" help="Url domain.ltd/client" />
|
||||
<TextFieldWide name="host" label="Host" help="Eg. client.domain.ltd, domain.ltd/client, domain.ltd:port" />
|
||||
|
||||
<NumberFieldWide name="port" label="Port" />
|
||||
<NumberFieldWide name="port" label="Port" help="WebUI port for qBittorrent and daemon port for Deluge" />
|
||||
|
||||
<div className="py-6 px-6 space-y-6 sm:py-0 sm:space-y-0 sm:divide-y sm:divide-gray-200">
|
||||
<SwitchGroupWide name="ssl" label="SSL" />
|
||||
|
@ -67,7 +67,7 @@ function FormFieldsArr() {
|
|||
|
||||
return (
|
||||
<Fragment>
|
||||
<TextFieldWide name="host" label="Host" help="Full url like http(s)://domain.ltd/" />
|
||||
<TextFieldWide name="host" label="Host" help="Full url http(s)://domain.ltd and/or subdomain/subfolder" />
|
||||
|
||||
<PasswordFieldWide name="settings.apikey" label="API key" />
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue