From 540c6cd546ccadbb2c32e435d1fdcb5af24a1360 Mon Sep 17 00:00:00 2001 From: Bohdan Horbeshko Date: Thu, 27 Jan 2022 01:57:46 -0500 Subject: [PATCH] Unhardcode some paths --- README.md | 4 +++- config.yml.example | 1 + config/config.go | 3 ++- config_schema.json | 3 +++ telegabber.go | 12 +++++------- telegram/client.go | 9 +++++++-- 6 files changed, 21 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index baef1cf..bdbb218 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,9 @@ It is good idea to obtain Telegram API ID from [**https://my.telegram.org**](htt ### Arguments ### -* `--profiling-port=xxxx`: starts the pprof server on port `xxxx`. Access is limited to localhost. +* `--profiling-port=xxxx`: start the pprof server on port `xxxx`. Access is limited to localhost. +* `--config=/bla/bla/config.yml`: set the config file path (default: `config.yml`). +* `--schema=/bla/bla/schema.json`: set the schema file path (default: `./config_schema.json`). ### How to receive files from Telegram ### diff --git a/config.yml.example b/config.yml.example index 130366b..eed3257 100644 --- a/config.yml.example +++ b/config.yml.example @@ -6,6 +6,7 @@ :upload: 'https:///xmppfiles.localhost' # xmpp http upload address :tdlib_verbosity: 1 :tdlib: + :datadir: './sessions/' :client: :api_id: '17349' :api_hash: '344583e45741c457fe1862106095a5eb' diff --git a/config/config.go b/config/config.go index 39fa4da..8c7cc9b 100644 --- a/config/config.go +++ b/config/config.go @@ -42,7 +42,8 @@ type TelegramContentConfig struct { // TelegramTdlibConfig is for :tdlib: subtree type TelegramTdlibConfig struct { - Client TelegramTdlibClientConfig `yaml:":client"` + Datadir string `yaml:":datadir"` + Client TelegramTdlibClientConfig `yaml:":client"` } // TelegramTdlibClientConfig is for :client: subtree diff --git a/config_schema.json b/config_schema.json index f146edb..785bb44 100644 --- a/config_schema.json +++ b/config_schema.json @@ -31,6 +31,9 @@ "required": [":client"], "type": "object", "properties": { + ":datadir": { + "type": "string" + }, ":client": { "type": "object", "required": [":api_id", ":api_hash"], diff --git a/telegabber.go b/telegabber.go index 14b3b3d..97a082b 100644 --- a/telegabber.go +++ b/telegabber.go @@ -15,12 +15,6 @@ import ( goxmpp "gosrc.io/xmpp" ) -// YAML config, compatible with the format of Zhabogram 2.0.0 -const configPath string = "config.yml" - -// JSON schema (not for editing by a user) -const schemaPath string = "./config_schema.json" - var sm *goxmpp.StreamManager var component *goxmpp.Component var err error @@ -30,6 +24,10 @@ var sigintChannel chan os.Signal func main() { var profilingPort = flag.Int("profiling-port", 0, "The port for pprof server") + // YAML config, compatible with the format of Zhabogram 2.0.0 + var configPath = flag.String("config", "config.yml", "Config file path") + // JSON schema (not for editing by a user) + var schemaPath = flag.String("schema", "./config_schema.json", "Schema file path") flag.Parse() if *profilingPort > 0 { @@ -42,7 +40,7 @@ func main() { sigintChannel = make(chan os.Signal, 1) signal.Notify(sigintChannel, os.Interrupt) - config, err := config.ReadConfig(configPath, schemaPath) + config, err := config.ReadConfig(*configPath, *schemaPath) if err != nil { log.Fatal(err) } diff --git a/telegram/client.go b/telegram/client.go index 4995597..8813df0 100644 --- a/telegram/client.go +++ b/telegram/client.go @@ -78,11 +78,16 @@ func NewClient(conf config.TelegramConfig, jid string, component *xmpp.Component return &Client{}, errors.Wrap(err, "Wrong api_id") } + datadir := conf.Tdlib.Datadir + if datadir == "" { + datadir = "./sessions/" // ye olde defaute + } + parameters := client.TdlibParameters{ UseTestDc: false, - DatabaseDirectory: filepath.Join("./sessions/", jid), - FilesDirectory: filepath.Join("./sessions/", jid, "/files/"), + DatabaseDirectory: filepath.Join(datadir, jid), + FilesDirectory: filepath.Join(datadir, jid, "/files/"), UseFileDatabase: true, UseChatInfoDatabase: conf.Tdlib.Client.UseChatInfoDatabase,