nitter/src/routes/router_utils.nim

28 lines
795 B
Nim
Raw Normal View History

import strutils, sequtils, asyncdispatch, httpclient
2019-09-21 00:08:30 +01:00
import ../utils, ../prefs
export utils, prefs
2019-09-20 14:03:18 +01:00
from net import SslError
2019-09-06 01:42:35 +01:00
template cookiePrefs*(): untyped {.dirty.} =
2019-10-23 13:06:47 +01:00
getPrefs(request.cookies.getOrDefault("preferences"), cfg)
2019-09-06 01:42:35 +01: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
proc getNames*(name: string): seq[string] =
name.strip(chars={'/'}).split(",").filterIt(it.len > 0)
proc safeClose*(client: AsyncHttpClient) =
try: client.close()
except SslError: discard
proc safeFetch*(url: string): Future[string] {.async.} =
let client = newAsyncHttpClient()
try: result = await client.getContent(url)
except: discard
client.safeClose()