mirror of https://github.com/cloudreve/Cloudreve
Feat: retry for Onedrive SimpleUpload
parent
491e4de9de
commit
1a93c9a2b9
|
@ -8,6 +8,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
model "github.com/HFO4/cloudreve/models"
|
model "github.com/HFO4/cloudreve/models"
|
||||||
"github.com/HFO4/cloudreve/pkg/cache"
|
"github.com/HFO4/cloudreve/pkg/cache"
|
||||||
|
"github.com/HFO4/cloudreve/pkg/filesystem/fsctx"
|
||||||
"github.com/HFO4/cloudreve/pkg/request"
|
"github.com/HFO4/cloudreve/pkg/request"
|
||||||
"github.com/HFO4/cloudreve/pkg/util"
|
"github.com/HFO4/cloudreve/pkg/util"
|
||||||
"io"
|
"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)))
|
res, err := client.request(ctx, "PUT", requestURL, body, request.WithContentLength(int64(size)))
|
||||||
if err != nil {
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -501,7 +512,6 @@ func (client *Client) request(ctx context.Context, method string, url string, bo
|
||||||
)
|
)
|
||||||
|
|
||||||
if res.Err != nil {
|
if res.Err != nil {
|
||||||
// TODO 重试
|
|
||||||
return "", sysError(res.Err)
|
return "", sysError(res.Err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,8 +23,6 @@ const (
|
||||||
UserCtx
|
UserCtx
|
||||||
// ThumbSizeCtx 缩略图尺寸
|
// ThumbSizeCtx 缩略图尺寸
|
||||||
ThumbSizeCtx
|
ThumbSizeCtx
|
||||||
// OriginSourceNameCtx 原始原文件名
|
|
||||||
OriginSourceNameCtx
|
|
||||||
// FileSizeCtx 文件大小
|
// FileSizeCtx 文件大小
|
||||||
FileSizeCtx
|
FileSizeCtx
|
||||||
// ShareKeyCtx 分享文件的 HashID
|
// ShareKeyCtx 分享文件的 HashID
|
||||||
|
@ -33,4 +31,6 @@ const (
|
||||||
LimitParentCtx
|
LimitParentCtx
|
||||||
// IgnoreConflictCtx 忽略重名冲突
|
// IgnoreConflictCtx 忽略重名冲突
|
||||||
IgnoreConflictCtx
|
IgnoreConflictCtx
|
||||||
|
// RetryCtx 失败重试次数
|
||||||
|
RetryCtx
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue