config.nim 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 masterRss = cfg.get("Config", "enableRSS", true)
  13. let conf = Config(
  14. # Server
  15. address: cfg.get("Server", "address", "0.0.0.0"),
  16. port: cfg.get("Server", "port", 8080),
  17. useHttps: cfg.get("Server", "https", true),
  18. httpMaxConns: cfg.get("Server", "httpMaxConnections", 100),
  19. staticDir: cfg.get("Server", "staticDir", "./public"),
  20. title: cfg.get("Server", "title", "Nitter"),
  21. hostname: cfg.get("Server", "hostname", "nitter.net"),
  22. # Cache
  23. listCacheTime: cfg.get("Cache", "listMinutes", 120),
  24. rssCacheTime: cfg.get("Cache", "rssMinutes", 10),
  25. redisHost: cfg.get("Cache", "redisHost", "localhost"),
  26. redisPort: cfg.get("Cache", "redisPort", 6379),
  27. redisConns: cfg.get("Cache", "redisConnections", 20),
  28. redisMaxConns: cfg.get("Cache", "redisMaxConnections", 30),
  29. redisPassword: cfg.get("Cache", "redisPassword", ""),
  30. # Config
  31. hmacKey: cfg.get("Config", "hmacKey", "secretkey"),
  32. base64Media: cfg.get("Config", "base64Media", false),
  33. minTokens: cfg.get("Config", "tokenCount", 10),
  34. enableRSSUserTweets: masterRss and cfg.get("Config", "enableRSSUserTweets", true),
  35. enableRSSUserReplies: masterRss and cfg.get("Config", "enableRSSUserReplies", true),
  36. enableRSSUserMedia: masterRss and cfg.get("Config", "enableRSSUserMedia", true),
  37. enableRSSSearch: masterRss and cfg.get("Config", "enableRSSSearch", true),
  38. enableRSSList: masterRss and cfg.get("Config", "enableRSSList", true),
  39. enableDebug: cfg.get("Config", "enableDebug", false),
  40. proxy: cfg.get("Config", "proxy", ""),
  41. proxyAuth: cfg.get("Config", "proxyAuth", ""),
  42. apiProxy: cfg.get("Config", "apiProxy", ""),
  43. disableTid: cfg.get("Config", "disableTid", false),
  44. maxConcurrentReqs: cfg.get("Config", "maxConcurrentReqs", 2)
  45. )
  46. return (conf, cfg)