From 0eef7a129c328efb9dfaf0203ec03bfd38bcd048 Mon Sep 17 00:00:00 2001 From: foxxorcat Date: Thu, 12 May 2022 13:26:12 +0800 Subject: [PATCH 1/4] fix(xunlei):the verification code cannot be obtained from the mobile phone number or email --- drivers/xunlei/xunlei.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/xunlei/xunlei.go b/drivers/xunlei/xunlei.go index a1b1a656..4ab1a43f 100644 --- a/drivers/xunlei/xunlei.go +++ b/drivers/xunlei/xunlei.go @@ -117,8 +117,20 @@ func (c *Client) Login(account *model.Account) (err error) { model.SaveAccount(account) }() + meta := make(map[string]string) + if strings.Contains(account.Username, "@") { + meta["email"] = account.Username + } else if len(account.Username) >= 11 { + if !strings.Contains(account.Username, "+") { + account.Username = "+86 " + account.Username + } + meta["phone_number"] = account.Username + } else { + meta["username"] = account.Username + } + url := XLUSER_API_URL + "/auth/signin" - err = c.requestCaptchaToken(getAction(http.MethodPost, url), map[string]string{"username": account.Username}) + err = c.requestCaptchaToken(getAction(http.MethodPost, url), meta) if err != nil { return err } From 041b3587bf35295ba122718777f2120c26626051 Mon Sep 17 00:00:00 2001 From: foxxorcat Date: Thu, 12 May 2022 13:27:49 +0800 Subject: [PATCH 2/4] fix(xunlei):turn page --- drivers/xunlei/driver.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/xunlei/driver.go b/drivers/xunlei/driver.go index 2e5b6325..135f3dde 100644 --- a/drivers/xunlei/driver.go +++ b/drivers/xunlei/driver.go @@ -171,14 +171,15 @@ func (driver XunLeiCloud) Files(path string, account *model.Account) ([]model.Fi return nil, err } - time.Sleep(time.Millisecond * 400) + time.Sleep(time.Millisecond * 300) files := make([]model.File, 0) + var pageToken string for { var fileList FileList _, err = GetClient(account).Request("GET", FILE_API_URL, func(r *resty.Request) { r.SetQueryParams(map[string]string{ "parent_id": parentFile.Id, - "page_token": fileList.NextPageToken, + "page_token": pageToken, "with_audit": "true", "filters": `{"phase": {"eq": "PHASE_TYPE_COMPLETE"}, "trashed":{"eq":false}}`, }) @@ -195,6 +196,7 @@ func (driver XunLeiCloud) Files(path string, account *model.Account) ([]model.Fi if fileList.NextPageToken == "" { break } + pageToken = fileList.NextPageToken } if len(files) > 0 { _ = base.SetCache(path, files, account) From 6a67d1cf6970a30c814843d0d09b90fce2933c9a Mon Sep 17 00:00:00 2001 From: foxxorcat Date: Thu, 12 May 2022 19:15:39 +0800 Subject: [PATCH 3/4] fix(xunlei):check captchaToken --- drivers/xunlei/driver.go | 6 ++---- drivers/xunlei/xunlei.go | 11 +++++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/drivers/xunlei/driver.go b/drivers/xunlei/driver.go index 135f3dde..4eb5b3bf 100644 --- a/drivers/xunlei/driver.go +++ b/drivers/xunlei/driver.go @@ -117,11 +117,9 @@ func (driver XunLeiCloud) Save(account *model.Account, old *model.Account) error client := GetClient(account) // 指定验证通过的captchaToken - if client.captchaToken != "" { - client.Lock() - client.captchaToken = account.CaptchaToken + if account.CaptchaToken != "" { + client.UpdateCaptchaToken(strings.TrimSpace(account.CaptchaToken)) account.CaptchaToken = "" - client.Unlock() } if client.token == "" { diff --git a/drivers/xunlei/xunlei.go b/drivers/xunlei/xunlei.go index 4ab1a43f..2c966c99 100644 --- a/drivers/xunlei/xunlei.go +++ b/drivers/xunlei/xunlei.go @@ -269,3 +269,14 @@ func (c *Client) Request(method string, url string, callback func(*resty.Request } return c.Request(method, url, callback, account) } + +func (c *Client) UpdateCaptchaToken(captchaToken string) bool { + c.Lock() + defer c.Unlock() + + if captchaToken != "" { + c.captchaToken = captchaToken + return true + } + return false +} From f917882a84e2dff1edeaa0ac960c5399d9643404 Mon Sep 17 00:00:00 2001 From: foxxorcat Date: Thu, 12 May 2022 19:15:52 +0800 Subject: [PATCH 4/4] perf(xunlei):upload --- drivers/xunlei/driver.go | 60 +++++++++++++++++++++++----------------- go.mod | 3 -- go.sum | 9 ------ 3 files changed, 34 insertions(+), 38 deletions(-) diff --git a/drivers/xunlei/driver.go b/drivers/xunlei/driver.go index 4eb5b3bf..fa9db1cc 100644 --- a/drivers/xunlei/driver.go +++ b/drivers/xunlei/driver.go @@ -1,10 +1,6 @@ package xunlei import ( - "fmt" - "io" - "io/ioutil" - "os" "path/filepath" "strconv" "strings" @@ -14,7 +10,10 @@ import ( "github.com/Xhofe/alist/drivers/base" "github.com/Xhofe/alist/model" "github.com/Xhofe/alist/utils" - "github.com/aliyun/aliyun-oss-go-sdk/oss" + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/credentials" + "github.com/aws/aws-sdk-go/aws/session" + "github.com/aws/aws-sdk-go/service/s3/s3manager" "github.com/go-resty/resty/v2" "github.com/google/uuid" ) @@ -179,6 +178,7 @@ func (driver XunLeiCloud) Files(path string, account *model.Account) ([]model.Fi "parent_id": parentFile.Id, "page_token": pageToken, "with_audit": "true", + "limit": "100", "filters": `{"phase": {"eq": "PHASE_TYPE_COMPLETE"}, "trashed":{"eq":false}}`, }) r.SetResult(&fileList) @@ -357,19 +357,24 @@ func (driver XunLeiCloud) Upload(file *model.FileStream, account *model.Account) return err } - tempFile, err := ioutil.TempFile(conf.Conf.TempDir, "file-*") - if err != nil { - return err - } + /* + tempFile, err := ioutil.TempFile(conf.Conf.TempDir, "file-*") + if err != nil { + return err + } - defer os.Remove(tempFile.Name()) + defer tempFile.Close() + defer os.Remove(tempFile.Name()) - gcid, err := getGcid(io.TeeReader(file, tempFile), int64(file.Size)) - if err != nil { - return err - } + gcid, err := getGcid(io.TeeReader(file, tempFile), int64(file.Size)) + if err != nil { + return err + } - tempFile.Close() + if _, err = tempFile.Seek(0, io.SeekStart); err != nil { + return err + } + */ var resp UploadTaskResponse _, err = GetClient(account).Request("POST", FILE_API_URL, func(r *resty.Request) { @@ -377,8 +382,8 @@ func (driver XunLeiCloud) Upload(file *model.FileStream, account *model.Account) "kind": FILE, "parent_id": parentFile.Id, "name": file.Name, - "size": fmt.Sprint(file.Size), - "hash": gcid, + "size": file.Size, + "hash": "1CF254FBC456E1B012CD45C546636AA62CF8350E", "upload_type": UPLOAD_TYPE_RESUMABLE, }) r.SetResult(&resp) @@ -390,18 +395,21 @@ func (driver XunLeiCloud) Upload(file *model.FileStream, account *model.Account) param := resp.Resumable.Params if resp.UploadType == UPLOAD_TYPE_RESUMABLE { param.Endpoint = strings.TrimLeft(param.Endpoint, param.Bucket+".") - client, err := oss.New(param.Endpoint, param.AccessKeyID, param.AccessKeySecret, oss.SecurityToken(param.SecurityToken), oss.EnableMD5(true)) - if err != nil { - return err - } - bucket, err := client.Bucket(param.Bucket) - if err != nil { - return err - } - err = bucket.UploadFile(param.Key, tempFile.Name(), 1<<22, oss.Routines(3), oss.Checkpoint(true, ""), oss.Expires(param.Expiration)) + s, err := session.NewSession(&aws.Config{ + Credentials: credentials.NewStaticCredentials(param.AccessKeyID, param.AccessKeySecret, param.SecurityToken), + Region: aws.String("xunlei"), + Endpoint: aws.String(param.Endpoint), + }) if err != nil { return err } + _, err = s3manager.NewUploader(s).Upload(&s3manager.UploadInput{ + Bucket: aws.String(param.Bucket), + Key: aws.String(param.Key), + Expires: aws.Time(param.Expiration), + Body: file, + }) + return err } return nil } diff --git a/go.mod b/go.mod index 433b2ed0..9da54ec1 100644 --- a/go.mod +++ b/go.mod @@ -27,15 +27,12 @@ require ( require github.com/kr/fs v0.1.0 // indirect require ( - github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f // indirect github.com/fatih/color v1.13.0 github.com/mattn/go-colorable v0.1.9 // indirect - golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect ) require ( github.com/XiaoMi/pegasus-go-client v0.0.0-20210427083443-f3b6b08bc4c2 // indirect - github.com/aliyun/aliyun-oss-go-sdk v2.2.1+incompatible github.com/beorn7/perks v1.0.1 // indirect github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b // indirect github.com/cenkalti/backoff/v4 v4.1.0 // indirect diff --git a/go.sum b/go.sum index 7e73c124..7d46f2d7 100644 --- a/go.sum +++ b/go.sum @@ -20,8 +20,6 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuy github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= -github.com/aliyun/aliyun-oss-go-sdk v2.2.1+incompatible h1:uuJIwCFhbZy+zdvLy5zrcIToPEQP0s5CFOZ0Zj03O/w= -github.com/aliyun/aliyun-oss-go-sdk v2.2.1+incompatible/go.mod h1:T/Aws4fEfogEE9v+HPhhw+CntffsBHJ8nXQCwKr0/g8= github.com/allegro/bigcache/v2 v2.2.5 h1:mRc8r6GQjuJsmSKQNPsR5jQVXc8IJ1xsW5YXUYMLfqI= github.com/allegro/bigcache/v2 v2.2.5/go.mod h1:FppZsIO+IZk7gCuj5FiIDHGygD9xvWQcqg1uIPMb6tY= github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= @@ -34,8 +32,6 @@ github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQ github.com/aws/aws-sdk-go v1.27.0 h1:0xphMHGMLBrPMfxR2AmVjZKcMEESEgWF8Kru94BNByk= github.com/aws/aws-sdk-go v1.27.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g= -github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f h1:ZNv7On9kyUzm7fvRZumSyy/IUiSC7AzL0I1jKKtwooA= -github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f/go.mod h1:AuiFmCCPBSrqvVMvuqFuk0qogytodnVFVSN5CeJB8Gc= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= @@ -466,8 +462,6 @@ github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThC github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E= -github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww= -github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4= github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ= @@ -659,9 +653,6 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/time v0.0.0-20191024005414-555d28b269f0 h1:/5xXl8Y5W96D+TtHSlonuFqGHIWVuyCkGJLwGh9JJFs= -golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=