Unhardcode some paths

This commit is contained in:
Bohdan Horbeshko 2022-01-27 01:57:46 -05:00
parent 6da0fd56ff
commit 540c6cd546
6 changed files with 21 additions and 11 deletions

View file

@ -68,7 +68,9 @@ It is good idea to obtain Telegram API ID from [**https://my.telegram.org**](htt
### Arguments ### ### 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 ### ### How to receive files from Telegram ###

View file

@ -6,6 +6,7 @@
:upload: 'https:///xmppfiles.localhost' # xmpp http upload address :upload: 'https:///xmppfiles.localhost' # xmpp http upload address
:tdlib_verbosity: 1 :tdlib_verbosity: 1
:tdlib: :tdlib:
:datadir: './sessions/'
:client: :client:
:api_id: '17349' :api_id: '17349'
:api_hash: '344583e45741c457fe1862106095a5eb' :api_hash: '344583e45741c457fe1862106095a5eb'

View file

@ -42,6 +42,7 @@ type TelegramContentConfig struct {
// TelegramTdlibConfig is for :tdlib: subtree // TelegramTdlibConfig is for :tdlib: subtree
type TelegramTdlibConfig struct { type TelegramTdlibConfig struct {
Datadir string `yaml:":datadir"`
Client TelegramTdlibClientConfig `yaml:":client"` Client TelegramTdlibClientConfig `yaml:":client"`
} }

View file

@ -31,6 +31,9 @@
"required": [":client"], "required": [":client"],
"type": "object", "type": "object",
"properties": { "properties": {
":datadir": {
"type": "string"
},
":client": { ":client": {
"type": "object", "type": "object",
"required": [":api_id", ":api_hash"], "required": [":api_id", ":api_hash"],

View file

@ -15,12 +15,6 @@ import (
goxmpp "gosrc.io/xmpp" 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 sm *goxmpp.StreamManager
var component *goxmpp.Component var component *goxmpp.Component
var err error var err error
@ -30,6 +24,10 @@ var sigintChannel chan os.Signal
func main() { func main() {
var profilingPort = flag.Int("profiling-port", 0, "The port for pprof server") 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() flag.Parse()
if *profilingPort > 0 { if *profilingPort > 0 {
@ -42,7 +40,7 @@ func main() {
sigintChannel = make(chan os.Signal, 1) sigintChannel = make(chan os.Signal, 1)
signal.Notify(sigintChannel, os.Interrupt) signal.Notify(sigintChannel, os.Interrupt)
config, err := config.ReadConfig(configPath, schemaPath) config, err := config.ReadConfig(*configPath, *schemaPath)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }

View file

@ -78,11 +78,16 @@ func NewClient(conf config.TelegramConfig, jid string, component *xmpp.Component
return &Client{}, errors.Wrap(err, "Wrong api_id") return &Client{}, errors.Wrap(err, "Wrong api_id")
} }
datadir := conf.Tdlib.Datadir
if datadir == "" {
datadir = "./sessions/" // ye olde defaute
}
parameters := client.TdlibParameters{ parameters := client.TdlibParameters{
UseTestDc: false, UseTestDc: false,
DatabaseDirectory: filepath.Join("./sessions/", jid), DatabaseDirectory: filepath.Join(datadir, jid),
FilesDirectory: filepath.Join("./sessions/", jid, "/files/"), FilesDirectory: filepath.Join(datadir, jid, "/files/"),
UseFileDatabase: true, UseFileDatabase: true,
UseChatInfoDatabase: conf.Tdlib.Client.UseChatInfoDatabase, UseChatInfoDatabase: conf.Tdlib.Client.UseChatInfoDatabase,