nitter/src/routes/preferences.nim

46 lines
1.2 KiB
Nim
Raw Normal View History

2019-10-23 12:32:37 +02:00
import strutils, uri, os, algorithm
2019-09-06 02:42:35 +02:00
import jester
import router_utils
2019-09-21 01:08:30 +02:00
import ".."/[types]
2019-09-06 02:42:35 +02:00
import ../views/[general, preferences]
export preferences
2019-10-23 11:48:08 +02:00
proc findThemes*(dir: string): seq[string] =
for kind, path in walkDir(dir / "css" / "themes"):
result.add path.splitFile.name.capitalizeAscii
2019-10-23 12:46:52 +02:00
sort(result)
2019-10-23 11:48:08 +02:00
2019-09-06 02:42:35 +02:00
proc createPrefRouter*(cfg: Config) =
router preferences:
template savePrefs(): untyped =
setCookie("preferences", $prefs.id, daysForward(360), httpOnly=true, secure=cfg.useHttps)
get "/settings":
2019-10-23 11:48:08 +02:00
let html = renderPreferences(cookiePrefs(), refPath(), findThemes(cfg.staticDir))
resp renderMain(html, request, cfg, "Preferences")
2019-09-06 02:42:35 +02:00
get "/settings/@i?":
redirect("/settings")
2019-09-06 02:42:35 +02:00
post "/saveprefs":
var prefs = cookiePrefs()
genUpdatePrefs()
savePrefs()
redirect(refPath())
post "/resetprefs":
var prefs = cookiePrefs()
resetPrefs(prefs, cfg.hostname)
2019-09-06 02:42:35 +02:00
savePrefs()
redirect($(parseUri("/settings") ? filterParams(request.params)))
post "/enablehls":
var prefs = cookiePrefs()
prefs.hlsPlayback = true
cache(prefs)
savePrefs()
redirect(refPath())