initial commit
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type TorrentInfo struct {
|
||||
Name string `json:"name"`
|
||||
Hash string `json:"hash"`
|
||||
State string `json:"state"`
|
||||
Category string `json:"category"`
|
||||
AddedOn UnixTimestamp `json:"added_on"`
|
||||
AmountLeft int64 `json:"amount_left"`
|
||||
Downloaded int64 `json:"downloaded"`
|
||||
Size int64 `json:"size"`
|
||||
TotalSize int64 `json:"total_size"`
|
||||
}
|
||||
|
||||
func (c *Client) LisTorrents() ([]TorrentInfo, error) {
|
||||
var torrents []TorrentInfo
|
||||
if err := c.reqBuilder().Path("/api/v2/torrents/info").ToJSON(&torrents).Fetch(context.TODO()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return torrents, nil
|
||||
}
|
||||
|
||||
type TorrentFile struct {
|
||||
Index int32 `json:"index"`
|
||||
Name string `json:"name"`
|
||||
Size int64 `json:"size"`
|
||||
Progress float64 `json:"progress"`
|
||||
Priority uint8 `json:"priority"`
|
||||
IsSeed bool `json:"is_seed"`
|
||||
PieceRange []int64 `json:"piece_range"`
|
||||
Availability float64 `json:"availability"`
|
||||
}
|
||||
|
||||
func (c *Client) TorrentFiles(hash string) ([]TorrentFile, error) {
|
||||
var files []TorrentFile
|
||||
if err := c.reqBuilder().Path("/api/v2/torrents/files").Param("hash", hash).ToJSON(&files).Fetch(context.TODO()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return files, nil
|
||||
}
|
||||
|
||||
func (c *Client) DeleteTorrent(hash string, deleteFiles bool) error {
|
||||
err := c.reqBuilder().
|
||||
Path("/api/v2/torrents/delete").
|
||||
BodyForm(url.Values{
|
||||
"hashes": []string{hash},
|
||||
"deleteFiles": []string{strconv.FormatBool(deleteFiles)},
|
||||
}).
|
||||
Fetch(context.TODO())
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user