From 1f56c6954754efa67fecf8cc1bfe11f6a8f18dcb Mon Sep 17 00:00:00 2001 From: nuxen <47067662+nuxencs@users.noreply.github.com> Date: Tue, 16 Jan 2024 16:20:56 +0100 Subject: [PATCH] fix(config): renamed default client causes error (#61) * fix(config): renamed default client causes error * fix(config): init map to void panic --- README.md | 3 +-- config.yaml | 1 - internal/config/config.go | 17 ++++------------- internal/http/processor.go | 11 ++++------- 4 files changed, 9 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 3815dfa..32850a5 100644 --- a/README.md +++ b/README.md @@ -173,8 +173,7 @@ to look like this: ``` Replace the `clientname` value, in this case `default`, with the name you gave your desired qBittorrent client in your -config under the `clients` section. If you don't specify `clientname` in the JSON payload, the `default` client defined -in your config will be used. +config under the `clients` section. You need to specify a `clientname` in the JSON payload otherwise the request will fail. #### API Authentication diff --git a/config.yaml b/config.yaml index a977096..d83b45e 100644 --- a/config.yaml +++ b/config.yaml @@ -14,7 +14,6 @@ port: 42069 clients: # Client name used in the autobrr filter, can be customized to whatever you like - # If you change the name of the default client you always need to specify that name in the autobrr filter # Note that a client name has to be unique and can only be used once # # Default: default diff --git a/internal/config/config.go b/internal/config/config.go index 80fd26f..ccbf498 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -41,7 +41,6 @@ port: 42069 clients: # Client name used in the autobrr filter, can be customized to whatever you like - # If you change the name of the default client you always need to specify that name in the autobrr filter # Note that a client name has to be unique and can only be used once # # Default: default @@ -267,18 +266,10 @@ func New(configPath string, version string) *AppConfig { func (c *AppConfig) defaults() { c.Config = &domain.Config{ - Version: "dev", - Host: "0.0.0.0", - Port: 42069, - Clients: map[string]*domain.Client{ - "default": { - Host: "127.0.0.1", - Port: 8080, - Username: "admin", - Password: "adminadmin", - PreImportPath: "", - }, - }, + Version: "dev", + Host: "0.0.0.0", + Port: 42069, + Clients: make(map[string]*domain.Client), LogLevel: "DEBUG", LogPath: "", LogMaxSize: 50, diff --git a/internal/http/processor.go b/internal/http/processor.go index ddeae25..154f3e9 100644 --- a/internal/http/processor.go +++ b/internal/http/processor.go @@ -157,14 +157,11 @@ func (p processor) ProcessSeasonPack(w netHTTP.ResponseWriter, r *netHTTP.Reques client, ok := p.cfg.Config.Clients[clientName] if !ok { - p.log.Info().Msgf("client not found in config: %q", clientName) - - // use default client - clientName = "default" - client = p.cfg.Config.Clients[clientName] - - p.log.Info().Msgf("using default client serving at %s:%d", client.Host, client.Port) + p.log.Error().Msgf("client not found in config: %q", clientName) + netHTTP.Error(w, fmt.Sprintf("client not found in config: %q", clientName), 472) + return } + p.log.Info().Msgf("using %q client serving at %s:%d", clientName, client.Host, client.Port) if len(p.req.Name) == 0 { p.log.Error().Msgf("error getting announce name")