mirror of
https://github.com/tgdrive/teldrive.git
synced 2025-09-07 06:56:48 +08:00
feat: Add tg-session-file flag to run command
This commit is contained in:
parent
82e4f4afe2
commit
4efc7c2591
5 changed files with 14 additions and 5 deletions
|
@ -68,6 +68,7 @@ func NewRun() *cobra.Command {
|
|||
|
||||
runCmd.Flags().IntVar(&config.TG.AppId, "tg-app-id", 0, "Telegram app ID")
|
||||
runCmd.Flags().StringVar(&config.TG.AppHash, "tg-app-hash", "", "Telegram app hash")
|
||||
runCmd.Flags().StringVar(&config.TG.SessionFile, "tg-session-file", "", "Bot session file path")
|
||||
runCmd.Flags().BoolVar(&config.TG.RateLimit, "tg-rate-limit", true, "Enable rate limiting")
|
||||
runCmd.Flags().IntVar(&config.TG.RateBurst, "tg-rate-burst", 5, "Limiting burst")
|
||||
runCmd.Flags().IntVar(&config.TG.Rate, "tg-rate", 100, "Limiting rate")
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
rate = 100
|
||||
rate-burst = 5
|
||||
rate-limit = true
|
||||
session-file = ""
|
||||
system-lang-code = "en-US"
|
||||
system-version = "Win32"
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ type TGConfig struct {
|
|||
LangCode string
|
||||
SystemLangCode string
|
||||
LangPack string
|
||||
SessionFile string
|
||||
BgBotsLimit int
|
||||
DisableStreamBots bool
|
||||
Uploads struct {
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/divyam234/teldrive/internal/config"
|
||||
"github.com/divyam234/teldrive/internal/utils"
|
||||
"go.etcd.io/bbolt"
|
||||
)
|
||||
|
@ -41,8 +42,13 @@ func (b *Bolt) Delete(key string) error {
|
|||
})
|
||||
}
|
||||
|
||||
func NewBoltKV() KV {
|
||||
boltDB, err := bbolt.Open(filepath.Join(utils.ExecutableDir(), "teldrive.db"), 0666, &bbolt.Options{
|
||||
func NewBoltKV(cnf *config.Config) KV {
|
||||
|
||||
sessionFile := cnf.TG.SessionFile
|
||||
if sessionFile == "" {
|
||||
sessionFile = filepath.Join(utils.ExecutableDir(), "teldrive.db")
|
||||
}
|
||||
boltDB, err := bbolt.Open(sessionFile, 0666, &bbolt.Options{
|
||||
Timeout: time.Second,
|
||||
NoGrowSync: false,
|
||||
})
|
||||
|
|
|
@ -21,18 +21,18 @@ func RunWithAuth(ctx context.Context, client *telegram.Client, token string, f f
|
|||
if !status.Authorized {
|
||||
return errors.Errorf("not authorized. please login first")
|
||||
}
|
||||
logger.Debug("User Session",
|
||||
logger.Debugw("User Session",
|
||||
zap.Int64("id", status.User.ID),
|
||||
zap.String("username", status.User.Username))
|
||||
} else {
|
||||
if !status.Authorized {
|
||||
logger.Debug("creating bot session")
|
||||
logger.Debugw("creating bot session")
|
||||
_, err := client.Auth().Bot(ctx, token)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
status, _ = client.Auth().Status(ctx)
|
||||
logger.Debug("Bot Session",
|
||||
logger.Debugw("Bot Session",
|
||||
zap.Int64("id", status.User.ID),
|
||||
zap.String("username", status.User.Username))
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue