Store preferences in cookies, add config defaults

This commit is contained in:
Zed
2020-05-08 02:48:47 +02:00
parent 517d9144f6
commit 312ff78628
9 changed files with 109 additions and 109 deletions

View File

@@ -1,7 +1,7 @@
import parsecfg except Config
import net, types, strutils
import types, strutils
proc get[T](config: parseCfg.Config; s, v: string; default: T): T =
proc get*[T](config: parseCfg.Config; s, v: string; default: T): T =
let val = config.getSectionValue(s, v)
if val.len == 0: return default
@@ -9,10 +9,10 @@ proc get[T](config: parseCfg.Config; s, v: string; default: T): T =
elif T is bool: parseBool(val)
elif T is string: val
proc getConfig*(path: string): Config =
proc getConfig*(path: string): (Config, parseCfg.Config) =
var cfg = loadConfig(path)
Config(
let conf = Config(
address: cfg.get("Server", "address", "0.0.0.0"),
port: cfg.get("Server", "port", 8080),
useHttps: cfg.get("Server", "https", true),
@@ -23,6 +23,7 @@ proc getConfig*(path: string): Config =
cacheDir: cfg.get("Cache", "directory", "/tmp/nitter"),
profileCacheTime: cfg.get("Cache", "profileMinutes", 10),
defaultTheme: cfg.get("Config", "defaultTheme", "Nitter"),
hmacKey: cfg.get("Config", "hmacKey", "secretkey")
)
return (conf, cfg)