2021-12-27 01:37:38 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
2022-01-10 15:18:10 +00:00
|
|
|
import strutils, uri, os, algorithm
|
2019-09-06 00:42:35 +00:00
|
|
|
|
|
|
|
import jester
|
|
|
|
|
|
|
|
import router_utils
|
2022-01-10 15:18:10 +00:00
|
|
|
import ".."/[types, formatters]
|
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
|
2022-01-09 22:58:21 +00:00
|
|
|
result.add theme.replace("_", " ").titleize
|
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:
|
|
|
|
get "/settings":
|
2020-06-09 14:45:21 +00:00
|
|
|
let
|
|
|
|
prefs = cookiePrefs()
|
|
|
|
html = renderPreferences(prefs, refPath(), findThemes(cfg.staticDir))
|
|
|
|
resp renderMain(html, request, cfg, prefs, "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":
|
|
|
|
genUpdatePrefs()
|
|
|
|
redirect(refPath())
|
|
|
|
|
|
|
|
post "/resetprefs":
|
2020-05-08 00:48:47 +00:00
|
|
|
genResetPrefs()
|
2022-01-03 01:12:51 +00:00
|
|
|
redirect("/settings?referer=" & encodeUrl(refPath()))
|
2019-09-06 00:42:35 +00:00
|
|
|
|
|
|
|
post "/enablehls":
|
2020-05-08 00:48:47 +00:00
|
|
|
savePref("hlsPlayback", "on", request)
|
2019-09-06 00:42:35 +00:00
|
|
|
redirect(refPath())
|
2019-12-06 07:21:37 +00:00
|
|
|
|