Skip to content

Commit

Permalink
refactor(app): remove tgc
Browse files Browse the repository at this point in the history
  • Loading branch information
iyear committed Dec 11, 2023
1 parent 6dcb76e commit e58df34
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 230 deletions.
11 changes: 4 additions & 7 deletions app/dl/dl.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"go.uber.org/multierr"
"go.uber.org/zap"

"github.com/iyear/tdl/app/internal/tgc"
"github.com/iyear/tdl/pkg/consts"
"github.com/iyear/tdl/pkg/dcpool"
"github.com/iyear/tdl/pkg/downloader"
Expand All @@ -23,6 +22,7 @@ import (
"github.com/iyear/tdl/pkg/logger"
"github.com/iyear/tdl/pkg/prog"
"github.com/iyear/tdl/pkg/storage"
"github.com/iyear/tdl/pkg/tclient"
"github.com/iyear/tdl/pkg/tmessage"
"github.com/iyear/tdl/pkg/utils"
)
Expand Down Expand Up @@ -53,12 +53,9 @@ type parser struct {
}

func Run(ctx context.Context, c *telegram.Client, kvd kv.KV, opts Options) (rerr error) {
middlewares, err := tgc.NewDefaultMiddlewares(ctx)
if err != nil {
return errors.Wrap(err, "create middlewares")
}

pool := dcpool.NewPool(c, int64(viper.GetInt(consts.FlagPoolSize)), middlewares...)
pool := dcpool.NewPool(c,
int64(viper.GetInt(consts.FlagPoolSize)),
tclient.NewDefaultMiddlewares(ctx, viper.GetDuration(consts.FlagReconnectTimeout))...)
defer multierr.AppendInvoke(&rerr, multierr.Close(pool))

parsers := []parser{
Expand Down
11 changes: 4 additions & 7 deletions app/forward/forward.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ import (
"go.uber.org/multierr"

"github.com/iyear/tdl/app/internal/tctx"
"github.com/iyear/tdl/app/internal/tgc"
"github.com/iyear/tdl/pkg/consts"
"github.com/iyear/tdl/pkg/dcpool"
"github.com/iyear/tdl/pkg/forwarder"
"github.com/iyear/tdl/pkg/kv"
"github.com/iyear/tdl/pkg/prog"
"github.com/iyear/tdl/pkg/storage"
"github.com/iyear/tdl/pkg/tclient"
"github.com/iyear/tdl/pkg/texpr"
"github.com/iyear/tdl/pkg/tmessage"
"github.com/iyear/tdl/pkg/utils"
Expand Down Expand Up @@ -52,12 +52,9 @@ func Run(ctx context.Context, c *telegram.Client, kvd kv.KV, opts Options) (rerr

ctx = tctx.WithKV(ctx, kvd)

middlewares, err := tgc.NewDefaultMiddlewares(ctx)
if err != nil {
return errors.Wrap(err, "create middlewares")
}

pool := dcpool.NewPool(c, int64(viper.GetInt(consts.FlagPoolSize)), middlewares...)
pool := dcpool.NewPool(c,
int64(viper.GetInt(consts.FlagPoolSize)),
tclient.NewDefaultMiddlewares(ctx, viper.GetDuration(consts.FlagReconnectTimeout))...)
defer multierr.AppendInvoke(&rerr, multierr.Close(pool))

ctx = tctx.WithPool(ctx, pool)
Expand Down
29 changes: 0 additions & 29 deletions app/internal/tgc/run.go

This file was deleted.

147 changes: 0 additions & 147 deletions app/internal/tgc/tgc.go

This file was deleted.

18 changes: 15 additions & 3 deletions app/login/code.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,29 @@ import (

"github.com/cenkalti/backoff/v4"
"github.com/fatih/color"
"github.com/go-faster/errors"
"github.com/gotd/td/telegram"
"github.com/gotd/td/telegram/auth"
"github.com/spf13/viper"

"github.com/iyear/tdl/app/internal/tgc"
"github.com/iyear/tdl/pkg/consts"
"github.com/iyear/tdl/pkg/key"
"github.com/iyear/tdl/pkg/kv"
"github.com/iyear/tdl/pkg/tclient"
)

func Code(ctx context.Context) error {
c, kv, err := tgc.Login(ctx)
kvd, err := kv.From(ctx).Open(viper.GetString(consts.FlagNamespace))
if err != nil {
return errors.Wrap(err, "open kv")
}
c, err := tclient.New(ctx, tclient.Options{
KV: kvd,
Proxy: viper.GetString(consts.FlagProxy),
NTP: viper.GetString(consts.FlagNTP),
ReconnectTimeout: viper.GetDuration(consts.FlagReconnectTimeout),
Test: viper.GetString(consts.FlagTest) != "",
}, true)
if err != nil {
return err
}
Expand Down Expand Up @@ -54,7 +66,7 @@ func Code(ctx context.Context) error {
return err
}

if err = kv.Set(key.App(), []byte(consts.AppBuiltin)); err != nil {
if err = kvd.Set(key.App(), []byte(tclient.AppBuiltin)); err != nil {
return err
}

Expand Down
3 changes: 2 additions & 1 deletion app/login/desktop.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/iyear/tdl/pkg/key"
"github.com/iyear/tdl/pkg/kv"
"github.com/iyear/tdl/pkg/storage"
"github.com/iyear/tdl/pkg/tclient"
"github.com/iyear/tdl/pkg/tdesktop"
"github.com/iyear/tdl/pkg/tpath"
"github.com/iyear/tdl/pkg/utils"
Expand Down Expand Up @@ -78,7 +79,7 @@ func Desktop(ctx context.Context, opts *Options) error {
return err
}

if err = kvd.Set(key.App(), []byte(consts.AppDesktop)); err != nil {
if err = kvd.Set(key.App(), []byte(tclient.AppDesktop)); err != nil {
return err
}

Expand Down
11 changes: 4 additions & 7 deletions app/up/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import (
"github.com/spf13/viper"
"go.uber.org/multierr"

"github.com/iyear/tdl/app/internal/tgc"
"github.com/iyear/tdl/pkg/consts"
"github.com/iyear/tdl/pkg/dcpool"
"github.com/iyear/tdl/pkg/kv"
"github.com/iyear/tdl/pkg/prog"
"github.com/iyear/tdl/pkg/storage"
"github.com/iyear/tdl/pkg/tclient"
"github.com/iyear/tdl/pkg/uploader"
"github.com/iyear/tdl/pkg/utils"
)
Expand All @@ -37,12 +37,9 @@ func Run(ctx context.Context, c *telegram.Client, kvd kv.KV, opts Options) (rerr

color.Blue("Files count: %d", len(files))

middlewares, err := tgc.NewDefaultMiddlewares(ctx)
if err != nil {
return errors.Wrap(err, "create middlewares")
}

pool := dcpool.NewPool(c, int64(viper.GetInt(consts.FlagPoolSize)), middlewares...)
pool := dcpool.NewPool(c,
int64(viper.GetInt(consts.FlagPoolSize)),
tclient.NewDefaultMiddlewares(ctx, viper.GetDuration(consts.FlagReconnectTimeout))...)
defer multierr.AppendInvoke(&rerr, multierr.Close(pool))

manager := peers.Options{Storage: storage.NewPeers(kvd)}.Build(pool.Default(ctx))
Expand Down
29 changes: 0 additions & 29 deletions pkg/consts/telegram.go
Original file line number Diff line number Diff line change
@@ -1,32 +1,3 @@
package consts

import (
"github.com/gotd/td/telegram"
)

const (
AppBuiltin = "builtin"
AppDesktop = "desktop"
)

var Apps = map[string]struct {
AppID int
AppHash string
}{
// application created by iyear
AppBuiltin: {AppID: 15055931, AppHash: "021d433426cbb920eeb95164498fe3d3"},
// application created by tdesktop.
// https://opentele.readthedocs.io/en/latest/documentation/authorization/api/#class-telegramdesktop
AppDesktop: {AppID: 2040, AppHash: "b18441a1ff607e10a989891a5462e627"},
}

var Device = telegram.DeviceConfig{
DeviceModel: "Desktop",
SystemVersion: "Windows 10",
AppVersion: "4.2.4 x64",
LangCode: "en",
SystemLangCode: "en-US",
LangPack: "tdesktop",
}

const FileMaxSize = 4000 * 1024 * 1024

0 comments on commit e58df34

Please sign in to comment.