mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 00:39:13 +00:00
feat(download-client): add support for Porla (#553)
* Add support for the 'Test' button to work * Make Porla show up in filter actions select * Add an empty Porla action * Make Porla action find download client * Make implementation actually add torrent to Porla * Fix qBittorrent import * Finish up Porla action * Check length on commitish before slicing * Move Porla to the other DL clients * Add Porla to type name map * Move Porla to beneath the other download clients
This commit is contained in:
parent
b95c1e6913
commit
870e109f6c
12 changed files with 271 additions and 2 deletions
30
pkg/porla/client.go
Normal file
30
pkg/porla/client.go
Normal file
|
@ -0,0 +1,30 @@
|
|||
package porla
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/autobrr/autobrr/pkg/jsonrpc"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
Name string
|
||||
Hostname string
|
||||
rpcClient jsonrpc.Client
|
||||
}
|
||||
|
||||
type Settings struct {
|
||||
Hostname string
|
||||
AuthToken string
|
||||
Log *log.Logger
|
||||
}
|
||||
|
||||
func NewClient(settings Settings) *Client {
|
||||
c := &Client{
|
||||
rpcClient: jsonrpc.NewClientWithOpts(settings.Hostname+"/api/v1/jsonrpc", &jsonrpc.ClientOpts{
|
||||
Headers: map[string]string{
|
||||
"Authorization": "Bearer " + settings.AuthToken,
|
||||
},
|
||||
}),
|
||||
}
|
||||
return c
|
||||
}
|
20
pkg/porla/domain.go
Normal file
20
pkg/porla/domain.go
Normal file
|
@ -0,0 +1,20 @@
|
|||
package porla
|
||||
|
||||
type SysVersions struct {
|
||||
Porla SysVersionsPorla `json:"porla"`
|
||||
}
|
||||
|
||||
type SysVersionsPorla struct {
|
||||
Commitish string `json:"commitish"`
|
||||
Version string `json:"version"`
|
||||
}
|
||||
|
||||
type TorrentsAddReq struct {
|
||||
DownloadLimit int64 `json:"download_limit,omitempty"`
|
||||
SavePath string `json:"save_path,omitempty"`
|
||||
Ti string `json:"ti"`
|
||||
UploadLimit int64 `json:"upload_limit,omitempty"`
|
||||
}
|
||||
|
||||
type TorrentsAddRes struct {
|
||||
}
|
43
pkg/porla/methods.go
Normal file
43
pkg/porla/methods.go
Normal file
|
@ -0,0 +1,43 @@
|
|||
package porla
|
||||
|
||||
func (c *Client) Version() (*SysVersionsPorla, error) {
|
||||
response, err := c.rpcClient.Call("sys.versions")
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if response.Error != nil {
|
||||
return nil, response.Error
|
||||
}
|
||||
|
||||
var versions *SysVersions
|
||||
err = response.GetObject(&versions)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &versions.Porla, nil
|
||||
}
|
||||
|
||||
func (c *Client) TorrentsAdd(req *TorrentsAddReq) error {
|
||||
response, err := c.rpcClient.Call("torrents.add", req)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if response.Error != nil {
|
||||
return response.Error
|
||||
}
|
||||
|
||||
var res *TorrentsAddRes
|
||||
err = response.GetObject(&res)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue