feat: support cancel for some drivers (close #2717)

This commit is contained in:
Noah Hsu
2022-12-21 15:03:09 +08:00
parent e4a88a7c13
commit 105f22969c
31 changed files with 118 additions and 129 deletions

View File

@ -13,6 +13,7 @@ import (
"github.com/alist-org/alist/v3/internal/driver"
"github.com/alist-org/alist/v3/internal/errs"
"github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/pkg/utils"
log "github.com/sirupsen/logrus"
)
@ -268,6 +269,9 @@ func (d *Yun139) Put(ctx context.Context, dstDir model.Obj, stream model.FileStr
part := int(math.Ceil(float64(stream.GetSize()) / float64(Default)))
var start int64 = 0
for i := 0; i < part; i++ {
if utils.IsCanceled(ctx) {
return ctx.Err()
}
byteSize := stream.GetSize() - start
if byteSize > Default {
byteSize = Default
@ -281,6 +285,7 @@ func (d *Yun139) Put(ctx context.Context, dstDir model.Obj, stream model.FileStr
if err != nil {
return err
}
req = req.WithContext(ctx)
headers := map[string]string{
"Accept": "*/*",
"Content-Type": "text/plain;name=" + unicode(stream.GetName()),