feat: upload progress recovery (#4987)
* feat(189pc):upload progress recovery * fix:some err * feat(baidu_netdisk,baidu_photo):upload progress recovery * feat(mopan):upload progress recovery * feat(baidu_netdisk):custom upload api
This commit is contained in:
@ -23,7 +23,7 @@ type Group struct {
|
||||
|
||||
func NewGroupWithContext(ctx context.Context, limit int, retryOpts ...retry.Option) (*Group, context.Context) {
|
||||
ctx, cancel := context.WithCancelCause(ctx)
|
||||
return (&Group{cancel: cancel, ctx: ctx, opts: retryOpts}).SetLimit(limit), ctx
|
||||
return (&Group{cancel: cancel, ctx: ctx, opts: append(retryOpts, retry.Context(ctx))}).SetLimit(limit), ctx
|
||||
}
|
||||
|
||||
func (g *Group) done() {
|
||||
|
@ -2,7 +2,6 @@ package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/alist-org/alist/v3/internal/errs"
|
||||
"io"
|
||||
"mime"
|
||||
"os"
|
||||
@ -10,6 +9,8 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/alist-org/alist/v3/internal/errs"
|
||||
|
||||
"github.com/alist-org/alist/v3/internal/conf"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
@ -127,7 +128,7 @@ func CreateTempFile(r io.ReadCloser, size int64) (*os.File, error) {
|
||||
}
|
||||
if size != 0 && readBytes != size {
|
||||
_ = os.Remove(f.Name())
|
||||
return nil, errs.NewErr(err, "CreateTempFile failed, incoming stream actual size= %s, expect = %s ", readBytes, size)
|
||||
return nil, errs.NewErr(err, "CreateTempFile failed, incoming stream actual size= %d, expect = %d ", readBytes, size)
|
||||
}
|
||||
_, err = f.Seek(0, io.SeekStart)
|
||||
if err != nil {
|
||||
|
@ -52,14 +52,15 @@ type limitWriter struct {
|
||||
}
|
||||
|
||||
func (l *limitWriter) Write(p []byte) (n int, err error) {
|
||||
lp := len(p)
|
||||
if l.limit > 0 {
|
||||
if int64(len(p)) > l.limit {
|
||||
if int64(lp) > l.limit {
|
||||
p = p[:l.limit]
|
||||
}
|
||||
l.limit -= int64(len(p))
|
||||
_, err = l.w.Write(p)
|
||||
}
|
||||
return len(p), err
|
||||
return lp, err
|
||||
}
|
||||
|
||||
func LimitWriter(w io.Writer, limit int64) io.Writer {
|
||||
|
@ -69,3 +69,13 @@ func SliceMeet[T1, T2 any](arr []T1, v T2, meet func(item T1, v T2) bool) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func SliceFilter[T any](arr []T, filter func(src T) bool) []T {
|
||||
res := make([]T, 0, len(arr))
|
||||
for _, src := range arr {
|
||||
if filter(src) {
|
||||
res = append(res, src)
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
Reference in New Issue
Block a user