feat(downloadclients): Porla support preset (#978)

* Correctly omit download/upload limits

* Prefix JWT correctly

* Allow setting Porla preset
This commit is contained in:
Viktor Elofsson 2023-06-14 19:51:34 +02:00 committed by GitHub
parent 956225c108
commit 3d9839d234
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 27 deletions

View file

@ -51,20 +51,32 @@ func (s *service) porla(ctx context.Context, action *domain.Action, release doma
return rejections, nil 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() { if release.HasMagnetUri() {
opts := &porla.TorrentsAddReq{ opts := &porla.TorrentsAddReq{
DownloadLimit: -1, DownloadLimit: downloadLimit,
UploadLimit: -1,
SavePath: action.SavePath,
MagnetUri: release.MagnetURI, MagnetUri: release.MagnetURI,
} SavePath: action.SavePath,
UploadLimit: uploadLimit,
if action.LimitDownloadSpeed > 0 { Preset: preset,
opts.DownloadLimit = action.LimitDownloadSpeed * 1000
}
if action.LimitUploadSpeed > 0 {
opts.UploadLimit = action.LimitUploadSpeed * 1000
} }
if err = prl.TorrentsAdd(ctx, opts); err != nil { 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{ opts := &porla.TorrentsAddReq{
DownloadLimit: -1, DownloadLimit: downloadLimit,
SavePath: action.SavePath, SavePath: action.SavePath,
Ti: base64.StdEncoding.EncodeToString(content), Ti: base64.StdEncoding.EncodeToString(content),
UploadLimit: -1, UploadLimit: uploadLimit,
} Preset: preset,
if action.LimitDownloadSpeed > 0 {
opts.DownloadLimit = action.LimitDownloadSpeed * 1000
}
if action.LimitUploadSpeed > 0 {
opts.UploadLimit = action.LimitUploadSpeed * 1000
} }
if err = prl.TorrentsAdd(ctx, opts); err != nil { if err = prl.TorrentsAdd(ctx, opts); err != nil {

View file

@ -8,6 +8,7 @@ import (
"io" "io"
"log" "log"
"net/http" "net/http"
"strings"
"time" "time"
"github.com/autobrr/autobrr/pkg/jsonrpc" "github.com/autobrr/autobrr/pkg/jsonrpc"
@ -75,9 +76,15 @@ func NewClient(cfg Config) *Client {
Transport: customTransport, Transport: customTransport,
} }
token := cfg.AuthToken
if !strings.HasPrefix(token, "Bearer ") {
token = "Bearer " + token
}
c.rpcClient = jsonrpc.NewClientWithOpts(cfg.Hostname+"/api/v1/jsonrpc", &jsonrpc.ClientOpts{ c.rpcClient = jsonrpc.NewClientWithOpts(cfg.Hostname+"/api/v1/jsonrpc", &jsonrpc.ClientOpts{
Headers: map[string]string{ Headers: map[string]string{
"X-Porla-Token": cfg.AuthToken, "X-Porla-Token": token,
}, },
HTTPClient: httpClient, HTTPClient: httpClient,
BasicUser: cfg.BasicUser, BasicUser: cfg.BasicUser,

View file

@ -13,11 +13,12 @@ type SysVersionsPorla struct {
} }
type TorrentsAddReq struct { type TorrentsAddReq struct {
DownloadLimit int64 `json:"download_limit,omitempty"` DownloadLimit *int64 `json:"download_limit,omitempty"`
SavePath string `json:"save_path,omitempty"` SavePath string `json:"save_path,omitempty"`
Ti string `json:"ti,omitempty"` Ti string `json:"ti,omitempty"`
MagnetUri string `json:"magnet_uri,omitempty"` MagnetUri string `json:"magnet_uri,omitempty"`
UploadLimit int64 `json:"upload_limit,omitempty"` UploadLimit *int64 `json:"upload_limit,omitempty"`
Preset *string `json:"preset,omitempty"`
} }
type TorrentsAddRes struct { type TorrentsAddRes struct {

View file

@ -476,6 +476,15 @@ const TypeForm = ({ action, idx, clients }: TypeFormProps) => {
</div> </div>
</div> </div>
<div className="mt-6 grid grid-cols-12 gap-6">
<TextField
name={`actions.${idx}.label`}
label="Preset"
columns={6}
placeholder="eg. default"
tooltip={<div>A case-sensitive preset name as configured in Porla.</div>} />
</div>
<CollapsableSection title="Rules" subtitle="client options"> <CollapsableSection title="Rules" subtitle="client options">
<div className="col-span-12"> <div className="col-span-12">
<div className="mt-6 grid grid-cols-12 gap-6"> <div className="mt-6 grid grid-cols-12 gap-6">