Skip to content

Commit addce8b

Browse files
authored
feat(baidu_netdisk): Add shard upload timeout setting (#1682)
add timeout
1 parent 42fc841 commit addce8b

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

drivers/baidu_netdisk/driver.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,13 @@ func (d *BaiduNetdisk) GetAddition() driver.Additional {
5858
}
5959

6060
func (d *BaiduNetdisk) Init(ctx context.Context) error {
61+
timeout := DEFAULT_UPLOAD_SLICE_TIMEOUT
62+
if d.UploadSliceTimeout > 0 {
63+
timeout = time.Second * time.Duration(d.UploadSliceTimeout)
64+
}
65+
6166
d.upClient = base.NewRestyClient().
62-
SetTimeout(UPLOAD_TIMEOUT).
67+
SetTimeout(timeout).
6368
SetRetryCount(UPLOAD_RETRY_COUNT).
6469
SetRetryWaitTime(UPLOAD_RETRY_WAIT_TIME).
6570
SetRetryMaxWaitTime(UPLOAD_RETRY_MAX_WAIT_TIME)

drivers/baidu_netdisk/meta.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type Addition struct {
1919
AccessToken string
2020
RefreshToken string `json:"refresh_token" required:"true"`
2121
UploadThread string `json:"upload_thread" default:"3" help:"1<=thread<=32"`
22+
UploadSliceTimeout int `json:"upload_timeout" type:"number" default:"60" help:"per-slice upload timeout in seconds"`
2223
UploadAPI string `json:"upload_api" default:"https://d.pcs.baidu.com"`
2324
UseDynamicUploadAPI bool `json:"use_dynamic_upload_api" default:"true" help:"dynamically get upload api domain, when enabled, the 'Upload API' setting will be used as a fallback if failed to get"`
2425
CustomUploadPartSize int64 `json:"custom_upload_part_size" type:"number" default:"0" help:"0 for auto"`
@@ -27,12 +28,12 @@ type Addition struct {
2728
}
2829

2930
const (
30-
UPLOAD_FALLBACK_API = "https://d.pcs.baidu.com" // 备用上传地址
31-
UPLOAD_URL_EXPIRE_TIME = time.Minute * 60 // 上传地址有效期(分钟)
32-
UPLOAD_TIMEOUT = time.Minute * 30 // 上传请求超时时间
33-
UPLOAD_RETRY_COUNT = 3
34-
UPLOAD_RETRY_WAIT_TIME = time.Second * 1
35-
UPLOAD_RETRY_MAX_WAIT_TIME = time.Second * 5
31+
UPLOAD_FALLBACK_API = "https://d.pcs.baidu.com" // 备用上传地址
32+
UPLOAD_URL_EXPIRE_TIME = time.Minute * 60 // 上传地址有效期(分钟)
33+
DEFAULT_UPLOAD_SLICE_TIMEOUT = time.Second * 60 // 上传分片请求默认超时时间
34+
UPLOAD_RETRY_COUNT = 3
35+
UPLOAD_RETRY_WAIT_TIME = time.Second * 1
36+
UPLOAD_RETRY_MAX_WAIT_TIME = time.Second * 5
3637
)
3738

3839
var config = driver.Config{

0 commit comments

Comments
 (0)