"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
yandex: implement custom user agent to help with upload speeds
Sebastian Büngeraf9f8ced8055
diff --git a/backend/yandex/yandex.go b/backend/yandex/yandex.goindex 798cccd6c..aabb2f8db 100644--- a/backend/yandex/yandex.go+++ b/backend/yandex/yandex.go@@ -26,6 +26,7 @@ import ("github.com/rclone/rclone/lib/encoder""github.com/rclone/rclone/lib/oauthutil""github.com/rclone/rclone/lib/pacer"+ "github.com/rclone/rclone/lib/random""github.com/rclone/rclone/lib/readers""github.com/rclone/rclone/lib/rest""golang.org/x/oauth2"@@ -39,6 +40,8 @@ const (minSleep = 10 * time.MillisecondmaxSleep = 2 * time.Second // may needs to be increased, testing neededdecayConstant = 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@@ -79,15 +82,22 @@ func init() {// it doesn't seem worth making an exception for thisDefault: (encoder.Display |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 backendtype Options struct {- Token string `config:"token"`- HardDelete bool `config:"hard_delete"`- Enc encoder.MultiEncoder `config:"encoding"`+ Token string `config:"token"`+ HardDelete bool `config:"hard_delete"`+ Enc encoder.MultiEncoder `config:"encoding"`+ SpoofUserAgent bool `config:"spoof_ua"`}// Fs represents a remote yandex@@ -254,6 +264,12 @@ func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, ereturn 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)if err != nil {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, ereturn nil, fmt.Errorf("failed to configure Yandex: %w", err)}- ci := fs.GetConfig(ctx)f := &Fs{name: name,opt: *opt,diff --git a/docs/content/yandex.md b/docs/content/yandex.mdindex 45039f0d7..6c65b1adc 100644--- a/docs/content/yandex.md+++ b/docs/content/yandex.md@@ -210,6 +210,17 @@ Properties:- Type: Encoding- 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-descriptionDescription of the remote.