2021-12-27 10:37:38 +09:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
2019-07-31 11:23:16 +09:00
|
|
|
import parsecfg except Config
|
2020-05-08 09:48:47 +09:00
|
|
|
import types, strutils
|
2019-07-31 11:23:16 +09:00
|
|
|
|
2021-12-30 09:55:55 +09:00
|
|
|
proc get*[T](config: parseCfg.Config; section, key: string; default: T): T =
|
|
|
|
let val = config.getSectionValue(section, key)
|
2019-07-31 11:23:16 +09:00
|
|
|
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 09:48:47 +09:00
|
|
|
proc getConfig*(path: string): (Config, parseCfg.Config) =
|
2019-07-31 11:23:16 +09:00
|
|
|
var cfg = loadConfig(path)
|
|
|
|
|
2020-05-08 09:48:47 +09:00
|
|
|
let conf = Config(
|
2019-07-31 11:23:16 +09:00
|
|
|
address: cfg.get("Server", "address", "0.0.0.0"),
|
|
|
|
port: cfg.get("Server", "port", 8080),
|
2019-08-19 10:02:34 +09:00
|
|
|
useHttps: cfg.get("Server", "https", true),
|
2021-06-24 06:17:16 +09:00
|
|
|
httpMaxConns: cfg.get("Server", "httpMaxConnections", 100),
|
|
|
|
|
2021-12-31 03:32:18 +09:00
|
|
|
title: cfg.get("Server", "title", "076ツイッター"),
|
|
|
|
hostname: cfg.get("Server", "hostname", "twitter.076.ne.jp"),
|
2020-06-01 09:26:04 +09:00
|
|
|
staticDir: cfg.get("Server", "staticDir", "./public"),
|
2019-07-31 11:23:16 +09:00
|
|
|
|
2020-06-09 22:04:38 +09:00
|
|
|
hmacKey: cfg.get("Config", "hmacKey", "secretkey"),
|
|
|
|
base64Media: cfg.get("Config", "base64Media", false),
|
|
|
|
minTokens: cfg.get("Config", "tokenCount", 10),
|
2021-12-28 14:21:22 +09:00
|
|
|
enableRss: cfg.get("Config", "enableRSS", true),
|
2021-10-01 01:03:07 +09:00
|
|
|
proxy: cfg.get("Config", "proxy", ""),
|
|
|
|
proxyAuth: cfg.get("Config", "proxyAuth", ""),
|
2020-06-09 22:04:38 +09:00
|
|
|
|
2020-06-01 09:26:04 +09: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),
|
2021-07-18 09:20:17 +09:00
|
|
|
redisMaxConns: cfg.get("Cache", "redisMaxConnections", 30),
|
2021-08-07 07:53:16 +09:00
|
|
|
redisPassword: cfg.get("Cache", "redisPassword", ""),
|
2021-07-18 09:20:17 +09:00
|
|
|
|
2021-11-04 15:16:57 +09:00
|
|
|
replaceYouTube: cfg.get("Preferences", "replaceYouTube", "youtube.076.ne.jp"),
|
|
|
|
replaceOdysee: cfg.get("Preferences", "replaceOdysee", "odysee.076.ne.jp")
|
2019-07-31 11:23:16 +09:00
|
|
|
)
|
2020-05-08 09:48:47 +09:00
|
|
|
|
|
|
|
return (conf, cfg)
|