Add t.co and /cards link resolvers

For t.co links: https://t.co/.. -> nitter.net/t.co/..
For card links: https://cards.twitter.com/cards/.. -> nitter.net/cards/...
This commit is contained in:
Zed
2019-12-30 11:41:09 +01:00
parent d27ab68a90
commit 1aa1487402
5 changed files with 46 additions and 3 deletions

23
src/routes/resolver.nim Normal file
View File

@@ -0,0 +1,23 @@
import strutils
import jester
import router_utils
import ".."/[query, types, api, agents]
import ../views/general
template respResolved*(url, kind: string): untyped =
if url.len == 0:
resp showError("Invalid $1 link" % kind, cfg)
else:
redirect(url)
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")