mirror of
https://github.com/idanoo/autobrr
synced 2025-07-22 16:29:12 +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
|
@ -16,32 +16,19 @@ import (
|
|||
func (s *service) rtorrent(ctx context.Context, action *domain.Action, release domain.Release) ([]string, error) {
|
||||
s.log.Debug().Msgf("action rTorrent: %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)
|
||||
}
|
||||
|
||||
rt := client.Client.(*rtorrent.Client)
|
||||
|
||||
var rejections []string
|
||||
|
||||
// create config
|
||||
cfg := rtorrent.Config{
|
||||
Addr: client.Host,
|
||||
TLSSkipVerify: client.TLSSkipVerify,
|
||||
BasicUser: client.Settings.Basic.Username,
|
||||
BasicPass: client.Settings.Basic.Password,
|
||||
}
|
||||
|
||||
// create client
|
||||
rt := rtorrent.NewClient(cfg)
|
||||
|
||||
if release.HasMagnetUri() {
|
||||
var args []*rtorrent.FieldValue
|
||||
|
||||
|
@ -79,55 +66,54 @@ func (s *service) rtorrent(ctx context.Context, action *domain.Action, release d
|
|||
s.log.Info().Msgf("torrent from magnet successfully added to client: '%s'", client.Name)
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
} else {
|
||||
if release.TorrentTmpFile == "" {
|
||||
if err := release.DownloadTorrentFileCtx(ctx); err != nil {
|
||||
s.log.Error().Err(err).Msgf("could not download torrent file for release: %s", release.TorrentName)
|
||||
return nil, err
|
||||
}
|
||||
if release.TorrentTmpFile == "" {
|
||||
if err := release.DownloadTorrentFileCtx(ctx); err != nil {
|
||||
s.log.Error().Err(err).Msgf("could not download torrent file for release: %s", release.TorrentName)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
tmpFile, err := os.ReadFile(release.TorrentTmpFile)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not read torrent file: %s", release.TorrentTmpFile)
|
||||
}
|
||||
tmpFile, err := os.ReadFile(release.TorrentTmpFile)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not read torrent file: %s", release.TorrentTmpFile)
|
||||
}
|
||||
|
||||
var args []*rtorrent.FieldValue
|
||||
var args []*rtorrent.FieldValue
|
||||
|
||||
if action.Label != "" {
|
||||
if action.Label != "" {
|
||||
args = append(args, &rtorrent.FieldValue{
|
||||
Field: rtorrent.DLabel,
|
||||
Value: action.Label,
|
||||
})
|
||||
}
|
||||
if action.SavePath != "" {
|
||||
if action.ContentLayout == domain.ActionContentLayoutSubfolderNone {
|
||||
args = append(args, &rtorrent.FieldValue{
|
||||
Field: rtorrent.DLabel,
|
||||
Value: action.Label,
|
||||
Field: "d.directory_base",
|
||||
Value: action.SavePath,
|
||||
})
|
||||
} else {
|
||||
args = append(args, &rtorrent.FieldValue{
|
||||
Field: rtorrent.DDirectory,
|
||||
Value: action.SavePath,
|
||||
})
|
||||
}
|
||||
if action.SavePath != "" {
|
||||
if action.ContentLayout == domain.ActionContentLayoutSubfolderNone {
|
||||
args = append(args, &rtorrent.FieldValue{
|
||||
Field: "d.directory_base",
|
||||
Value: action.SavePath,
|
||||
})
|
||||
} else {
|
||||
args = append(args, &rtorrent.FieldValue{
|
||||
Field: rtorrent.DDirectory,
|
||||
Value: action.SavePath,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
var addTorrentFile func(context.Context, []byte, ...*rtorrent.FieldValue) error
|
||||
if action.Paused {
|
||||
addTorrentFile = rt.AddTorrentStopped
|
||||
} else {
|
||||
addTorrentFile = rt.AddTorrent
|
||||
}
|
||||
|
||||
if err := addTorrentFile(ctx, tmpFile, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "could not add torrent file: %s", release.TorrentTmpFile)
|
||||
}
|
||||
|
||||
s.log.Info().Msgf("torrent successfully added to client: '%s'", client.Name)
|
||||
}
|
||||
|
||||
var addTorrentFile func(context.Context, []byte, ...*rtorrent.FieldValue) error
|
||||
if action.Paused {
|
||||
addTorrentFile = rt.AddTorrentStopped
|
||||
} else {
|
||||
addTorrentFile = rt.AddTorrent
|
||||
}
|
||||
|
||||
if err := addTorrentFile(ctx, tmpFile, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "could not add torrent file: %s", release.TorrentTmpFile)
|
||||
}
|
||||
|
||||
s.log.Info().Msgf("torrent successfully added to client: '%s'", client.Name)
|
||||
|
||||
return rejections, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue