diff --git a/internal/action/lidarr.go b/internal/action/lidarr.go index 79e8cd2..0a9a3f3 100644 --- a/internal/action/lidarr.go +++ b/internal/action/lidarr.go @@ -34,7 +34,7 @@ func (s *service) lidarr(ctx context.Context, action *domain.Action, release dom InfoUrl: release.InfoURL, DownloadUrl: release.DownloadURL, MagnetUrl: release.MagnetURI, - Size: int64(release.Size), + Size: release.Size, Indexer: release.Indexer.GetExternalIdentifier(), DownloadClientId: client.Settings.ExternalDownloadClientId, DownloadClient: client.Settings.ExternalDownloadClient, diff --git a/internal/action/radarr.go b/internal/action/radarr.go index 3855a02..eecf2c3 100644 --- a/internal/action/radarr.go +++ b/internal/action/radarr.go @@ -34,7 +34,7 @@ func (s *service) radarr(ctx context.Context, action *domain.Action, release dom InfoUrl: release.InfoURL, DownloadUrl: release.DownloadURL, MagnetUrl: release.MagnetURI, - Size: int64(release.Size), + Size: release.Size, Indexer: release.Indexer.GetExternalIdentifier(), DownloadClientId: client.Settings.ExternalDownloadClientId, DownloadClient: client.Settings.ExternalDownloadClient, diff --git a/internal/action/readarr.go b/internal/action/readarr.go index 10512d9..dda7896 100644 --- a/internal/action/readarr.go +++ b/internal/action/readarr.go @@ -34,7 +34,7 @@ func (s *service) readarr(ctx context.Context, action *domain.Action, release do InfoUrl: release.InfoURL, DownloadUrl: release.DownloadURL, MagnetUrl: release.MagnetURI, - Size: int64(release.Size), + Size: release.Size, Indexer: release.Indexer.GetExternalIdentifier(), DownloadClientId: client.Settings.ExternalDownloadClientId, DownloadClient: client.Settings.ExternalDownloadClient, diff --git a/internal/action/sonarr.go b/internal/action/sonarr.go index ac62a23..149c070 100644 --- a/internal/action/sonarr.go +++ b/internal/action/sonarr.go @@ -34,7 +34,7 @@ func (s *service) sonarr(ctx context.Context, action *domain.Action, release dom InfoUrl: release.InfoURL, DownloadUrl: release.DownloadURL, MagnetUrl: release.MagnetURI, - Size: int64(release.Size), + Size: release.Size, Indexer: release.Indexer.GetExternalIdentifier(), DownloadClientId: client.Settings.ExternalDownloadClientId, DownloadClient: client.Settings.ExternalDownloadClient, diff --git a/internal/action/whisparr.go b/internal/action/whisparr.go index bdfe2cb..32e9466 100644 --- a/internal/action/whisparr.go +++ b/internal/action/whisparr.go @@ -34,7 +34,7 @@ func (s *service) whisparr(ctx context.Context, action *domain.Action, release d InfoUrl: release.InfoURL, DownloadUrl: release.DownloadURL, MagnetUrl: release.MagnetURI, - Size: int64(release.Size), + Size: release.Size, Indexer: release.Indexer.GetExternalIdentifier(), DownloadClientId: client.Settings.ExternalDownloadClientId, DownloadClient: client.Settings.ExternalDownloadClient, diff --git a/pkg/lidarr/client.go b/pkg/lidarr/client.go index 0108a27..e29f488 100644 --- a/pkg/lidarr/client.go +++ b/pkg/lidarr/client.go @@ -17,6 +17,10 @@ import ( func (c *client) get(ctx context.Context, endpoint string) (int, []byte, error) { u, err := url.Parse(c.config.Hostname) + if err != nil { + return 0, nil, errors.Wrap(err, "could not parse url: %s", c.config.Hostname) + } + u.Path = path.Join(u.Path, "/api/v1/", endpoint) reqUrl := u.String() @@ -38,6 +42,10 @@ func (c *client) get(ctx context.Context, endpoint string) (int, []byte, error) defer resp.Body.Close() + if resp.Body == nil { + return resp.StatusCode, nil, errors.New("response body is nil") + } + var buf bytes.Buffer if _, err = io.Copy(&buf, resp.Body); err != nil { return resp.StatusCode, nil, errors.Wrap(err, "lidarr.io.Copy error") @@ -48,6 +56,10 @@ func (c *client) get(ctx context.Context, endpoint string) (int, []byte, error) func (c *client) post(ctx context.Context, endpoint string, data interface{}) (*http.Response, error) { u, err := url.Parse(c.config.Hostname) + if err != nil { + return nil, errors.Wrap(err, "could not parse url: %s", c.config.Hostname) + } + u.Path = path.Join(u.Path, "/api/v1/", endpoint) reqUrl := u.String() @@ -87,6 +99,10 @@ func (c *client) post(ctx context.Context, endpoint string, data interface{}) (* func (c *client) postBody(ctx context.Context, endpoint string, data interface{}) (int, []byte, error) { u, err := url.Parse(c.config.Hostname) + if err != nil { + return 0, nil, errors.Wrap(err, "could not parse url: %s", c.config.Hostname) + } + u.Path = path.Join(u.Path, "/api/v1/", endpoint) reqUrl := u.String() @@ -113,6 +129,10 @@ func (c *client) postBody(ctx context.Context, endpoint string, data interface{} defer resp.Body.Close() + if resp.Body == nil { + return resp.StatusCode, nil, errors.New("response body is nil") + } + var buf bytes.Buffer if _, err = io.Copy(&buf, resp.Body); err != nil { return resp.StatusCode, nil, errors.Wrap(err, "lidarr.io.Copy") diff --git a/pkg/lidarr/lidarr.go b/pkg/lidarr/lidarr.go index 4209e2c..1b8d446 100644 --- a/pkg/lidarr/lidarr.go +++ b/pkg/lidarr/lidarr.go @@ -66,7 +66,7 @@ type Release struct { InfoUrl string `json:"infoUrl,omitempty"` DownloadUrl string `json:"downloadUrl,omitempty"` MagnetUrl string `json:"magnetUrl,omitempty"` - Size int64 `json:"size"` + Size uint64 `json:"size"` Indexer string `json:"indexer"` DownloadProtocol string `json:"downloadProtocol"` Protocol string `json:"protocol"` diff --git a/pkg/radarr/client.go b/pkg/radarr/client.go index d60ab20..c3acacc 100644 --- a/pkg/radarr/client.go +++ b/pkg/radarr/client.go @@ -17,6 +17,10 @@ import ( func (c *client) get(ctx context.Context, endpoint string) (int, []byte, error) { u, err := url.Parse(c.config.Hostname) + if err != nil { + return 0, nil, errors.Wrap(err, "could not parse url: %s", c.config.Hostname) + } + u.Path = path.Join(u.Path, "/api/v3/", endpoint) reqUrl := u.String() @@ -38,6 +42,10 @@ func (c *client) get(ctx context.Context, endpoint string) (int, []byte, error) defer resp.Body.Close() + if resp.Body == nil { + return resp.StatusCode, nil, errors.New("response body is nil") + } + var buf bytes.Buffer if _, err = io.Copy(&buf, resp.Body); err != nil { return resp.StatusCode, nil, errors.Wrap(err, "radarr.io.Copy") @@ -48,6 +56,10 @@ func (c *client) get(ctx context.Context, endpoint string) (int, []byte, error) func (c *client) post(ctx context.Context, endpoint string, data interface{}) (*http.Response, error) { u, err := url.Parse(c.config.Hostname) + if err != nil { + return nil, errors.Wrap(err, "could not parse url: %s", c.config.Hostname) + } + u.Path = path.Join(u.Path, "/api/v3/", endpoint) reqUrl := u.String() @@ -89,6 +101,10 @@ func (c *client) post(ctx context.Context, endpoint string, data interface{}) (* func (c *client) postBody(ctx context.Context, endpoint string, data interface{}) (int, []byte, error) { u, err := url.Parse(c.config.Hostname) + if err != nil { + return 0, nil, errors.Wrap(err, "could not parse url: %s", c.config.Hostname) + } + u.Path = path.Join(u.Path, "/api/v3/", endpoint) reqUrl := u.String() @@ -115,6 +131,10 @@ func (c *client) postBody(ctx context.Context, endpoint string, data interface{} defer resp.Body.Close() + if resp.Body == nil { + return resp.StatusCode, nil, errors.New("response body is nil") + } + var buf bytes.Buffer if _, err = io.Copy(&buf, resp.Body); err != nil { return resp.StatusCode, nil, errors.Wrap(err, "radarr.io.Copy") diff --git a/pkg/radarr/radarr.go b/pkg/radarr/radarr.go index a8d2e08..3ac5c46 100644 --- a/pkg/radarr/radarr.go +++ b/pkg/radarr/radarr.go @@ -65,7 +65,7 @@ type Release struct { InfoUrl string `json:"infoUrl,omitempty"` DownloadUrl string `json:"downloadUrl,omitempty"` MagnetUrl string `json:"magnetUrl,omitempty"` - Size int64 `json:"size"` + Size uint64 `json:"size"` Indexer string `json:"indexer"` DownloadProtocol string `json:"downloadProtocol"` Protocol string `json:"protocol"` diff --git a/pkg/readarr/client.go b/pkg/readarr/client.go index f1e1cca..f4a401f 100644 --- a/pkg/readarr/client.go +++ b/pkg/readarr/client.go @@ -17,6 +17,10 @@ import ( func (c *client) get(ctx context.Context, endpoint string) (int, []byte, error) { u, err := url.Parse(c.config.Hostname) + if err != nil { + return 0, nil, errors.Wrap(err, "could not parse url: %s", c.config.Hostname) + } + u.Path = path.Join(u.Path, "/api/v1/", endpoint) reqUrl := u.String() @@ -38,6 +42,10 @@ func (c *client) get(ctx context.Context, endpoint string) (int, []byte, error) defer resp.Body.Close() + if resp.Body == nil { + return resp.StatusCode, nil, errors.New("response body is nil") + } + var buf bytes.Buffer if _, err = io.Copy(&buf, resp.Body); err != nil { return resp.StatusCode, nil, errors.Wrap(err, "readarr.io.Copy") @@ -48,6 +56,10 @@ func (c *client) get(ctx context.Context, endpoint string) (int, []byte, error) func (c *client) post(ctx context.Context, endpoint string, data interface{}) (*http.Response, error) { u, err := url.Parse(c.config.Hostname) + if err != nil { + return nil, errors.Wrap(err, "could not parse url: %s", c.config.Hostname) + } + u.Path = path.Join(u.Path, "/api/v1/", endpoint) reqUrl := u.String() @@ -87,6 +99,10 @@ func (c *client) post(ctx context.Context, endpoint string, data interface{}) (* func (c *client) postBody(ctx context.Context, endpoint string, data interface{}) (int, []byte, error) { u, err := url.Parse(c.config.Hostname) + if err != nil { + return 0, nil, errors.Wrap(err, "could not parse url: %s", c.config.Hostname) + } + u.Path = path.Join(u.Path, "/api/v1/", endpoint) reqUrl := u.String() @@ -115,6 +131,10 @@ func (c *client) postBody(ctx context.Context, endpoint string, data interface{} defer resp.Body.Close() + if resp.Body == nil { + return resp.StatusCode, nil, errors.New("response body is nil") + } + var buf bytes.Buffer if _, err = io.Copy(&buf, resp.Body); err != nil { return resp.StatusCode, nil, errors.Wrap(err, "readarr.io.Copy") diff --git a/pkg/readarr/readarr.go b/pkg/readarr/readarr.go index 0c66257..e29dce8 100644 --- a/pkg/readarr/readarr.go +++ b/pkg/readarr/readarr.go @@ -67,7 +67,7 @@ type Release struct { InfoUrl string `json:"infoUrl,omitempty"` DownloadUrl string `json:"downloadUrl,omitempty"` MagnetUrl string `json:"magnetUrl,omitempty"` - Size int64 `json:"size"` + Size uint64 `json:"size"` Indexer string `json:"indexer"` DownloadProtocol string `json:"downloadProtocol"` Protocol string `json:"protocol"` diff --git a/pkg/sonarr/client.go b/pkg/sonarr/client.go index 141ced9..ababdc2 100644 --- a/pkg/sonarr/client.go +++ b/pkg/sonarr/client.go @@ -17,6 +17,10 @@ import ( func (c *client) get(ctx context.Context, endpoint string) (int, []byte, error) { u, err := url.Parse(c.config.Hostname) + if err != nil { + return 0, nil, errors.Wrap(err, "could not parse url: %s", c.config.Hostname) + } + u.Path = path.Join(u.Path, "/api/v3/", endpoint) reqUrl := u.String() @@ -38,6 +42,10 @@ func (c *client) get(ctx context.Context, endpoint string) (int, []byte, error) defer resp.Body.Close() + if resp.Body == nil { + return resp.StatusCode, nil, errors.New("response body is nil") + } + var buf bytes.Buffer if _, err = io.Copy(&buf, resp.Body); err != nil { return resp.StatusCode, nil, errors.Wrap(err, "sonarr.io.Copy") @@ -48,6 +56,10 @@ func (c *client) get(ctx context.Context, endpoint string) (int, []byte, error) func (c *client) post(ctx context.Context, endpoint string, data interface{}) (*http.Response, error) { u, err := url.Parse(c.config.Hostname) + if err != nil { + return nil, errors.Wrap(err, "could not parse url: %s", c.config.Hostname) + } + u.Path = path.Join(u.Path, "/api/v3/", endpoint) reqUrl := u.String() @@ -87,6 +99,10 @@ func (c *client) post(ctx context.Context, endpoint string, data interface{}) (* func (c *client) postBody(ctx context.Context, endpoint string, data interface{}) (int, []byte, error) { u, err := url.Parse(c.config.Hostname) + if err != nil { + return 0, nil, errors.Wrap(err, "could not parse url: %s", c.config.Hostname) + } + u.Path = path.Join(u.Path, "/api/v3/", endpoint) reqUrl := u.String() @@ -113,6 +129,10 @@ func (c *client) postBody(ctx context.Context, endpoint string, data interface{} defer resp.Body.Close() + if resp.Body == nil { + return resp.StatusCode, nil, errors.New("response body is nil") + } + var buf bytes.Buffer if _, err = io.Copy(&buf, resp.Body); err != nil { return resp.StatusCode, nil, errors.Wrap(err, "sonarr.io.Copy") diff --git a/pkg/sonarr/sonarr.go b/pkg/sonarr/sonarr.go index c74d68e..81e3377 100644 --- a/pkg/sonarr/sonarr.go +++ b/pkg/sonarr/sonarr.go @@ -67,7 +67,7 @@ type Release struct { InfoUrl string `json:"infoUrl,omitempty"` DownloadUrl string `json:"downloadUrl,omitempty"` MagnetUrl string `json:"magnetUrl,omitempty"` - Size int64 `json:"size"` + Size uint64 `json:"size"` Indexer string `json:"indexer"` DownloadProtocol string `json:"downloadProtocol"` Protocol string `json:"protocol"` diff --git a/pkg/whisparr/client.go b/pkg/whisparr/client.go index 9de186a..87b3d33 100644 --- a/pkg/whisparr/client.go +++ b/pkg/whisparr/client.go @@ -16,6 +16,10 @@ import ( func (c *client) get(ctx context.Context, endpoint string) (*http.Response, error) { u, err := url.Parse(c.config.Hostname) + if err != nil { + return nil, errors.Wrap(err, "could not parse url: %s", c.config.Hostname) + } + u.Path = path.Join(u.Path, "/api/v3/", endpoint) reqUrl := u.String() @@ -45,6 +49,10 @@ func (c *client) get(ctx context.Context, endpoint string) (*http.Response, erro func (c *client) post(ctx context.Context, endpoint string, data interface{}) (*http.Response, error) { u, err := url.Parse(c.config.Hostname) + if err != nil { + return nil, errors.Wrap(err, "could not parse url: %s", c.config.Hostname) + } + u.Path = path.Join(u.Path, "/api/v3/", endpoint) reqUrl := u.String() diff --git a/pkg/whisparr/whisparr.go b/pkg/whisparr/whisparr.go index 14d0b45..a965e3d 100644 --- a/pkg/whisparr/whisparr.go +++ b/pkg/whisparr/whisparr.go @@ -65,7 +65,7 @@ type Release struct { InfoUrl string `json:"infoUrl,omitempty"` DownloadUrl string `json:"downloadUrl,omitempty"` MagnetUrl string `json:"magnetUrl,omitempty"` - Size int64 `json:"size"` + Size uint64 `json:"size"` Indexer string `json:"indexer"` DownloadProtocol string `json:"downloadProtocol"` Protocol string `json:"protocol"`