mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 00:39:13 +00:00
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:
parent
77e1c2c305
commit
861f30c144
30 changed files with 928 additions and 680 deletions
|
@ -6,14 +6,11 @@ package action
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/autobrr/autobrr/internal/domain"
|
||||
"github.com/autobrr/autobrr/pkg/errors"
|
||||
"github.com/autobrr/autobrr/pkg/transmission"
|
||||
|
||||
"github.com/hekmon/transmissionrpc/v3"
|
||||
)
|
||||
|
||||
|
@ -28,38 +25,16 @@ var TrTrue = true
|
|||
func (s *service) transmission(ctx context.Context, action *domain.Action, release domain.Release) ([]string, error) {
|
||||
s.log.Debug().Msgf("action Transmission: %s", action.Name)
|
||||
|
||||
var err error
|
||||
|
||||
// get client for action
|
||||
client, err := s.clientSvc.FindByID(ctx, action.ClientID)
|
||||
client, err := s.clientSvc.GetClient(ctx, action.ClientID)
|
||||
if err != nil {
|
||||
s.log.Error().Stack().Err(err).Msgf("error finding client: %d", action.ClientID)
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "could not get client with id %d", action.ClientID)
|
||||
}
|
||||
|
||||
if client == nil {
|
||||
return nil, errors.New("could not find client by id: %d", action.ClientID)
|
||||
if !client.Enabled {
|
||||
return nil, errors.New("client %s %s not enabled", client.Type, client.Name)
|
||||
}
|
||||
|
||||
scheme := "http"
|
||||
if client.TLS {
|
||||
scheme = "https"
|
||||
}
|
||||
|
||||
u, err := url.Parse(fmt.Sprintf("%s://%s:%d/transmission/rpc", scheme, client.Host, client.Port))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
tbt, err := transmission.New(u, &transmission.Config{
|
||||
UserAgent: "autobrr",
|
||||
Username: client.Username,
|
||||
Password: client.Password,
|
||||
TLSSkipVerify: client.TLSSkipVerify,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "error logging into client: %s", client.Host)
|
||||
}
|
||||
tbt := client.Client.(*transmissionrpc.Client)
|
||||
|
||||
rejections, err := s.transmissionCheckRulesCanDownload(ctx, action, client, tbt)
|
||||
if err != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue