Skip to content

Commit

Permalink
Automatically try again when uploading onedrive fails
Browse files Browse the repository at this point in the history
  • Loading branch information
gaowanliang committed Apr 2, 2021
1 parent 9996700 commit 598b2a0
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
3 changes: 2 additions & 1 deletion i18n/active.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,6 @@
"googleDriveOAuthFileCreateSuccess": "Google Drive OAuth2 file created successfully, save to:",
"startUploadGoogleDrive": "Start uploading to Google Drive",
"googleDriveUploadTip": "Google Drive account `%s` \n Uploading `%s` Time: %d s",
"uploadGoogleDriveComplete": "DownloadFolder upload to Google Drive complete"
"uploadGoogleDriveComplete": "DownloadFolder upload to Google Drive complete",
"oneDriveUploadFailAndRetry": "OneDrive account `%s` \n There was a connection problem when uploading `%s`. Retrying. It's the %d times retrying"
}
3 changes: 2 additions & 1 deletion i18n/active.zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,6 @@
"googleDriveOAuthFileCreateSuccess": "Google Drive OAuth2文件创建成功,保存至:",
"startUploadGoogleDrive": "开始上传至Google Drive",
"googleDriveUploadTip": "正在向Google Drive账户 `%s` 上传 `%s` 已耗时: %d s",
"uploadGoogleDriveComplete": "DownloadFolder上传至Google Drive完成"
"uploadGoogleDriveComplete": "DownloadFolder上传至Google Drive完成",
"oneDriveUploadFailAndRetry": "向OneDrive账户 `%s` 上传 `%s` 时出现连接问题,正在重试,当前为第%d次重试"
}
3 changes: 2 additions & 1 deletion i18n/active.zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,6 @@
"googleDriveOAuthFileCreateSuccess": "Google Drive OAuth2檔創建成功,保存至:",
"startUploadGoogleDrive": "開始上傳至Google Drive",
"googleDriveUploadTip": "正在向Google Drive帳戶 `%s` 上傳 `%s` 已耗時: %d s",
"uploadGoogleDriveComplete": "DownloadFolder上傳至Google Drive完成"
"uploadGoogleDriveComplete": "DownloadFolder上傳至Google Drive完成",
"oneDriveUploadFailAndRetry": "向OneDrive帳戶 `%s` 上傳 `%s` 時出現連接問題,正在重試,當前為第%d次重試"
}
10 changes: 9 additions & 1 deletion src/onedrive/api/restore/upload/onedriveRecoverableRestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,15 @@ func (rs *RestoreService) recoverableUpload(userID string, bearerToken string, c

timeUnix = time.Now().UnixNano()
//3b. make a call to the upload url with the file part based on the offset. 使用基于偏移量的文件部分调用上载url。
resp, err := rs.uploadFilePart(uploadURL, filePath, bearerToken, *filePartInBytes, sOffset, isLastChunk)
var resp *http.Response
for errCount := 1; errCount < 10; errCount++ {
resp, err = rs.uploadFilePart(uploadURL, filePath, bearerToken, *filePartInBytes, sOffset, isLastChunk)
if err != nil {
sendMsg(fmt.Sprintf(locText("oneDriveUploadFailAndRetry"), username, filePath, errCount))
} else {
break
}
}

if err != nil {
return nil, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,15 @@ func (rs *RestoreService) recoverableUpload(userID string, bearerToken string, c

timeUnix = time.Now().UnixNano()
//3b. make a call to the upload url with the file part based on the offset. 使用基于偏移量的文件部分调用上载url。
resp, err := rs.uploadFilePart(uploadURL, filePath, bearerToken, *filePartInBytes, sOffset, isLastChunk)
var resp *http.Response
for errCount := 1; errCount < 10; errCount++ {
resp, err = rs.uploadFilePart(uploadURL, filePath, bearerToken, *filePartInBytes, sOffset, isLastChunk)
if err != nil {
sendMsg(fmt.Sprintf(locText("oneDriveUploadFailAndRetry"), username, filePath, errCount))
} else {
break
}
}

if err != nil {
return nil, err
Expand Down

0 comments on commit 598b2a0

Please sign in to comment.