mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 00:39:13 +00:00
feat(clients): Transmission support seedtime and ratiolimit (#1211)
* feat(clients): Transmission seedtime ratiolimit * feat(clients): update client pkg * feat(clients): update client pkg test * feat(actions): update transmission
This commit is contained in:
parent
568e41de24
commit
d5d1cecc1b
6 changed files with 189 additions and 23 deletions
58
pkg/transmission/transmission.go
Normal file
58
pkg/transmission/transmission.go
Normal file
|
@ -0,0 +1,58 @@
|
|||
package transmission
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/hekmon/transmissionrpc/v3"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
UserAgent string
|
||||
CustomClient *http.Client
|
||||
Username string
|
||||
Password string
|
||||
TLSSkipVerify bool
|
||||
Timeout int
|
||||
}
|
||||
|
||||
func New(endpoint *url.URL, cfg *Config) (*transmissionrpc.Client, error) {
|
||||
ct := &customTransport{
|
||||
Username: cfg.Username,
|
||||
Password: cfg.Password,
|
||||
TLSSkipVerify: cfg.TLSSkipVerify,
|
||||
}
|
||||
|
||||
extra := &transmissionrpc.Config{
|
||||
CustomClient: &http.Client{
|
||||
Transport: ct,
|
||||
Timeout: time.Second * 60,
|
||||
},
|
||||
UserAgent: cfg.UserAgent,
|
||||
}
|
||||
|
||||
return transmissionrpc.New(endpoint, extra)
|
||||
}
|
||||
|
||||
type customTransport struct {
|
||||
Username string
|
||||
Password string
|
||||
TLSSkipVerify bool
|
||||
}
|
||||
|
||||
func (t *customTransport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
dt := http.DefaultTransport.(*http.Transport).Clone()
|
||||
if t.TLSSkipVerify {
|
||||
dt.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
|
||||
}
|
||||
|
||||
r := req.Clone(req.Context())
|
||||
|
||||
if t.Username != "" && t.Password != "" {
|
||||
r.SetBasicAuth(t.Username, t.Password)
|
||||
}
|
||||
|
||||
return dt.RoundTrip(r)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue