From 1e5ea024ad7817f3ecaf725a4802d9f8d335d849 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Tue, 16 Jan 2024 16:03:45 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E9=83=A8=E5=88=86=20O?= =?UTF-8?q?nedrive=20=E5=A4=87=E4=BB=BD=E8=B4=A6=E5=8F=B7=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=97=AE=E9=A2=98=20(#3621?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../utils/cloud_storage/client/onedrive.go | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/backend/utils/cloud_storage/client/onedrive.go b/backend/utils/cloud_storage/client/onedrive.go index b349d9ff9..603010aa2 100644 --- a/backend/utils/cloud_storage/client/onedrive.go +++ b/backend/utils/cloud_storage/client/onedrive.go @@ -4,6 +4,7 @@ import ( "bufio" "bytes" "context" + "crypto/tls" "encoding/json" "errors" "fmt" @@ -14,6 +15,7 @@ import ( "path" "strconv" "strings" + "time" "github.com/1Panel-dev/1Panel/backend/app/model" "github.com/1Panel-dev/1Panel/backend/constant" @@ -157,7 +159,13 @@ func (o oneDriveClient) Upload(src, target string) (bool, error) { splitCount += 1 } bfReader := bufio.NewReader(file) - var fileUploadResp *UploadSessionUploadResponse + httpClient := http.Client{ + Timeout: time.Minute * 10, + Transport: &http.Transport{ + Proxy: http.ProxyFromEnvironment, + TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, + }, + } for splitNow := int64(0); splitNow < splitCount; splitNow++ { length, err := bfReader.Read(buffer) if err != nil { @@ -171,12 +179,15 @@ func (o oneDriveClient) Upload(src, target string) (bool, error) { if err != nil { return false, err } - if err := o.client.Do(ctx, sessionFileUploadReq, false, &fileUploadResp); err != nil { + res, err := httpClient.Do(sessionFileUploadReq) + if err != nil { return false, err } - } - if fileUploadResp.Id == "" { - return false, errors.New("something went wrong. file upload incomplete. consider upload the file in a step-by-step manner") + if res.StatusCode != 201 && res.StatusCode != 202 && res.StatusCode != 200 { + data, _ := io.ReadAll(res.Body) + res.Body.Close() + return false, errors.New(string(data)) + } } return true, nil