diff --git a/drivers/139/meta.go b/drivers/139/meta.go index 8e963d70..184c3e12 100644 --- a/drivers/139/meta.go +++ b/drivers/139/meta.go @@ -21,6 +21,7 @@ type Addition struct { ReportRealSize bool `json:"report_real_size" type:"bool" default:"true" help:"Enable to report the real file size during upload"` UseLargeThumbnail bool `json:"use_large_thumbnail" type:"bool" default:"false" help:"Enable to use large thumbnail for images"` UseOldStreamUpload bool `json:"use_old_stream_upload" type:"bool" default:"false" help:"Enable to use old stream upload method (not support rapid upload)"` + ClientType string `json:"client_type" type:"select" options:"web,pc" default:"web" help:"Client type reported to the personal cloud API. web (9) allows uploading files up to 50 GB; pc (13) raises the single file upload limit to 500 GB."` } var config = driver.Config{ diff --git a/drivers/139/util.go b/drivers/139/util.go index 7d60db55..a53f99e9 100644 --- a/drivers/139/util.go +++ b/drivers/139/util.go @@ -843,6 +843,24 @@ func unicode(str string) string { return textUnquoted } +// Client types reported in the X-Yun-Client-Info header. The web client is the +// default with a 50 GB single file upload limit, while the PC client raises the +// limit to 500 GB. +const ( + yunClientTypeWeb = "9" + yunClientTypePC = "13" +) + +// yunClientInfo returns the X-Yun-Client-Info header value for the configured +// client_type addition. Anything other than pc falls back to the web client. +func (d *Yun139) yunClientInfo() string { + clientType := yunClientTypeWeb + if d.ClientType == "pc" { + clientType = yunClientTypePC + } + return "||" + clientType + "|7.14.0|chrome|120.0.0.0|||windows 10||zh-CN|||dW5kZWZpbmVk||" +} + func (d *Yun139) newRequest(url string, method string, callback base.ReqCallback, resp interface{}) ([]byte, error) { req := base.RestyClient.R() randStr := random.String(16) @@ -878,7 +896,7 @@ func (d *Yun139) newRequest(url string, method string, callback base.ReqCallback "X-Yun-Api-Version": "v1", "X-Yun-App-Channel": "10000034", "X-Yun-Channel-Source": "10000034", - "X-Yun-Client-Info": "||13|7.14.0|chrome|120.0.0.0|||windows 10||zh-CN|||dW5kZWZpbmVk||", + "X-Yun-Client-Info": d.yunClientInfo(), "X-Yun-Module-Type": "100", "X-Yun-Svc-Type": "1", }) diff --git a/drivers/139/util_test.go b/drivers/139/util_test.go index d4abdc4d..6514a042 100644 --- a/drivers/139/util_test.go +++ b/drivers/139/util_test.go @@ -42,6 +42,33 @@ func TestExtractFastLoginCookies(t *testing.T) { } } +func TestYunClientInfoClientType(t *testing.T) { + tests := []struct { + name string + clientType string + want string + }{ + { + name: "default web client", + want: "||9|7.14.0|chrome|120.0.0.0|||windows 10||zh-CN|||dW5kZWZpbmVk||", + }, + { + name: "pc client", + clientType: "pc", + want: "||13|7.14.0|chrome|120.0.0.0|||windows 10||zh-CN|||dW5kZWZpbmVk||", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + d := Yun139{Addition: Addition{ClientType: tt.clientType}} + if got := d.yunClientInfo(); got != tt.want { + t.Fatalf("yunClientInfo() = %q, want %q", got, tt.want) + } + }) + } +} + func TestCredentialState(t *testing.T) { tests := []struct { name string