fix(actions): reject if client is disabled (#1626)

* fix(actions): error on disabled client

* fix(actions): sql scan args

* refactor: download client cache for actions

* fix: tests client store

* fix: tests client store and int conversion

* fix: tests revert findbyid ctx timeout

* fix: tests row.err

* feat: add logging to download client cache
This commit is contained in:
ze0s 2024-08-27 19:45:06 +02:00 committed by GitHub
parent 77e1c2c305
commit 861f30c144
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
30 changed files with 928 additions and 680 deletions

View file

@ -17,40 +17,16 @@ func (s *service) sonarr(ctx context.Context, action *domain.Action, release dom
// TODO validate data
// get client for action
client, err := s.clientSvc.FindByID(ctx, action.ClientID)
client, err := s.clientSvc.GetClient(ctx, action.ClientID)
if err != nil {
return nil, errors.Wrap(err, "sonarr could not find client: %v", action.ClientID)
return nil, errors.Wrap(err, "could not get client with id %d", action.ClientID)
}
// return early if no client found
if client == nil {
return nil, errors.New("no client found")
if !client.Enabled {
return nil, errors.New("client %s %s not enabled", client.Type, client.Name)
}
// initial config
cfg := sonarr.Config{
Hostname: client.Host,
APIKey: client.Settings.APIKey,
Log: s.subLogger,
}
// only set basic auth if enabled
if client.Settings.Basic.Auth {
cfg.BasicAuth = client.Settings.Basic.Auth
cfg.Username = client.Settings.Basic.Username
cfg.Password = client.Settings.Basic.Password
}
externalClientId := client.Settings.ExternalDownloadClientId
if action.ExternalDownloadClientID > 0 {
externalClientId = int(action.ExternalDownloadClientID)
}
externalClient := client.Settings.ExternalDownloadClient
if action.ExternalDownloadClient != "" {
externalClient = action.ExternalDownloadClient
}
arr := client.Client.(sonarr.Client)
r := sonarr.Release{
Title: release.TorrentName,
@ -59,14 +35,20 @@ func (s *service) sonarr(ctx context.Context, action *domain.Action, release dom
MagnetUrl: release.MagnetURI,
Size: int64(release.Size),
Indexer: release.Indexer.GetExternalIdentifier(),
DownloadClientId: externalClientId,
DownloadClient: externalClient,
DownloadClientId: client.Settings.ExternalDownloadClientId,
DownloadClient: client.Settings.ExternalDownloadClient,
DownloadProtocol: release.Protocol.String(),
Protocol: release.Protocol.String(),
PublishDate: time.Now().Format(time.RFC3339),
}
arr := sonarr.New(cfg)
if action.ExternalDownloadClientID > 0 {
r.DownloadClientId = int(action.ExternalDownloadClientID)
}
if action.ExternalDownloadClient != "" {
r.DownloadClient = action.ExternalDownloadClient
}
rejections, err := arr.Push(ctx, r)
if err != nil {