2021-12-27 01:37:38 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
2020-06-09 14:45:21 +00:00
|
|
|
import strutils, sequtils, uri, tables
|
|
|
|
from jester import Request, cookies
|
|
|
|
|
|
|
|
import ../views/general
|
|
|
|
import ".."/[utils, prefs, types]
|
|
|
|
export utils, prefs, types
|
2019-09-20 13:03:18 +00:00
|
|
|
|
2020-06-01 00:22:56 +00:00
|
|
|
template savePref*(pref, value: string; req: Request; expire=false) =
|
2020-05-08 00:48:47 +00:00
|
|
|
if not expire or pref in cookies(req):
|
|
|
|
setCookie(pref, value, daysForward(when expire: -10 else: 360),
|
|
|
|
httpOnly=true, secure=cfg.useHttps)
|
|
|
|
|
2019-09-06 00:42:35 +00:00
|
|
|
template cookiePrefs*(): untyped {.dirty.} =
|
2020-05-08 00:48:47 +00:00
|
|
|
getPrefs(cookies(request))
|
2019-09-06 00:42:35 +00:00
|
|
|
|
2020-06-09 14:45:21 +00:00
|
|
|
template cookiePref*(pref): untyped {.dirty.} =
|
|
|
|
getPref(cookies(request), pref)
|
|
|
|
|
|
|
|
template themePrefs*(): Prefs =
|
|
|
|
var res = defaultPrefs
|
|
|
|
res.theme = cookiePref(theme)
|
|
|
|
res
|
|
|
|
|
|
|
|
template showError*(error: string; cfg: Config): string =
|
|
|
|
renderMain(renderError(error), request, cfg, themePrefs(), "Error")
|
|
|
|
|
2019-09-06 00:42:35 +00:00
|
|
|
template getPath*(): untyped {.dirty.} =
|
|
|
|
$(parseUri(request.path) ? filterParams(request.params))
|
|
|
|
|
|
|
|
template refPath*(): untyped {.dirty.} =
|
|
|
|
if @"referer".len > 0: @"referer" else: "/"
|
2019-12-04 04:58:18 +00:00
|
|
|
|
2020-06-01 00:22:56 +00:00
|
|
|
template getCursor*(): string =
|
|
|
|
let cursor = @"cursor"
|
|
|
|
decodeUrl(if cursor.len > 0: cursor else: @"max_position", false)
|
|
|
|
|
|
|
|
template getCursor*(req: Request): string =
|
|
|
|
let cursor = req.params.getOrDefault("cursor")
|
|
|
|
decodeUrl(if cursor.len > 0: cursor
|
|
|
|
else: req.params.getOrDefault("max_position"), false)
|
|
|
|
|
2019-12-04 04:58:18 +00:00
|
|
|
proc getNames*(name: string): seq[string] =
|
|
|
|
name.strip(chars={'/'}).split(",").filterIt(it.len > 0)
|