nitter/src/routes/router_utils.nim

28 lines
795 B
Nim
Raw Normal View History

import strutils, sequtils, asyncdispatch, httpclient
2019-09-21 01:08:30 +02:00
import ../utils, ../prefs
export utils, prefs
2019-09-20 15:03:18 +02:00
from net import SslError
2019-09-06 02:42:35 +02:00
template cookiePrefs*(): untyped {.dirty.} =
2019-10-23 14:06:47 +02:00
getPrefs(request.cookies.getOrDefault("preferences"), cfg)
2019-09-06 02:42:35 +02:00
template getPath*(): untyped {.dirty.} =
$(parseUri(request.path) ? filterParams(request.params))
template refPath*(): untyped {.dirty.} =
if @"referer".len > 0: @"referer" else: "/"
2019-12-04 05:58:18 +01: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()