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:
ze0s 2023-10-31 00:38:23 +01:00 committed by GitHub
parent 568e41de24
commit d5d1cecc1b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 189 additions and 23 deletions

View 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)
}