nitter/src/routes/resolver.nim

26 lines
654 B
Nim
Raw Normal View History

2021-12-27 02:37:38 +01:00
# SPDX-License-Identifier: AGPL-3.0-only
import strutils
import jester
import router_utils
2021-12-20 03:11:12 +01:00
import ".."/[types, api]
import ../views/general
template respResolved*(url, kind: string): untyped =
let u = url
if u.len == 0:
resp showError("Invalid $1 link" % kind, cfg)
else:
redirect(u)
proc createResolverRouter*(cfg: Config) =
router resolver:
get "/cards/@card/@id":
let url = "https://cards.twitter.com/cards/$1/$2" % [@"card", @"id"]
respResolved(await resolve(url, cookiePrefs()), "card")
get "/t.co/@url":
let url = "https://t.co/" & @"url"
respResolved(await resolve(url, cookiePrefs()), "t.co")