2019-10-23 10:32:37 +00:00
|
|
|
import strutils, uri, os, algorithm
|
2019-09-06 00:42:35 +00:00
|
|
|
|
|
|
|
import jester
|
|
|
|
|
|
|
|
import router_utils
|
2019-09-20 23:08:30 +00:00
|
|
|
import ".."/[types]
|
2019-09-06 00:42:35 +00:00
|
|
|
import ../views/[general, preferences]
|
|
|
|
|
|
|
|
export preferences
|
|
|
|
|
2019-10-23 09:48:08 +00:00
|
|
|
proc findThemes*(dir: string): seq[string] =
|
|
|
|
for kind, path in walkDir(dir / "css" / "themes"):
|
2019-10-27 10:24:09 +00:00
|
|
|
let theme = path.splitFile.name
|
|
|
|
result.add theme.capitalizeAscii.replace("_", " ")
|
2019-10-23 10:46:52 +00:00
|
|
|
sort(result)
|
2019-10-23 09:48:08 +00:00
|
|
|
|
2019-09-06 00:42:35 +00: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 09:48:08 +00:00
|
|
|
let html = renderPreferences(cookiePrefs(), refPath(), findThemes(cfg.staticDir))
|
2019-10-21 03:19:00 +00:00
|
|
|
resp renderMain(html, request, cfg, "Preferences")
|
2019-09-06 00:42:35 +00:00
|
|
|
|
2019-10-08 18:49:31 +00:00
|
|
|
get "/settings/@i?":
|
|
|
|
redirect("/settings")
|
|
|
|
|
2019-09-06 00:42:35 +00:00
|
|
|
post "/saveprefs":
|
|
|
|
var prefs = cookiePrefs()
|
|
|
|
genUpdatePrefs()
|
|
|
|
savePrefs()
|
|
|
|
redirect(refPath())
|
|
|
|
|
|
|
|
post "/resetprefs":
|
|
|
|
var prefs = cookiePrefs()
|
2019-10-23 12:06:47 +00:00
|
|
|
resetPrefs(prefs, cfg)
|
2019-09-06 00:42:35 +00:00
|
|
|
savePrefs()
|
|
|
|
redirect($(parseUri("/settings") ? filterParams(request.params)))
|
|
|
|
|
|
|
|
post "/enablehls":
|
|
|
|
var prefs = cookiePrefs()
|
|
|
|
prefs.hlsPlayback = true
|
|
|
|
cache(prefs)
|
|
|
|
savePrefs()
|
|
|
|
redirect(refPath())
|