diff --git a/pkg/filesystem/driver/onedrive/api.go b/pkg/filesystem/driver/onedrive/api.go index 7498b10..8165b52 100644 --- a/pkg/filesystem/driver/onedrive/api.go +++ b/pkg/filesystem/driver/onedrive/api.go @@ -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) } diff --git a/pkg/filesystem/fsctx/context.go b/pkg/filesystem/fsctx/context.go index 355d0a5..d8b9061 100644 --- a/pkg/filesystem/fsctx/context.go +++ b/pkg/filesystem/fsctx/context.go @@ -23,8 +23,6 @@ const ( UserCtx // ThumbSizeCtx 缩略图尺寸 ThumbSizeCtx - // OriginSourceNameCtx 原始原文件名 - OriginSourceNameCtx // FileSizeCtx 文件大小 FileSizeCtx // ShareKeyCtx 分享文件的 HashID @@ -33,4 +31,6 @@ const ( LimitParentCtx // IgnoreConflictCtx 忽略重名冲突 IgnoreConflictCtx + // RetryCtx 失败重试次数 + RetryCtx )