config.nim 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import parsecfg except Config
  2. import types, strutils
  3. proc get*[T](config: parseCfg.Config; s, v: string; default: T): T =
  4. let val = config.getSectionValue(s, v)
  5. if val.len == 0: return default
  6. when T is int: parseInt(val)
  7. elif T is bool: parseBool(val)
  8. elif T is string: val
  9. proc getConfig*(path: string): (Config, parseCfg.Config) =
  10. var cfg = loadConfig(path)
  11. let conf = Config(
  12. address: cfg.get("Server", "address", "0.0.0.0"),
  13. port: cfg.get("Server", "port", 8080),
  14. useHttps: cfg.get("Server", "https", true),
  15. httpMaxConns: cfg.get("Server", "httpMaxConnections", 100),
  16. title: cfg.get("Server", "title", "Nitter"),
  17. hostname: cfg.get("Server", "hostname", "nitter.net"),
  18. staticDir: cfg.get("Server", "staticDir", "./public"),
  19. hmacKey: cfg.get("Config", "hmacKey", "secretkey"),
  20. base64Media: cfg.get("Config", "base64Media", false),
  21. minTokens: cfg.get("Config", "tokenCount", 10),
  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. replaceYouTube: cfg.get("Preferences", "replaceYouTube", "piped.kavin.rocks")
  30. )
  31. return (conf, cfg)