diff --git a/internal/action/porla.go b/internal/action/porla.go index f257769..8922430 100644 --- a/internal/action/porla.go +++ b/internal/action/porla.go @@ -51,20 +51,32 @@ func (s *service) porla(ctx context.Context, action *domain.Action, release doma return rejections, nil } + var downloadLimit *int64 = nil + var uploadLimit *int64 = nil + + if action.LimitDownloadSpeed > 0 { + dlValue := action.LimitDownloadSpeed * 1000 + downloadLimit = &dlValue + } + + if action.LimitUploadSpeed > 0 { + ulValue := action.LimitUploadSpeed * 1000 + uploadLimit = &ulValue + } + + var preset *string = nil + + if action.Label != "" { + preset = &action.Label + } + if release.HasMagnetUri() { opts := &porla.TorrentsAddReq{ - DownloadLimit: -1, - UploadLimit: -1, - SavePath: action.SavePath, + DownloadLimit: downloadLimit, MagnetUri: release.MagnetURI, - } - - if action.LimitDownloadSpeed > 0 { - opts.DownloadLimit = action.LimitDownloadSpeed * 1000 - } - - if action.LimitUploadSpeed > 0 { - opts.UploadLimit = action.LimitUploadSpeed * 1000 + SavePath: action.SavePath, + UploadLimit: uploadLimit, + Preset: preset, } if err = prl.TorrentsAdd(ctx, opts); err != nil { @@ -94,18 +106,11 @@ func (s *service) porla(ctx context.Context, action *domain.Action, release doma } opts := &porla.TorrentsAddReq{ - DownloadLimit: -1, + DownloadLimit: downloadLimit, SavePath: action.SavePath, Ti: base64.StdEncoding.EncodeToString(content), - UploadLimit: -1, - } - - if action.LimitDownloadSpeed > 0 { - opts.DownloadLimit = action.LimitDownloadSpeed * 1000 - } - - if action.LimitUploadSpeed > 0 { - opts.UploadLimit = action.LimitUploadSpeed * 1000 + UploadLimit: uploadLimit, + Preset: preset, } if err = prl.TorrentsAdd(ctx, opts); err != nil { diff --git a/pkg/porla/client.go b/pkg/porla/client.go index a6e7b6e..8ef9ff3 100644 --- a/pkg/porla/client.go +++ b/pkg/porla/client.go @@ -8,6 +8,7 @@ import ( "io" "log" "net/http" + "strings" "time" "github.com/autobrr/autobrr/pkg/jsonrpc" @@ -75,9 +76,15 @@ func NewClient(cfg Config) *Client { Transport: customTransport, } + token := cfg.AuthToken + + if !strings.HasPrefix(token, "Bearer ") { + token = "Bearer " + token + } + c.rpcClient = jsonrpc.NewClientWithOpts(cfg.Hostname+"/api/v1/jsonrpc", &jsonrpc.ClientOpts{ Headers: map[string]string{ - "X-Porla-Token": cfg.AuthToken, + "X-Porla-Token": token, }, HTTPClient: httpClient, BasicUser: cfg.BasicUser, diff --git a/pkg/porla/domain.go b/pkg/porla/domain.go index e3d68fe..6096e22 100644 --- a/pkg/porla/domain.go +++ b/pkg/porla/domain.go @@ -13,11 +13,12 @@ type SysVersionsPorla struct { } type TorrentsAddReq struct { - DownloadLimit int64 `json:"download_limit,omitempty"` - SavePath string `json:"save_path,omitempty"` - Ti string `json:"ti,omitempty"` - MagnetUri string `json:"magnet_uri,omitempty"` - UploadLimit int64 `json:"upload_limit,omitempty"` + DownloadLimit *int64 `json:"download_limit,omitempty"` + SavePath string `json:"save_path,omitempty"` + Ti string `json:"ti,omitempty"` + MagnetUri string `json:"magnet_uri,omitempty"` + UploadLimit *int64 `json:"upload_limit,omitempty"` + Preset *string `json:"preset,omitempty"` } type TorrentsAddRes struct { diff --git a/web/src/screens/filters/action.tsx b/web/src/screens/filters/action.tsx index 2ff564c..dd223ff 100644 --- a/web/src/screens/filters/action.tsx +++ b/web/src/screens/filters/action.tsx @@ -476,6 +476,15 @@ const TypeForm = ({ action, idx, clients }: TypeFormProps) => { +