mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 08:49:13 +00:00
fix(torznab): Jackett support (#388)
* feat(torznab): add Jackett support * Update torznab.go * fix(feeds): unify jackett and prowlarr apikey
This commit is contained in:
parent
a9fe2cf500
commit
eefd1b576c
2 changed files with 25 additions and 8 deletions
|
@ -70,6 +70,10 @@ func (c *client) get(endpoint string, opts map[string]string) (int, *Response, e
|
||||||
"t": {"search"},
|
"t": {"search"},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.ApiKey != "" {
|
||||||
|
params.Add("apikey", c.ApiKey)
|
||||||
|
}
|
||||||
|
|
||||||
u, err := url.Parse(c.Host)
|
u, err := url.Parse(c.Host)
|
||||||
u.Path = strings.TrimSuffix(u.Path, "/")
|
u.Path = strings.TrimSuffix(u.Path, "/")
|
||||||
u.RawQuery = params.Encode()
|
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)
|
req.SetBasicAuth(c.BasicAuth.Username, c.BasicAuth.Password)
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.ApiKey != "" {
|
// Jackett only supports api key via url param while Prowlarr does that and via header
|
||||||
req.Header.Add("X-API-Key", c.ApiKey)
|
//if c.ApiKey != "" {
|
||||||
}
|
// req.Header.Add("X-API-Key", c.ApiKey)
|
||||||
|
//}
|
||||||
|
|
||||||
resp, err := c.http.Do(req)
|
resp, err := c.http.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -126,6 +131,10 @@ func (c *client) getCaps(endpoint string, opts map[string]string) (int, *Caps, e
|
||||||
"t": {"caps"},
|
"t": {"caps"},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.ApiKey != "" {
|
||||||
|
params.Add("apikey", c.ApiKey)
|
||||||
|
}
|
||||||
|
|
||||||
u, err := url.Parse(c.Host)
|
u, err := url.Parse(c.Host)
|
||||||
u.Path = strings.TrimSuffix(u.Path, "/")
|
u.Path = strings.TrimSuffix(u.Path, "/")
|
||||||
u.RawQuery = params.Encode()
|
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)
|
req.SetBasicAuth(c.BasicAuth.Username, c.BasicAuth.Password)
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.ApiKey != "" {
|
// Jackett only supports api key via url param while Prowlarr does that and via header
|
||||||
req.Header.Add("X-API-Key", c.ApiKey)
|
//if c.ApiKey != "" {
|
||||||
}
|
// req.Header.Add("X-API-Key", c.ApiKey)
|
||||||
|
//}
|
||||||
|
|
||||||
resp, err := c.http.Do(req)
|
resp, err := c.http.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -71,8 +72,14 @@ func TestClient_GetCaps(t *testing.T) {
|
||||||
key := "mock-key"
|
key := "mock-key"
|
||||||
|
|
||||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
apiKey := r.Header.Get("X-API-Key")
|
//apiKey := r.Header.Get("X-API-Key")
|
||||||
if apiKey != key {
|
//if apiKey != key {
|
||||||
|
// w.WriteHeader(http.StatusUnauthorized)
|
||||||
|
// w.Write(nil)
|
||||||
|
// return
|
||||||
|
//}
|
||||||
|
|
||||||
|
if !strings.Contains(r.RequestURI, key) {
|
||||||
w.WriteHeader(http.StatusUnauthorized)
|
w.WriteHeader(http.StatusUnauthorized)
|
||||||
w.Write(nil)
|
w.Write(nil)
|
||||||
return
|
return
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue