mirror of
https://github.com/idanoo/autobrr
synced 2025-07-22 16:29:12 +00:00
feat(actions): simplify macro parsing (#560)
* refactor(action): parse macros * feat(action): add ctx to arr clients and test
This commit is contained in:
parent
f6e68fae2b
commit
839eb9f3f3
31 changed files with 323 additions and 334 deletions
|
@ -30,22 +30,23 @@ func (s *service) testConnection(ctx context.Context, client domain.DownloadClie
|
|||
return s.testRTorrentConnection(client)
|
||||
|
||||
case domain.DownloadClientTypeTransmission:
|
||||
return s.testTransmissionConnection(client)
|
||||
return s.testTransmissionConnection(ctx, client)
|
||||
|
||||
case domain.DownloadClientTypeRadarr:
|
||||
return s.testRadarrConnection(client)
|
||||
return s.testRadarrConnection(ctx, client)
|
||||
|
||||
case domain.DownloadClientTypeSonarr:
|
||||
return s.testSonarrConnection(client)
|
||||
return s.testSonarrConnection(ctx, client)
|
||||
|
||||
case domain.DownloadClientTypeLidarr:
|
||||
return s.testLidarrConnection(client)
|
||||
return s.testLidarrConnection(ctx, client)
|
||||
|
||||
case domain.DownloadClientTypeWhisparr:
|
||||
return s.testWhisparrConnection(client)
|
||||
return s.testWhisparrConnection(ctx, client)
|
||||
|
||||
case domain.DownloadClientTypeReadarr:
|
||||
return s.testReadarrConnection(client)
|
||||
return s.testReadarrConnection(ctx, client)
|
||||
|
||||
default:
|
||||
return errors.New("unsupported client")
|
||||
}
|
||||
|
@ -138,7 +139,7 @@ func (s *service) testRTorrentConnection(client domain.DownloadClient) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *service) testTransmissionConnection(client domain.DownloadClient) error {
|
||||
func (s *service) testTransmissionConnection(ctx context.Context, client domain.DownloadClient) error {
|
||||
tbt, err := transmissionrpc.New(client.Host, client.Username, client.Password, &transmissionrpc.AdvancedConfig{
|
||||
HTTPS: client.TLS,
|
||||
Port: uint16(client.Port),
|
||||
|
@ -147,7 +148,7 @@ func (s *service) testTransmissionConnection(client domain.DownloadClient) error
|
|||
return errors.Wrap(err, "error logging into client: %v", client.Host)
|
||||
}
|
||||
|
||||
ok, version, _, err := tbt.RPCVersion(context.TODO())
|
||||
ok, version, _, err := tbt.RPCVersion(ctx)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error getting rpc info: %v", client.Host)
|
||||
}
|
||||
|
@ -163,7 +164,7 @@ func (s *service) testTransmissionConnection(client domain.DownloadClient) error
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *service) testRadarrConnection(client domain.DownloadClient) error {
|
||||
func (s *service) testRadarrConnection(ctx context.Context, client domain.DownloadClient) error {
|
||||
r := radarr.New(radarr.Config{
|
||||
Hostname: client.Host,
|
||||
APIKey: client.Settings.APIKey,
|
||||
|
@ -173,8 +174,7 @@ func (s *service) testRadarrConnection(client domain.DownloadClient) error {
|
|||
Log: s.subLogger,
|
||||
})
|
||||
|
||||
_, err := r.Test()
|
||||
if err != nil {
|
||||
if _, err := r.Test(ctx); err != nil {
|
||||
return errors.Wrap(err, "radarr: connection test failed: %v", client.Host)
|
||||
}
|
||||
|
||||
|
@ -183,7 +183,7 @@ func (s *service) testRadarrConnection(client domain.DownloadClient) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *service) testSonarrConnection(client domain.DownloadClient) error {
|
||||
func (s *service) testSonarrConnection(ctx context.Context, client domain.DownloadClient) error {
|
||||
r := sonarr.New(sonarr.Config{
|
||||
Hostname: client.Host,
|
||||
APIKey: client.Settings.APIKey,
|
||||
|
@ -193,8 +193,7 @@ func (s *service) testSonarrConnection(client domain.DownloadClient) error {
|
|||
Log: s.subLogger,
|
||||
})
|
||||
|
||||
_, err := r.Test()
|
||||
if err != nil {
|
||||
if _, err := r.Test(ctx); err != nil {
|
||||
return errors.Wrap(err, "sonarr: connection test failed: %v", client.Host)
|
||||
}
|
||||
|
||||
|
@ -203,7 +202,7 @@ func (s *service) testSonarrConnection(client domain.DownloadClient) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *service) testLidarrConnection(client domain.DownloadClient) error {
|
||||
func (s *service) testLidarrConnection(ctx context.Context, client domain.DownloadClient) error {
|
||||
r := lidarr.New(lidarr.Config{
|
||||
Hostname: client.Host,
|
||||
APIKey: client.Settings.APIKey,
|
||||
|
@ -213,8 +212,7 @@ func (s *service) testLidarrConnection(client domain.DownloadClient) error {
|
|||
Log: s.subLogger,
|
||||
})
|
||||
|
||||
_, err := r.Test()
|
||||
if err != nil {
|
||||
if _, err := r.Test(ctx); err != nil {
|
||||
return errors.Wrap(err, "lidarr: connection test failed: %v", client.Host)
|
||||
}
|
||||
|
||||
|
@ -223,7 +221,7 @@ func (s *service) testLidarrConnection(client domain.DownloadClient) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *service) testWhisparrConnection(client domain.DownloadClient) error {
|
||||
func (s *service) testWhisparrConnection(ctx context.Context, client domain.DownloadClient) error {
|
||||
r := whisparr.New(whisparr.Config{
|
||||
Hostname: client.Host,
|
||||
APIKey: client.Settings.APIKey,
|
||||
|
@ -233,8 +231,7 @@ func (s *service) testWhisparrConnection(client domain.DownloadClient) error {
|
|||
Log: s.subLogger,
|
||||
})
|
||||
|
||||
_, err := r.Test()
|
||||
if err != nil {
|
||||
if _, err := r.Test(ctx); err != nil {
|
||||
return errors.Wrap(err, "whisparr: connection test failed: %v", client.Host)
|
||||
}
|
||||
|
||||
|
@ -243,7 +240,7 @@ func (s *service) testWhisparrConnection(client domain.DownloadClient) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *service) testReadarrConnection(client domain.DownloadClient) error {
|
||||
func (s *service) testReadarrConnection(ctx context.Context, client domain.DownloadClient) error {
|
||||
r := readarr.New(readarr.Config{
|
||||
Hostname: client.Host,
|
||||
APIKey: client.Settings.APIKey,
|
||||
|
@ -253,8 +250,7 @@ func (s *service) testReadarrConnection(client domain.DownloadClient) error {
|
|||
Log: s.subLogger,
|
||||
})
|
||||
|
||||
_, err := r.Test()
|
||||
if err != nil {
|
||||
if _, err := r.Test(ctx); err != nil {
|
||||
return errors.Wrap(err, "readarr: connection test failed: %v", client.Host)
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ package download_client
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"log"
|
||||
"sync"
|
||||
|
||||
|
@ -69,11 +68,9 @@ func (s *service) FindByID(ctx context.Context, id int32) (*domain.DownloadClien
|
|||
}
|
||||
|
||||
func (s *service) Store(ctx context.Context, client domain.DownloadClient) (*domain.DownloadClient, error) {
|
||||
// validate data
|
||||
if client.Host == "" {
|
||||
return nil, errors.New("validation error: no host")
|
||||
} else if client.Type == "" {
|
||||
return nil, errors.New("validation error: no type")
|
||||
// basic validation of client
|
||||
if err := client.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// store
|
||||
|
@ -87,11 +84,9 @@ func (s *service) Store(ctx context.Context, client domain.DownloadClient) (*dom
|
|||
}
|
||||
|
||||
func (s *service) Update(ctx context.Context, client domain.DownloadClient) (*domain.DownloadClient, error) {
|
||||
// validate data
|
||||
if client.Host == "" {
|
||||
return nil, errors.New("validation error: no host")
|
||||
} else if client.Type == "" {
|
||||
return nil, errors.New("validation error: no type")
|
||||
// basic validation of client
|
||||
if err := client.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// update
|
||||
|
@ -125,10 +120,8 @@ func (s *service) Delete(ctx context.Context, clientID int) error {
|
|||
|
||||
func (s *service) Test(ctx context.Context, client domain.DownloadClient) error {
|
||||
// basic validation of client
|
||||
if client.Host == "" {
|
||||
return errors.New("validation error: no host")
|
||||
} else if client.Type == "" {
|
||||
return errors.New("validation error: no type")
|
||||
if err := client.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// test
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue