Skip to content

Commit

Permalink
fix(config): renamed default client causes error (#61)
Browse files Browse the repository at this point in the history
* fix(config): renamed default client causes error

* fix(config): init map to void panic
  • Loading branch information
nuxencs authored Jan 16, 2024
1 parent d606de2 commit 1f56c69
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 23 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 4 additions & 13 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 4 additions & 7 deletions internal/http/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 1f56c69

Please sign in to comment.