From d8789f7c74fbc1899969c44be9a0291035f0f8e9 Mon Sep 17 00:00:00 2001 From: iyear Date: Sun, 26 Nov 2023 14:09:48 +0800 Subject: [PATCH] chore(forward): pass part size in options --- app/forward/forward.go | 1 + pkg/forwarder/clone.go | 3 +-- pkg/forwarder/forwarder.go | 7 +++---- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/app/forward/forward.go b/app/forward/forward.go index 4eff2e4..3ef0240 100644 --- a/app/forward/forward.go +++ b/app/forward/forward.go @@ -86,6 +86,7 @@ func Run(ctx context.Context, opts Options) error { DryRun: opts.DryRun, Mode: opts.Mode, Progress: newProgress(fwProgress), + PartSize: viper.GetInt(consts.FlagPartSize), }) go fwProgress.Render() diff --git a/pkg/forwarder/clone.go b/pkg/forwarder/clone.go index 75a55b5..acc6867 100644 --- a/pkg/forwarder/clone.go +++ b/pkg/forwarder/clone.go @@ -67,8 +67,7 @@ func (f *Forwarder) CloneMedia(ctx context.Context, opts CloneOptions) (tg.Input return nil }) - err := wg.Wait() - if err != nil { + if err := wg.Wait(); err != nil { return nil, errors.Wrap(err, "wait") } diff --git a/pkg/forwarder/forwarder.go b/pkg/forwarder/forwarder.go index 04fb60e..53c58a9 100644 --- a/pkg/forwarder/forwarder.go +++ b/pkg/forwarder/forwarder.go @@ -11,10 +11,8 @@ import ( "github.com/gotd/td/telegram/message" "github.com/gotd/td/telegram/peers" "github.com/gotd/td/tg" - "github.com/spf13/viper" "go.uber.org/zap" - "github.com/iyear/tdl/pkg/consts" "github.com/iyear/tdl/pkg/dcpool" "github.com/iyear/tdl/pkg/logger" "github.com/iyear/tdl/pkg/tmedia" @@ -41,6 +39,7 @@ type Elem struct { type Options struct { Pool dcpool.Pool + PartSize int Iter Iter Silent bool DryRun bool @@ -178,7 +177,7 @@ func (f *Forwarder) forwardMessage(ctx context.Context, from, to peers.Peer, msg mediaFile, err := f.CloneMedia(ctx, CloneOptions{ Media: media, - PartSize: viper.GetInt(consts.FlagPartSize), + PartSize: f.opts.PartSize, Progress: uploadProgress{ meta: meta, progress: f.opts.Progress, @@ -211,7 +210,7 @@ func (f *Forwarder) forwardMessage(ctx context.Context, from, to peers.Peer, msg thumbFile, err := f.CloneMedia(ctx, CloneOptions{ Media: thumb, - PartSize: viper.GetInt(consts.FlagPartSize), + PartSize: f.opts.PartSize, Progress: nopProgress{}, }) if err != nil {