mirror of
https://github.com/rclone/rclone.git
synced 2024-11-22 00:13:49 +01:00
yandex: implement custom user agent to help with upload speeds
This commit is contained in:
parent
c63f1865f3
commit
af9f8ced80
@ -26,6 +26,7 @@ import (
|
|||||||
"github.com/rclone/rclone/lib/encoder"
|
"github.com/rclone/rclone/lib/encoder"
|
||||||
"github.com/rclone/rclone/lib/oauthutil"
|
"github.com/rclone/rclone/lib/oauthutil"
|
||||||
"github.com/rclone/rclone/lib/pacer"
|
"github.com/rclone/rclone/lib/pacer"
|
||||||
|
"github.com/rclone/rclone/lib/random"
|
||||||
"github.com/rclone/rclone/lib/readers"
|
"github.com/rclone/rclone/lib/readers"
|
||||||
"github.com/rclone/rclone/lib/rest"
|
"github.com/rclone/rclone/lib/rest"
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
@ -39,6 +40,8 @@ const (
|
|||||||
minSleep = 10 * time.Millisecond
|
minSleep = 10 * time.Millisecond
|
||||||
maxSleep = 2 * time.Second // may needs to be increased, testing needed
|
maxSleep = 2 * time.Second // may needs to be increased, testing needed
|
||||||
decayConstant = 2 // bigger for slower decay, exponential
|
decayConstant = 2 // bigger for slower decay, exponential
|
||||||
|
|
||||||
|
userAgentTemplae = `Yandex.Disk {"os":"windows","dtype":"ydisk3","vsn":"3.2.37.4977","id":"6BD01244C7A94456BBCEE7EEC990AEAD","id2":"0F370CD40C594A4783BC839C846B999C","session_id":"%s"}`
|
||||||
)
|
)
|
||||||
|
|
||||||
// Globals
|
// Globals
|
||||||
@ -79,15 +82,22 @@ func init() {
|
|||||||
// it doesn't seem worth making an exception for this
|
// it doesn't seem worth making an exception for this
|
||||||
Default: (encoder.Display |
|
Default: (encoder.Display |
|
||||||
encoder.EncodeInvalidUtf8),
|
encoder.EncodeInvalidUtf8),
|
||||||
|
}, {
|
||||||
|
Name: "spoof_ua",
|
||||||
|
Help: "Set the user agent to match an official version of the yandex disk client. May help with upload performance.",
|
||||||
|
Default: true,
|
||||||
|
Advanced: true,
|
||||||
|
Hide: fs.OptionHideConfigurator,
|
||||||
}}...),
|
}}...),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Options defines the configuration for this backend
|
// Options defines the configuration for this backend
|
||||||
type Options struct {
|
type Options struct {
|
||||||
Token string `config:"token"`
|
Token string `config:"token"`
|
||||||
HardDelete bool `config:"hard_delete"`
|
HardDelete bool `config:"hard_delete"`
|
||||||
Enc encoder.MultiEncoder `config:"encoding"`
|
Enc encoder.MultiEncoder `config:"encoding"`
|
||||||
|
SpoofUserAgent bool `config:"spoof_ua"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fs represents a remote yandex
|
// Fs represents a remote yandex
|
||||||
@ -254,6 +264,12 @@ func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, e
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctx, ci := fs.AddConfig(ctx)
|
||||||
|
if fs.ConfigOptionsInfo.Get("user_agent").IsDefault() && opt.SpoofUserAgent {
|
||||||
|
randomSessionID, _ := random.Password(128)
|
||||||
|
ci.UserAgent = fmt.Sprintf(userAgentTemplae, randomSessionID)
|
||||||
|
}
|
||||||
|
|
||||||
token, err := oauthutil.GetToken(name, m)
|
token, err := oauthutil.GetToken(name, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("couldn't read OAuth token: %w", err)
|
return nil, fmt.Errorf("couldn't read OAuth token: %w", err)
|
||||||
@ -274,7 +290,6 @@ func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, e
|
|||||||
return nil, fmt.Errorf("failed to configure Yandex: %w", err)
|
return nil, fmt.Errorf("failed to configure Yandex: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ci := fs.GetConfig(ctx)
|
|
||||||
f := &Fs{
|
f := &Fs{
|
||||||
name: name,
|
name: name,
|
||||||
opt: *opt,
|
opt: *opt,
|
||||||
|
@ -210,6 +210,17 @@ Properties:
|
|||||||
- Type: Encoding
|
- Type: Encoding
|
||||||
- Default: Slash,Del,Ctl,InvalidUtf8,Dot
|
- Default: Slash,Del,Ctl,InvalidUtf8,Dot
|
||||||
|
|
||||||
|
#### --yandex-spoof-ua
|
||||||
|
|
||||||
|
Set the user agent to match an official version of the yandex disk client. May help with upload performance.
|
||||||
|
|
||||||
|
Properties:
|
||||||
|
|
||||||
|
- Config: spoof_ua
|
||||||
|
- Env Var: RCLONE_YANDEX_SPOOF_UA
|
||||||
|
- Type: bool
|
||||||
|
- Default: true
|
||||||
|
|
||||||
#### --yandex-description
|
#### --yandex-description
|
||||||
|
|
||||||
Description of the remote.
|
Description of the remote.
|
||||||
|
Loading…
Reference in New Issue
Block a user