diff --git a/app/dl/dl.go b/app/dl/dl.go index b50c73e867..f5e29ecb9a 100644 --- a/app/dl/dl.go +++ b/app/dl/dl.go @@ -8,7 +8,6 @@ import ( "github.com/AlecAivazis/survey/v2" "github.com/fatih/color" "github.com/go-faster/errors" - "github.com/gotd/contrib/middleware/floodwait" "github.com/spf13/viper" "go.uber.org/multierr" "go.uber.org/zap" @@ -56,7 +55,7 @@ func Run(ctx context.Context, opts *Options) error { } return tgc.RunWithAuth(ctx, c, func(ctx context.Context) (rerr error) { - pool := dcpool.NewPool(c, int64(viper.GetInt(consts.FlagPoolSize)), floodwait.NewSimpleWaiter()) + pool := dcpool.NewPool(c, int64(viper.GetInt(consts.FlagPoolSize)), tgc.DefaultMiddlewares...) defer multierr.AppendInvoke(&rerr, multierr.Close(pool)) parsers := []parser{ diff --git a/app/forward/forward.go b/app/forward/forward.go index aa057f9a0f..d820301f08 100644 --- a/app/forward/forward.go +++ b/app/forward/forward.go @@ -10,7 +10,6 @@ import ( "github.com/antonmedv/expr" "github.com/antonmedv/expr/vm" "github.com/go-faster/errors" - "github.com/gotd/contrib/middleware/floodwait" "github.com/gotd/td/telegram/peers" pw "github.com/jedib0t/go-pretty/v6/progress" "github.com/spf13/viper" @@ -56,7 +55,7 @@ func Run(ctx context.Context, opts Options) error { ctx = tctx.WithKV(ctx, kvd) return tgc.RunWithAuth(ctx, c, func(ctx context.Context) (rerr error) { - pool := dcpool.NewPool(c, int64(viper.GetInt(consts.FlagPoolSize)), floodwait.NewSimpleWaiter()) + pool := dcpool.NewPool(c, int64(viper.GetInt(consts.FlagPoolSize)), tgc.DefaultMiddlewares...) defer multierr.AppendInvoke(&rerr, multierr.Close(pool)) ctx = tctx.WithPool(ctx, pool) diff --git a/app/internal/tgc/tgc.go b/app/internal/tgc/tgc.go index 75cac8d546..f2a3d889a7 100644 --- a/app/internal/tgc/tgc.go +++ b/app/internal/tgc/tgc.go @@ -22,10 +22,13 @@ import ( "github.com/iyear/tdl/pkg/key" "github.com/iyear/tdl/pkg/kv" "github.com/iyear/tdl/pkg/logger" + "github.com/iyear/tdl/pkg/retry" "github.com/iyear/tdl/pkg/storage" "github.com/iyear/tdl/pkg/utils" ) +var DefaultMiddlewares = []telegram.Middleware{retry.New(5), floodwait.NewSimpleWaiter()} + func New(ctx context.Context, login bool, middlewares ...telegram.Middleware) (*telegram.Client, kv.KV, error) { var ( kvd kv.KV @@ -102,9 +105,9 @@ func New(ctx context.Context, login bool, middlewares ...telegram.Middleware) (* } func NoLogin(ctx context.Context, middlewares ...telegram.Middleware) (*telegram.Client, kv.KV, error) { - return New(ctx, false, append(middlewares, floodwait.NewSimpleWaiter())...) + return New(ctx, false, append(middlewares, DefaultMiddlewares...)...) } func Login(ctx context.Context, middlewares ...telegram.Middleware) (*telegram.Client, kv.KV, error) { - return New(ctx, true, append(middlewares, floodwait.NewSimpleWaiter())...) + return New(ctx, true, append(middlewares, DefaultMiddlewares...)...) } diff --git a/app/up/up.go b/app/up/up.go index 95587662fa..0ef57bf874 100644 --- a/app/up/up.go +++ b/app/up/up.go @@ -5,7 +5,6 @@ import ( "github.com/fatih/color" "github.com/go-faster/errors" - "github.com/gotd/contrib/middleware/floodwait" "github.com/spf13/viper" "go.uber.org/multierr" @@ -37,7 +36,7 @@ func Run(ctx context.Context, opts *Options) error { } return tgc.RunWithAuth(ctx, c, func(ctx context.Context) (rerr error) { - pool := dcpool.NewPool(c, int64(viper.GetInt(consts.FlagPoolSize)), floodwait.NewSimpleWaiter()) + pool := dcpool.NewPool(c, int64(viper.GetInt(consts.FlagPoolSize)), tgc.DefaultMiddlewares...) defer multierr.AppendInvoke(&rerr, multierr.Close(pool)) options := uploader.Options{