mirror of
https://github.com/zedeus/nitter
synced 2026-09-05 22:59:31 +00:00
Refactor routing code
This commit is contained in:
parent
7bdf5b0f76
commit
014f01bf88
7 changed files with 253 additions and 203 deletions
38
src/routes/preferences.nim
Normal file
38
src/routes/preferences.nim
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import strutils, uri
|
||||
|
||||
import jester
|
||||
|
||||
import router_utils
|
||||
import ".."/[prefs, types, utils]
|
||||
import ../views/[general, preferences]
|
||||
|
||||
export preferences
|
||||
|
||||
proc createPrefRouter*(cfg: Config) =
|
||||
router preferences:
|
||||
template savePrefs(): untyped =
|
||||
setCookie("preferences", $prefs.id, daysForward(360), httpOnly=true, secure=cfg.useHttps)
|
||||
|
||||
get "/settings":
|
||||
let prefs = cookiePrefs()
|
||||
let path = refPath()
|
||||
resp renderMain(renderPreferences(prefs, path), prefs, cfg.title, "Preferences", path)
|
||||
|
||||
post "/saveprefs":
|
||||
var prefs = cookiePrefs()
|
||||
genUpdatePrefs()
|
||||
savePrefs()
|
||||
redirect(refPath())
|
||||
|
||||
post "/resetprefs":
|
||||
var prefs = cookiePrefs()
|
||||
resetPrefs(prefs)
|
||||
savePrefs()
|
||||
redirect($(parseUri("/settings") ? filterParams(request.params)))
|
||||
|
||||
post "/enablehls":
|
||||
var prefs = cookiePrefs()
|
||||
prefs.hlsPlayback = true
|
||||
cache(prefs)
|
||||
savePrefs()
|
||||
redirect(refPath())
|
||||
Loading…
Reference in a new issue