Add the Config view: edit and save the settings, applied without a restart
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -11,16 +11,26 @@ import (
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Client talks to a SABnzbd instance.
|
||||
type Client struct {
|
||||
mu sync.RWMutex // guards baseURL and apiKey, which Reconfigure can change
|
||||
baseURL string
|
||||
apiKey string
|
||||
http *http.Client
|
||||
}
|
||||
|
||||
// Reconfigure points the client at another instance or key.
|
||||
func (c *Client) Reconfigure(baseURL, apiKey string) {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
c.baseURL = strings.TrimRight(baseURL, "/")
|
||||
c.apiKey = apiKey
|
||||
}
|
||||
|
||||
// NewClient returns a client for the instance at baseURL.
|
||||
func NewClient(baseURL, apiKey string) *Client {
|
||||
return &Client{
|
||||
@@ -159,9 +169,12 @@ func boolParam(b bool) string {
|
||||
// {"status": false, "error": "..."}, which is turned into an error here.
|
||||
func (c *Client) call(ctx context.Context, params url.Values, out any) error {
|
||||
params.Set("output", "json")
|
||||
params.Set("apikey", c.apiKey)
|
||||
c.mu.RLock()
|
||||
baseURL, apiKey := c.baseURL, c.apiKey
|
||||
c.mu.RUnlock()
|
||||
params.Set("apikey", apiKey)
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, c.baseURL+"/api?"+params.Encode(), nil)
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, baseURL+"/api?"+params.Encode(), nil)
|
||||
if err != nil {
|
||||
return stripURL(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user