Feat: retry for Onedrive SimpleUpload

pull/247/head
HFO4 4 years ago
parent 491e4de9de
commit 1a93c9a2b9

@ -8,6 +8,7 @@ import (
"fmt"
model "github.com/HFO4/cloudreve/models"
"github.com/HFO4/cloudreve/pkg/cache"
"github.com/HFO4/cloudreve/pkg/filesystem/fsctx"
"github.com/HFO4/cloudreve/pkg/request"
"github.com/HFO4/cloudreve/pkg/util"
"io"
@ -254,6 +255,16 @@ func (client *Client) SimpleUpload(ctx context.Context, dst string, body io.Read
res, err := client.request(ctx, "PUT", requestURL, body, request.WithContentLength(int64(size)))
if err != nil {
retried := 0
if v, ok := ctx.Value(fsctx.RetryCtx).(int); ok {
retried = v
}
if retried < model.GetIntSetting("onedrive_chunk_retries", 1) {
retried++
util.Log().Debug("文件[%s]上传失败[%s]5秒钟后重试", dst, err)
time.Sleep(time.Duration(5) * time.Second)
return client.SimpleUpload(context.WithValue(ctx, fsctx.RetryCtx, retried), dst, body, size)
}
return nil, err
}
@ -501,7 +512,6 @@ func (client *Client) request(ctx context.Context, method string, url string, bo
)
if res.Err != nil {
// TODO 重试
return "", sysError(res.Err)
}

@ -23,8 +23,6 @@ const (
UserCtx
// ThumbSizeCtx 缩略图尺寸
ThumbSizeCtx
// OriginSourceNameCtx 原始原文件名
OriginSourceNameCtx
// FileSizeCtx 文件大小
FileSizeCtx
// ShareKeyCtx 分享文件的 HashID
@ -33,4 +31,6 @@ const (
LimitParentCtx
// IgnoreConflictCtx 忽略重名冲突
IgnoreConflictCtx
// RetryCtx 失败重试次数
RetryCtx
)

Loading…
Cancel
Save