feat: add get all torrents api

This commit is contained in:
Simon Ding
2024-07-27 09:26:51 +08:00
parent 51fc5c3c74
commit b2a092c64e
7 changed files with 124 additions and 83 deletions

View File

@@ -45,6 +45,22 @@ type Client struct {
cfg Config
}
func (c *Client) GetAll() ([]*Torrent, error) {
all, err := c.c.TorrentGetAll(context.TODO())
if err != nil {
return nil, errors.Wrap(err, "get all")
}
var torrents []*Torrent
for _, t := range all {
torrents = append(torrents, &Torrent{
ID: *t.ID,
c: c.c,
Config: c.cfg,
})
}
return torrents, nil
}
func (c *Client) Download(link, dir string) (*Torrent, error) {
if strings.HasPrefix(link, "http") {
client := &http.Client{