Add support for using freeleech tokens if available

This commit is contained in:
Daniel Mason 2025-07-11 10:12:43 +12:00
parent 74f777340e
commit 3656a68a27
Signed by: idanoo
GPG key ID: 387387CDBC02F132
28 changed files with 199 additions and 39 deletions

View file

@ -26,7 +26,7 @@ var ErrForbidden = errors.New("forbidden")
var ErrTooManyRequests = errors.New("too many requests: rate-limit reached")
type ApiClient interface {
GetTorrentByID(ctx context.Context, torrentID string) (*domain.TorrentBasic, error)
GetTorrentByID(ctx context.Context, torrentID string, freeleechToken bool) (*domain.TorrentBasic, error)
TestAPI(ctx context.Context) (bool, error)
}
@ -180,7 +180,7 @@ func (c *Client) getJSON(ctx context.Context, params url.Values, data any) error
return nil
}
func (c *Client) GetTorrentByID(ctx context.Context, torrentID string) (*domain.TorrentBasic, error) {
func (c *Client) GetTorrentByID(ctx context.Context, torrentID string, freeleechToken bool) (*domain.TorrentBasic, error) {
if torrentID == "" {
return nil, errors.New("ptp client: must have torrentID")
}
@ -189,6 +189,9 @@ func (c *Client) GetTorrentByID(ctx context.Context, torrentID string) (*domain.
params := url.Values{}
params.Add("torrentid", torrentID)
if freeleechToken {
params.Add("usetoken", "1")
}
err := c.getJSON(ctx, params, &response)
if err != nil {