* refactor: a big refactor. wip * refactor: port handle file * refactor: place all handlers * fix: task info nil pointer * feat: enhance task progress tracking and context management * feat: cancel task * feat: stream mode * feat: silent mode * feat: dir cmd * refactor: remove unused old file * feat: rule cmd * feat: handle silent mode * feat: batch task * fix: batch task progress and temp file cleanup * refactor: update file creation and cleanup methods for better resource management * feat: add save command with silent mode handling * feat: message link * feat: update message prompts to include file count in storage selection * feat: slient save links * refactor: reduce dup code * feat: rule type * feat: chose dir * feat: refactor file handling and storage rules, improve error handling and logging * feat: rule mode * feat: telegraph pics * fix: tphpics nil pointer and inaccurate dirpath * feat: silent save telegraph * feat: add suffix to avoid file overwrite * feat: new storage telegram * chore: tidy go mod
30 lines
756 B
Go
30 lines
756 B
Go
package middleware
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/cenkalti/backoff/v4"
|
|
"github.com/gotd/contrib/middleware/floodwait"
|
|
"github.com/gotd/td/telegram"
|
|
"github.com/krau/SaveAny-Bot/client/middleware/recovery"
|
|
"github.com/krau/SaveAny-Bot/client/middleware/retry"
|
|
)
|
|
|
|
// https://github.com/iyear/tdl/blob/master/core/tclient/tclient.go
|
|
func NewDefaultMiddlewares(ctx context.Context, timeout time.Duration) []telegram.Middleware {
|
|
return []telegram.Middleware{
|
|
recovery.New(ctx, newBackoff(timeout)),
|
|
retry.New(5),
|
|
floodwait.NewSimpleWaiter(),
|
|
}
|
|
}
|
|
|
|
func newBackoff(timeout time.Duration) backoff.BackOff {
|
|
b := backoff.NewExponentialBackOff()
|
|
b.Multiplier = 1.1
|
|
b.MaxElapsedTime = timeout
|
|
b.MaxInterval = 10 * time.Second
|
|
return b
|
|
}
|