mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-19 08:19:15 +08:00
fix: 解决部分 Onedrive 备份账号添加失败的问题 (#3621)
This commit is contained in:
parent
f89365106a
commit
1e5ea024ad
@ -4,6 +4,7 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"crypto/tls"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -14,6 +15,7 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/1Panel-dev/1Panel/backend/app/model"
|
"github.com/1Panel-dev/1Panel/backend/app/model"
|
||||||
"github.com/1Panel-dev/1Panel/backend/constant"
|
"github.com/1Panel-dev/1Panel/backend/constant"
|
||||||
@ -157,7 +159,13 @@ func (o oneDriveClient) Upload(src, target string) (bool, error) {
|
|||||||
splitCount += 1
|
splitCount += 1
|
||||||
}
|
}
|
||||||
bfReader := bufio.NewReader(file)
|
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++ {
|
for splitNow := int64(0); splitNow < splitCount; splitNow++ {
|
||||||
length, err := bfReader.Read(buffer)
|
length, err := bfReader.Read(buffer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -171,12 +179,15 @@ func (o oneDriveClient) Upload(src, target string) (bool, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
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
|
return false, err
|
||||||
}
|
}
|
||||||
}
|
if res.StatusCode != 201 && res.StatusCode != 202 && res.StatusCode != 200 {
|
||||||
if fileUploadResp.Id == "" {
|
data, _ := io.ReadAll(res.Body)
|
||||||
return false, errors.New("something went wrong. file upload incomplete. consider upload the file in a step-by-step manner")
|
res.Body.Close()
|
||||||
|
return false, errors.New(string(data))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true, nil
|
return true, nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user