config.nim 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # SPDX-License-Identifier: AGPL-3.0-only
  2. import parsecfg except Config
  3. import types, strutils
  4. proc get*[T](config: parseCfg.Config; section, key: string; default: T): T =
  5. let val = config.getSectionValue(section, key)
  6. if val.len == 0: return default
  7. when T is int: parseInt(val)
  8. elif T is bool: parseBool(val)
  9. elif T is string: val
  10. proc getConfig*(path: string): (Config, parseCfg.Config) =
  11. var cfg = loadConfig(path)
  12. let conf = Config(
  13. # Server
  14. address: cfg.get("Server", "address", "0.0.0.0"),
  15. port: cfg.get("Server", "port", 8080),
  16. useHttps: cfg.get("Server", "https", true),
  17. httpMaxConns: cfg.get("Server", "httpMaxConnections", 100),
  18. staticDir: cfg.get("Server", "staticDir", "./public"),
  19. title: cfg.get("Server", "title", "Nitter"),
  20. hostname: cfg.get("Server", "hostname", "nitter.net"),
  21. # Cache
  22. listCacheTime: cfg.get("Cache", "listMinutes", 120),
  23. rssCacheTime: cfg.get("Cache", "rssMinutes", 10),
  24. redisHost: cfg.get("Cache", "redisHost", "localhost"),
  25. redisPort: cfg.get("Cache", "redisPort", 6379),
  26. redisConns: cfg.get("Cache", "redisConnections", 20),
  27. redisMaxConns: cfg.get("Cache", "redisMaxConnections", 30),
  28. redisPassword: cfg.get("Cache", "redisPassword", ""),
  29. # Config
  30. hmacKey: cfg.get("Config", "hmacKey", "secretkey"),
  31. base64Media: cfg.get("Config", "base64Media", false),
  32. minTokens: cfg.get("Config", "tokenCount", 10),
  33. enableRss: cfg.get("Config", "enableRSS", true),
  34. enableDebug: cfg.get("Config", "enableDebug", false),
  35. proxy: cfg.get("Config", "proxy", ""),
  36. proxyAuth: cfg.get("Config", "proxyAuth", ""),
  37. apiProxy: cfg.get("Config", "apiProxy", ""),
  38. disableTid: cfg.get("Config", "disableTid", false),
  39. maxConcurrentReqs: cfg.get("Config", "maxConcurrentReqs", 2)
  40. )
  41. return (conf, cfg)