feat: add configurable timeout for Telegram client initialization

This commit is contained in:
krau
2025-04-07 10:23:50 +08:00
parent 87d3f14392
commit 50fba3f910
3 changed files with 7 additions and 9 deletions

View File

@@ -27,10 +27,10 @@ func newProxyDialer(proxyUrl string) (proxy.Dialer, error) {
} }
func Init() { func Init() {
InitTelegraphClient()
common.Log.Info("初始化 Telegram 客户端...") common.Log.Info("初始化 Telegram 客户端...")
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second) ctx, cancel := context.WithTimeout(context.Background(), time.Duration(config.Cfg.Telegram.Timeout)*time.Second)
defer cancel() defer cancel()
go InitTelegraphClient()
resultChan := make(chan struct { resultChan := make(chan struct {
client *gotgproto.Client client *gotgproto.Client
err error err error

View File

@@ -13,6 +13,9 @@ token = ""
# app_id = 123456 # app_id = 123456
# app_hash = "0123456789abcdef0123456789abcdef" # app_hash = "0123456789abcdef0123456789abcdef"
# 初始化超时时间, 单位: 秒
timeout = 60
[telegram.proxy] [telegram.proxy]
# 启用代理连接 telegram, 只支持 socks5 # 启用代理连接 telegram, 只支持 socks5
enable = false enable = false
@@ -30,12 +33,6 @@ enable = true
# 文件保存根路径 # 文件保存根路径
base_path = "./downloads" base_path = "./downloads"
[[storages]]
name = "本机2"
type = "local"
enable = true
base_path = "./downloads/2"
[[storages]] [[storages]]
name = "MyAlist" name = "MyAlist"
type = "alist" type = "alist"
@@ -49,7 +46,6 @@ token_exp = 86400 # 86400--1天 604800--7天 1296000--15天 2592000--30
# 请自行在 alist 侧配置合理的 token 过期时间 # 请自行在 alist 侧配置合理的 token 过期时间
# token = "" # token = ""
[[storages]] [[storages]]
name = "MyWebdav" name = "MyWebdav"
type = "webdav" type = "webdav"

View File

@@ -44,6 +44,7 @@ type telegramConfig struct {
Token string `toml:"token" mapstructure:"token"` Token string `toml:"token" mapstructure:"token"`
AppID int `toml:"app_id" mapstructure:"app_id" json:"app_id"` AppID int `toml:"app_id" mapstructure:"app_id" json:"app_id"`
AppHash string `toml:"app_hash" mapstructure:"app_hash" json:"app_hash"` AppHash string `toml:"app_hash" mapstructure:"app_hash" json:"app_hash"`
Timeout int `toml:"timeout" mapstructure:"timeout" json:"timeout"`
Proxy proxyConfig `toml:"proxy" mapstructure:"proxy"` Proxy proxyConfig `toml:"proxy" mapstructure:"proxy"`
// Deprecated // Deprecated
@@ -82,6 +83,7 @@ func Init() error {
viper.SetDefault("telegram.app_id", 1025907) viper.SetDefault("telegram.app_id", 1025907)
viper.SetDefault("telegram.app_hash", "452b0359b988148995f22ff0f4229750") viper.SetDefault("telegram.app_hash", "452b0359b988148995f22ff0f4229750")
viper.SetDefault("telegram.timeout", 60)
viper.SetDefault("temp.base_path", "cache/") viper.SetDefault("temp.base_path", "cache/")
viper.SetDefault("temp.cache_ttl", 3600) viper.SetDefault("temp.cache_ttl", 3600)