Skip to content

Commit 6d48306

Browse files
committed
在网络不稳定时会自动重试
1 parent 3b41aa6 commit 6d48306

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

Readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
- 支持命令参数使用, 方便外部程序调用.
99
- 支持自定义上传分块大小.
1010
- 支持多线程上传(多文件同时上传).
11-
- ~~支持根据文件大小动态调整重试次数~~
11+
- 支持根据文件大小动态调整重试次数
1212
- ~~支持跳过网盘中已存在的同名文件.~~
1313
- 支持通过Telegram Bot实时监控上传进度,方便使用全自动下载脚本时对上传的实时监控
1414

api/restore/upload/onedriveRecoverableRestore.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,19 @@ func (rs *RestoreService) recoverableUpload(userID string, bearerToken string, c
6262

6363
timeUnix = time.Now().UnixNano()
6464
//3b. make a call to the upload url with the file part based on the offset. 使用基于偏移量的文件部分调用上载url。
65-
resp, err := rs.uploadFilePart(uploadURL, filePath, bearerToken, *filePartInBytes, sOffset, isLastChunk)
66-
65+
var resp *http.Response
66+
for errCount := 1; errCount < 10; errCount++ {
67+
resp, err = rs.uploadFilePart(uploadURL, filePath, bearerToken, *filePartInBytes, sOffset, isLastChunk)
68+
if err != nil {
69+
sendMsg(fmt.Sprintf("向OneDrive账户 `%s` 上传 `%s` 时出现连接问题,正在重试,当前为第%d次重试", username, filePath, errCount))
70+
} else {
71+
break
72+
}
73+
}
6774
if err != nil {
68-
log.Panicf("Failed to Restore :%v", err)
75+
log.Fatalf("Failed to Load Files from source :%v", err)
6976
}
77+
7078
respMap := make(map[string]interface{})
7179
err = json.NewDecoder(resp.Body).Decode(&respMap)
7280
if err != nil {

0 commit comments

Comments
 (0)