mirror of
https://github.com/simon-ding/polaris.git
synced 2026-04-22 03:37:30 +08:00
feat: complete qbittorrent support
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"polaris/log"
|
||||
"polaris/pkg"
|
||||
"strings"
|
||||
|
||||
"github.com/hekmon/transmissionrpc/v3"
|
||||
@@ -45,12 +46,12 @@ type Client struct {
|
||||
cfg Config
|
||||
}
|
||||
|
||||
func (c *Client) GetAll() ([]*Torrent, error) {
|
||||
func (c *Client) GetAll() ([]pkg.Torrent, error) {
|
||||
all, err := c.c.TorrentGetAll(context.TODO())
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "get all")
|
||||
}
|
||||
var torrents []*Torrent
|
||||
var torrents []pkg.Torrent
|
||||
for _, t := range all {
|
||||
torrents = append(torrents, &Torrent{
|
||||
Hash: *t.HashString,
|
||||
@@ -61,7 +62,7 @@ func (c *Client) GetAll() ([]*Torrent, error) {
|
||||
return torrents, nil
|
||||
}
|
||||
|
||||
func (c *Client) Download(link, dir string) (*Torrent, error) {
|
||||
func (c *Client) Download(link, dir string) (pkg.Torrent, error) {
|
||||
if strings.HasPrefix(link, "http") {
|
||||
client := &http.Client{
|
||||
CheckRedirect: func(req *http.Request, via []*http.Request) error {
|
||||
@@ -207,6 +208,11 @@ func (t *Torrent) Save() string {
|
||||
return string(d)
|
||||
}
|
||||
|
||||
func (t *Torrent) GetHash() string {
|
||||
return t.Hash
|
||||
}
|
||||
|
||||
|
||||
func ReloadTorrent(s string) (*Torrent, error) {
|
||||
var torrent = Torrent{}
|
||||
err := json.Unmarshal([]byte(s), &torrent)
|
||||
|
||||
Reference in New Issue
Block a user