From eefd1b576c9678da3e6ef3906df511e6bafa6a78 Mon Sep 17 00:00:00 2001 From: Kyle Sanderson Date: Mon, 1 Aug 2022 06:21:29 -0700 Subject: [PATCH] fix(torznab): Jackett support (#388) * feat(torznab): add Jackett support * Update torznab.go * fix(feeds): unify jackett and prowlarr apikey --- pkg/torznab/torznab.go | 22 ++++++++++++++++------ pkg/torznab/torznab_test.go | 11 +++++++++-- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/pkg/torznab/torznab.go b/pkg/torznab/torznab.go index 765c784..1e448ce 100644 --- a/pkg/torznab/torznab.go +++ b/pkg/torznab/torznab.go @@ -70,6 +70,10 @@ func (c *client) get(endpoint string, opts map[string]string) (int, *Response, e "t": {"search"}, } + if c.ApiKey != "" { + params.Add("apikey", c.ApiKey) + } + u, err := url.Parse(c.Host) u.Path = strings.TrimSuffix(u.Path, "/") u.RawQuery = params.Encode() @@ -84,9 +88,10 @@ func (c *client) get(endpoint string, opts map[string]string) (int, *Response, e req.SetBasicAuth(c.BasicAuth.Username, c.BasicAuth.Password) } - if c.ApiKey != "" { - req.Header.Add("X-API-Key", c.ApiKey) - } + // Jackett only supports api key via url param while Prowlarr does that and via header + //if c.ApiKey != "" { + // req.Header.Add("X-API-Key", c.ApiKey) + //} resp, err := c.http.Do(req) if err != nil { @@ -126,6 +131,10 @@ func (c *client) getCaps(endpoint string, opts map[string]string) (int, *Caps, e "t": {"caps"}, } + if c.ApiKey != "" { + params.Add("apikey", c.ApiKey) + } + u, err := url.Parse(c.Host) u.Path = strings.TrimSuffix(u.Path, "/") u.RawQuery = params.Encode() @@ -140,9 +149,10 @@ func (c *client) getCaps(endpoint string, opts map[string]string) (int, *Caps, e req.SetBasicAuth(c.BasicAuth.Username, c.BasicAuth.Password) } - if c.ApiKey != "" { - req.Header.Add("X-API-Key", c.ApiKey) - } + // Jackett only supports api key via url param while Prowlarr does that and via header + //if c.ApiKey != "" { + // req.Header.Add("X-API-Key", c.ApiKey) + //} resp, err := c.http.Do(req) if err != nil { diff --git a/pkg/torznab/torznab_test.go b/pkg/torznab/torznab_test.go index 11d40f7..7867cdc 100644 --- a/pkg/torznab/torznab_test.go +++ b/pkg/torznab/torznab_test.go @@ -5,6 +5,7 @@ import ( "io/ioutil" "net/http" "net/http/httptest" + "strings" "testing" "github.com/stretchr/testify/assert" @@ -71,8 +72,14 @@ func TestClient_GetCaps(t *testing.T) { key := "mock-key" srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - apiKey := r.Header.Get("X-API-Key") - if apiKey != key { + //apiKey := r.Header.Get("X-API-Key") + //if apiKey != key { + // w.WriteHeader(http.StatusUnauthorized) + // w.Write(nil) + // return + //} + + if !strings.Contains(r.RequestURI, key) { w.WriteHeader(http.StatusUnauthorized) w.Write(nil) return