2019-07-31 02:23:16 +00:00
|
|
|
import parsecfg except Config
|
2020-05-08 00:48:47 +00:00
|
|
|
import types, strutils
|
2019-07-31 02:23:16 +00:00
|
|
|
|
2020-05-08 00:48:47 +00:00
|
|
|
proc get*[T](config: parseCfg.Config; s, v: string; default: T): T =
|
2019-07-31 02:23:16 +00:00
|
|
|
let val = config.getSectionValue(s, v)
|
|
|
|
if val.len == 0: return default
|
|
|
|
|
|
|
|
when T is int: parseInt(val)
|
|
|
|
elif T is bool: parseBool(val)
|
|
|
|
elif T is string: val
|
|
|
|
|
2020-05-08 00:48:47 +00:00
|
|
|
proc getConfig*(path: string): (Config, parseCfg.Config) =
|
2019-07-31 02:23:16 +00:00
|
|
|
var cfg = loadConfig(path)
|
|
|
|
|
2020-05-08 00:48:47 +00:00
|
|
|
let conf = Config(
|
2019-07-31 02:23:16 +00:00
|
|
|
address: cfg.get("Server", "address", "0.0.0.0"),
|
|
|
|
port: cfg.get("Server", "port", 8080),
|
2019-08-19 01:02:34 +00:00
|
|
|
useHttps: cfg.get("Server", "https", true),
|
2019-10-21 03:19:00 +00:00
|
|
|
title: cfg.get("Server", "title", "Nitter"),
|
|
|
|
hostname: cfg.get("Server", "hostname", "nitter.net"),
|
2020-06-01 00:26:04 +00:00
|
|
|
staticDir: cfg.get("Server", "staticDir", "./public"),
|
2019-07-31 02:23:16 +00:00
|
|
|
|
2020-06-09 13:04:38 +00:00
|
|
|
hmacKey: cfg.get("Config", "hmacKey", "secretkey"),
|
|
|
|
base64Media: cfg.get("Config", "base64Media", false),
|
|
|
|
minTokens: cfg.get("Config", "tokenCount", 10),
|
|
|
|
|
2020-06-01 00:26:04 +00:00
|
|
|
listCacheTime: cfg.get("Cache", "listMinutes", 120),
|
|
|
|
rssCacheTime: cfg.get("Cache", "rssMinutes", 10),
|
|
|
|
|
|
|
|
redisHost: cfg.get("Cache", "redisHost", "localhost"),
|
|
|
|
redisPort: cfg.get("Cache", "redisPort", 6379),
|
|
|
|
redisConns: cfg.get("Cache", "redisConnections", 20),
|
2020-06-09 13:04:38 +00:00
|
|
|
redisMaxConns: cfg.get("Cache", "redisMaxConnections", 30)
|
2019-07-31 02:23:16 +00:00
|
|
|
)
|
2020-05-08 00:48:47 +00:00
|
|
|
|
|
|
|
return (conf, cfg)
|