mirror of
https://github.com/OpenListTeam/OpenList.git
synced 2026-11-10 20:50:50 +08:00
feat(drivers/139): make the API client type configurable (#3196)
This commit is contained in:
1 parent
482464c2af
commit
3b28270a40
3 files changed
+47
-1
No files matched your search
@@ -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{
|
||||
|
||||
+19
-1
@@ -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",
|
||||
})
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user