mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 00:39:13 +00:00
fix(releases): retry action missing external indexer identifier (#1612)
* fix(releases): retry action missing external identifier * fix(actions): arrs set fallback indexer identifier
This commit is contained in:
parent
3183e15a4b
commit
abfac05b66
9 changed files with 105 additions and 18 deletions
|
@ -59,11 +59,11 @@ func (s *service) lidarr(ctx context.Context, action *domain.Action, release dom
|
||||||
DownloadUrl: release.DownloadURL,
|
DownloadUrl: release.DownloadURL,
|
||||||
MagnetUrl: release.MagnetURI,
|
MagnetUrl: release.MagnetURI,
|
||||||
Size: int64(release.Size),
|
Size: int64(release.Size),
|
||||||
Indexer: release.Indexer.IdentifierExternal,
|
Indexer: release.Indexer.GetExternalIdentifier(),
|
||||||
DownloadClientId: externalClientId,
|
DownloadClientId: externalClientId,
|
||||||
DownloadClient: externalClient,
|
DownloadClient: externalClient,
|
||||||
DownloadProtocol: string(release.Protocol),
|
DownloadProtocol: release.Protocol.String(),
|
||||||
Protocol: string(release.Protocol),
|
Protocol: release.Protocol.String(),
|
||||||
PublishDate: time.Now().Format(time.RFC3339),
|
PublishDate: time.Now().Format(time.RFC3339),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,11 +58,11 @@ func (s *service) radarr(ctx context.Context, action *domain.Action, release dom
|
||||||
DownloadUrl: release.DownloadURL,
|
DownloadUrl: release.DownloadURL,
|
||||||
MagnetUrl: release.MagnetURI,
|
MagnetUrl: release.MagnetURI,
|
||||||
Size: int64(release.Size),
|
Size: int64(release.Size),
|
||||||
Indexer: release.Indexer.IdentifierExternal,
|
Indexer: release.Indexer.GetExternalIdentifier(),
|
||||||
DownloadClientId: externalClientId,
|
DownloadClientId: externalClientId,
|
||||||
DownloadClient: externalClient,
|
DownloadClient: externalClient,
|
||||||
DownloadProtocol: string(release.Protocol),
|
DownloadProtocol: release.Protocol.String(),
|
||||||
Protocol: string(release.Protocol),
|
Protocol: release.Protocol.String(),
|
||||||
PublishDate: time.Now().Format(time.RFC3339),
|
PublishDate: time.Now().Format(time.RFC3339),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,11 +58,11 @@ func (s *service) readarr(ctx context.Context, action *domain.Action, release do
|
||||||
DownloadUrl: release.DownloadURL,
|
DownloadUrl: release.DownloadURL,
|
||||||
MagnetUrl: release.MagnetURI,
|
MagnetUrl: release.MagnetURI,
|
||||||
Size: int64(release.Size),
|
Size: int64(release.Size),
|
||||||
Indexer: release.Indexer.IdentifierExternal,
|
Indexer: release.Indexer.GetExternalIdentifier(),
|
||||||
DownloadClientId: externalClientId,
|
DownloadClientId: externalClientId,
|
||||||
DownloadClient: externalClient,
|
DownloadClient: externalClient,
|
||||||
DownloadProtocol: string(release.Protocol),
|
DownloadProtocol: release.Protocol.String(),
|
||||||
Protocol: string(release.Protocol),
|
Protocol: release.Protocol.String(),
|
||||||
PublishDate: time.Now().Format(time.RFC3339),
|
PublishDate: time.Now().Format(time.RFC3339),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,11 +58,11 @@ func (s *service) sonarr(ctx context.Context, action *domain.Action, release dom
|
||||||
DownloadUrl: release.DownloadURL,
|
DownloadUrl: release.DownloadURL,
|
||||||
MagnetUrl: release.MagnetURI,
|
MagnetUrl: release.MagnetURI,
|
||||||
Size: int64(release.Size),
|
Size: int64(release.Size),
|
||||||
Indexer: release.Indexer.IdentifierExternal,
|
Indexer: release.Indexer.GetExternalIdentifier(),
|
||||||
DownloadClientId: externalClientId,
|
DownloadClientId: externalClientId,
|
||||||
DownloadClient: externalClient,
|
DownloadClient: externalClient,
|
||||||
DownloadProtocol: string(release.Protocol),
|
DownloadProtocol: release.Protocol.String(),
|
||||||
Protocol: string(release.Protocol),
|
Protocol: release.Protocol.String(),
|
||||||
PublishDate: time.Now().Format(time.RFC3339),
|
PublishDate: time.Now().Format(time.RFC3339),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,11 +58,11 @@ func (s *service) whisparr(ctx context.Context, action *domain.Action, release d
|
||||||
DownloadUrl: release.DownloadURL,
|
DownloadUrl: release.DownloadURL,
|
||||||
MagnetUrl: release.MagnetURI,
|
MagnetUrl: release.MagnetURI,
|
||||||
Size: int64(release.Size),
|
Size: int64(release.Size),
|
||||||
Indexer: release.Indexer.IdentifierExternal,
|
Indexer: release.Indexer.GetExternalIdentifier(),
|
||||||
DownloadClientId: externalClientId,
|
DownloadClientId: externalClientId,
|
||||||
DownloadClient: externalClient,
|
DownloadClient: externalClient,
|
||||||
DownloadProtocol: string(release.Protocol),
|
DownloadProtocol: release.Protocol.String(),
|
||||||
Protocol: string(release.Protocol),
|
Protocol: release.Protocol.String(),
|
||||||
PublishDate: time.Now().Format(time.RFC3339),
|
PublishDate: time.Now().Format(time.RFC3339),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -165,6 +165,51 @@ func (r *IndexerRepo) FindByID(ctx context.Context, id int) (*domain.Indexer, er
|
||||||
return &i, nil
|
return &i, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *IndexerRepo) GetBy(ctx context.Context, req domain.GetIndexerRequest) (*domain.Indexer, error) {
|
||||||
|
queryBuilder := r.db.squirrel.
|
||||||
|
Select("id", "enabled", "name", "identifier", "identifier_external", "implementation", "base_url", "settings").
|
||||||
|
From("indexer")
|
||||||
|
|
||||||
|
if req.ID > 0 {
|
||||||
|
queryBuilder = queryBuilder.Where(sq.Eq{"id": req.ID})
|
||||||
|
} else if req.Name != "" {
|
||||||
|
queryBuilder = queryBuilder.Where(sq.Eq{"name": req.Name})
|
||||||
|
} else if req.Identifier != "" {
|
||||||
|
queryBuilder = queryBuilder.Where(sq.Eq{"identifier": req.Identifier})
|
||||||
|
}
|
||||||
|
|
||||||
|
query, args, err := queryBuilder.ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "error building query")
|
||||||
|
}
|
||||||
|
|
||||||
|
row := r.db.handler.QueryRowContext(ctx, query, args...)
|
||||||
|
if err := row.Err(); err != nil {
|
||||||
|
return nil, errors.Wrap(err, "error executing query")
|
||||||
|
}
|
||||||
|
|
||||||
|
var i domain.Indexer
|
||||||
|
|
||||||
|
var identifierExternal, implementation, baseURL, settings sql.Null[string]
|
||||||
|
|
||||||
|
if err := row.Scan(&i.ID, &i.Enabled, &i.Name, &i.Identifier, &identifierExternal, &implementation, &baseURL, &settings); err != nil {
|
||||||
|
return nil, errors.Wrap(err, "error scanning row")
|
||||||
|
}
|
||||||
|
|
||||||
|
i.IdentifierExternal = identifierExternal.V
|
||||||
|
i.Implementation = implementation.V
|
||||||
|
i.BaseURL = baseURL.V
|
||||||
|
|
||||||
|
var settingsMap map[string]string
|
||||||
|
if err = json.Unmarshal([]byte(settings.V), &settingsMap); err != nil {
|
||||||
|
return nil, errors.Wrap(err, "error unmarshal settings")
|
||||||
|
}
|
||||||
|
|
||||||
|
i.Settings = settingsMap
|
||||||
|
|
||||||
|
return &i, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (r *IndexerRepo) FindByFilterID(ctx context.Context, id int) ([]domain.Indexer, error) {
|
func (r *IndexerRepo) FindByFilterID(ctx context.Context, id int) ([]domain.Indexer, error) {
|
||||||
queryBuilder := r.db.squirrel.
|
queryBuilder := r.db.squirrel.
|
||||||
Select("id", "enabled", "name", "identifier", "identifier_external", "base_url", "settings").
|
Select("id", "enabled", "name", "identifier", "identifier_external", "base_url", "settings").
|
||||||
|
|
|
@ -22,6 +22,7 @@ type IndexerRepo interface {
|
||||||
Delete(ctx context.Context, id int) error
|
Delete(ctx context.Context, id int) error
|
||||||
FindByFilterID(ctx context.Context, id int) ([]Indexer, error)
|
FindByFilterID(ctx context.Context, id int) ([]Indexer, error)
|
||||||
FindByID(ctx context.Context, id int) (*Indexer, error)
|
FindByID(ctx context.Context, id int) (*Indexer, error)
|
||||||
|
GetBy(ctx context.Context, req GetIndexerRequest) (*Indexer, error)
|
||||||
ToggleEnabled(ctx context.Context, indexerID int, enabled bool) error
|
ToggleEnabled(ctx context.Context, indexerID int, enabled bool) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,6 +44,14 @@ type IndexerMinimal struct {
|
||||||
IdentifierExternal string `json:"identifier_external"`
|
IdentifierExternal string `json:"identifier_external"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m IndexerMinimal) GetExternalIdentifier() string {
|
||||||
|
if m.IdentifierExternal != "" {
|
||||||
|
return m.IdentifierExternal
|
||||||
|
}
|
||||||
|
|
||||||
|
return m.Identifier
|
||||||
|
}
|
||||||
|
|
||||||
type IndexerDefinition struct {
|
type IndexerDefinition struct {
|
||||||
ID int `json:"id,omitempty"`
|
ID int `json:"id,omitempty"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
@ -412,3 +421,9 @@ type IndexerTestApiRequest struct {
|
||||||
ApiUser string `json:"api_user,omitempty"`
|
ApiUser string `json:"api_user,omitempty"`
|
||||||
ApiKey string `json:"api_key"`
|
ApiKey string `json:"api_key"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type GetIndexerRequest struct {
|
||||||
|
ID int
|
||||||
|
Identifier string
|
||||||
|
Name string
|
||||||
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ type Service interface {
|
||||||
FindByFilterID(ctx context.Context, id int) ([]domain.Indexer, error)
|
FindByFilterID(ctx context.Context, id int) ([]domain.Indexer, error)
|
||||||
FindByID(ctx context.Context, id int) (*domain.Indexer, error)
|
FindByID(ctx context.Context, id int) (*domain.Indexer, error)
|
||||||
List(ctx context.Context) ([]domain.Indexer, error)
|
List(ctx context.Context) ([]domain.Indexer, error)
|
||||||
|
GetBy(ctx context.Context, req domain.GetIndexerRequest) (*domain.Indexer, error)
|
||||||
GetAll() ([]*domain.IndexerDefinition, error)
|
GetAll() ([]*domain.IndexerDefinition, error)
|
||||||
GetTemplates() ([]domain.IndexerDefinition, error)
|
GetTemplates() ([]domain.IndexerDefinition, error)
|
||||||
LoadIndexerDefinitions() error
|
LoadIndexerDefinitions() error
|
||||||
|
@ -98,6 +99,10 @@ func (s *service) Store(ctx context.Context, indexer domain.Indexer) (*domain.In
|
||||||
indexer.Identifier = slug.Make(fmt.Sprintf("%s-%s", indexer.Implementation, cleanName))
|
indexer.Identifier = slug.Make(fmt.Sprintf("%s-%s", indexer.Implementation, cleanName))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if indexer.IdentifierExternal == "" {
|
||||||
|
indexer.IdentifierExternal = indexer.Name
|
||||||
|
}
|
||||||
|
|
||||||
i, err := s.repo.Store(ctx, indexer)
|
i, err := s.repo.Store(ctx, indexer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.log.Error().Err(err).Msgf("failed to store indexer: %s", indexer.Name)
|
s.log.Error().Err(err).Msgf("failed to store indexer: %s", indexer.Name)
|
||||||
|
@ -217,6 +222,16 @@ func (s *service) List(ctx context.Context) ([]domain.Indexer, error) {
|
||||||
return indexers, err
|
return indexers, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *service) GetBy(ctx context.Context, req domain.GetIndexerRequest) (*domain.Indexer, error) {
|
||||||
|
indexer, err := s.repo.GetBy(ctx, req)
|
||||||
|
if err != nil {
|
||||||
|
s.log.Error().Err(err).Msgf("could not get indexer by: %v", req)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return indexer, err
|
||||||
|
}
|
||||||
|
|
||||||
func (s *service) GetAll() ([]*domain.IndexerDefinition, error) {
|
func (s *service) GetAll() ([]*domain.IndexerDefinition, error) {
|
||||||
var res = make([]*domain.IndexerDefinition, 0)
|
var res = make([]*domain.IndexerDefinition, 0)
|
||||||
|
|
||||||
|
|
|
@ -375,19 +375,31 @@ func (s *service) Retry(ctx context.Context, req *domain.ReleaseActionRetryReq)
|
||||||
// get release
|
// get release
|
||||||
release, err := s.Get(ctx, &domain.GetReleaseRequest{Id: req.ReleaseId})
|
release, err := s.Get(ctx, &domain.GetReleaseRequest{Id: req.ReleaseId})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return errors.Wrap(err, "retry error: could not find release by id: %d", req.ReleaseId)
|
||||||
|
}
|
||||||
|
|
||||||
|
indexerInfo, err := s.indexerSvc.GetBy(ctx, domain.GetIndexerRequest{Identifier: release.Indexer.Identifier})
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "retry error: could not get indexer by identifier: %s", release.Indexer.Identifier)
|
||||||
|
}
|
||||||
|
|
||||||
|
release.Indexer = domain.IndexerMinimal{
|
||||||
|
ID: int(indexerInfo.ID),
|
||||||
|
Name: indexerInfo.Name,
|
||||||
|
Identifier: indexerInfo.Identifier,
|
||||||
|
IdentifierExternal: indexerInfo.IdentifierExternal,
|
||||||
}
|
}
|
||||||
|
|
||||||
// get release filter action status
|
// get release filter action status
|
||||||
status, err := s.GetActionStatus(ctx, &domain.GetReleaseActionStatusRequest{Id: req.ActionStatusId})
|
status, err := s.GetActionStatus(ctx, &domain.GetReleaseActionStatusRequest{Id: req.ActionStatusId})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return errors.Wrap(err, "retry error: could not get release action")
|
||||||
}
|
}
|
||||||
|
|
||||||
// get filter action with action id from status
|
// get filter action with action id from status
|
||||||
filterAction, err := s.actionSvc.Get(ctx, &domain.GetActionRequest{Id: int(status.ActionID)})
|
filterAction, err := s.actionSvc.Get(ctx, &domain.GetActionRequest{Id: int(status.ActionID)})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return errors.Wrap(err, "retry error: could not get filter action for release")
|
||||||
}
|
}
|
||||||
|
|
||||||
// run filterAction
|
// run filterAction
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue