mirror of
https://github.com/iyear/tdl
synced 2025-01-09 04:17:35 +08:00
feat(forward): support —delay flag
This commit is contained in:
parent
735bbc74f7
commit
12c4f060de
@ -99,7 +99,7 @@ func (i *iter) HasNext() bool {
|
||||
defer i.mu.Unlock()
|
||||
|
||||
j := i.j + 1
|
||||
return i.i < len(i.dialogs) && j < len(i.dialogs[i.i].Messages)
|
||||
return i.err == nil && i.i < len(i.dialogs) && j < len(i.dialogs[i.i].Messages)
|
||||
}
|
||||
|
||||
func (i *iter) Next(ctx context.Context) bool {
|
||||
|
@ -99,6 +99,7 @@ func Run(ctx context.Context, c *telegram.Client, kvd kv.KV, opts Options) (rerr
|
||||
Progress: newProgress(fwProgress),
|
||||
PartSize: viper.GetInt(consts.FlagPartSize),
|
||||
Threads: viper.GetInt(consts.FlagThreads),
|
||||
Delay: viper.GetDuration(consts.FlagDelay),
|
||||
})
|
||||
|
||||
go fwProgress.Render()
|
||||
|
@ -80,6 +80,10 @@ func newIter(opts iterOptions) *iter {
|
||||
}
|
||||
}
|
||||
|
||||
func (i *iter) HasNext() bool {
|
||||
return i.err == nil && i.i < len(i.opts.dialogs)
|
||||
}
|
||||
|
||||
func (i *iter) Next(ctx context.Context) bool {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
|
@ -55,6 +55,7 @@ func (d *Downloader) Download(ctx context.Context, limit int) error {
|
||||
}
|
||||
|
||||
if d.opts.Delay != 0 && d.opts.Iter.HasNext() {
|
||||
logger.From(ctx).Debug("Delay", zap.Duration("delay", d.opts.Delay))
|
||||
color.Yellow("Delay %s", d.opts.Delay.String())
|
||||
<-time.After(d.opts.Delay)
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package forwarder
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/fatih/color"
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
@ -30,6 +31,7 @@ type Options struct {
|
||||
Threads int
|
||||
Iter Iter
|
||||
Progress Progress
|
||||
Delay time.Duration
|
||||
}
|
||||
|
||||
type Forwarder struct {
|
||||
@ -79,6 +81,12 @@ func (f *Forwarder) Forward(ctx context.Context) error {
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
if f.opts.Delay != 0 && f.opts.Iter.HasNext() {
|
||||
logger.From(ctx).Debug("Delay", zap.Duration("delay", f.opts.Delay))
|
||||
color.Yellow("Delay %s", f.opts.Delay.String())
|
||||
<-time.After(f.opts.Delay)
|
||||
}
|
||||
}
|
||||
|
||||
return f.opts.Iter.Err()
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
|
||||
type Iter interface {
|
||||
Next(ctx context.Context) bool
|
||||
HasNext() bool
|
||||
Value() Elem
|
||||
Err() error
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user