mirror of
https://github.com/idanoo/autobrr
synced 2025-07-22 08:19:12 +00:00

* chore: update copyright year in license headers * Revert "chore: update copyright year in license headers" This reverts commit 3e58129c431b9a491089ce36b908f9bb6ba38ed3. * chore: update copyright year in license headers * fix: sort go imports * fix: add missing license headers
43 lines
1.3 KiB
Go
43 lines
1.3 KiB
Go
// Copyright (c) 2021 - 2025, Ludvig Lundgren and the autobrr contributors.
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
package action
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/autobrr/autobrr/internal/domain"
|
|
"github.com/autobrr/autobrr/pkg/errors"
|
|
"github.com/autobrr/autobrr/pkg/sabnzbd"
|
|
)
|
|
|
|
func (s *service) sabnzbd(ctx context.Context, action *domain.Action, release domain.Release) ([]string, error) {
|
|
s.log.Trace().Msg("action Sabnzbd")
|
|
|
|
if release.Protocol != domain.ReleaseProtocolNzb {
|
|
return nil, errors.New("action type: %s invalid protocol: %s", action.Type, release.Protocol)
|
|
}
|
|
|
|
client, err := s.clientSvc.GetClient(ctx, action.ClientID)
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "could not get client with id %d", action.ClientID)
|
|
}
|
|
action.Client = client
|
|
|
|
if !client.Enabled {
|
|
return nil, errors.New("client %s %s not enabled", client.Type, client.Name)
|
|
}
|
|
|
|
sab := client.Client.(*sabnzbd.Client)
|
|
|
|
ids, err := sab.AddFromUrl(ctx, sabnzbd.AddNzbRequest{Url: release.DownloadURL, Category: action.Category})
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "could not add nzb to sabnzbd")
|
|
}
|
|
|
|
s.log.Trace().Msgf("nzb successfully added to client: '%+v'", ids)
|
|
|
|
s.log.Info().Msgf("nzb successfully added to client: '%s'", client.Name)
|
|
|
|
return nil, nil
|
|
}
|