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:
2026-10-20 23:31:13 +02:00
co-authored by Claude Sonnet 5.5
parent 0ccd02b3c5
commit a4ec9ad71e
25 changed files with 1168 additions and 54 deletions
+21 -2
View File
@@ -11,16 +11,34 @@ import (
"net/http"
"net/url"
"strings"
"sync"
"time"
)
// Client is a minimal JSON client for the Radarr/Sonarr v3 API.
type Client struct {
mu sync.RWMutex // guards baseURL and apiKey, which Reconfigure can change
baseURL string
apiKey string
http *http.Client
}
// settings returns the current base URL and API key.
func (c *Client) settings() (baseURL, apiKey string) {
c.mu.RLock()
defer c.mu.RUnlock()
return c.baseURL, c.apiKey
}
// Reconfigure points the client at another instance or key. Requests already
// in flight are not affected.
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 (without /api/v3).
func NewClient(baseURL, apiKey string) *Client {
return &Client{
@@ -46,7 +64,8 @@ func (e *APIError) Error() string {
// Do sends a request to /api/v3/<path>. body (if non-nil) is JSON-encoded and
// the response is decoded into out (if non-nil).
func (c *Client) Do(ctx context.Context, method, path string, query url.Values, body, out any) error {
u := c.baseURL + "/api/v3/" + strings.TrimLeft(path, "/")
base, apiKey := c.settings()
u := base + "/api/v3/" + strings.TrimLeft(path, "/")
if len(query) > 0 {
u += "?" + query.Encode()
}
@@ -64,7 +83,7 @@ func (c *Client) Do(ctx context.Context, method, path string, query url.Values,
if err != nil {
return err
}
req.Header.Set("X-Api-Key", c.apiKey)
req.Header.Set("X-Api-Key", apiKey)
req.Header.Set("Accept", "application/json")
if body != nil {
req.Header.Set("Content-Type", "application/json")