2021-12-27 01:37:38 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
2019-12-30 10:41:09 +00:00
|
|
|
import strutils
|
|
|
|
|
|
|
|
import jester
|
|
|
|
|
|
|
|
import router_utils
|
2021-12-20 02:11:12 +00:00
|
|
|
import ".."/[types, api]
|
2019-12-30 10:41:09 +00:00
|
|
|
import ../views/general
|
|
|
|
|
|
|
|
template respResolved*(url, kind: string): untyped =
|
2020-05-02 17:23:47 +00:00
|
|
|
let u = url
|
|
|
|
if u.len == 0:
|
2019-12-30 10:41:09 +00:00
|
|
|
resp showError("Invalid $1 link" % kind, cfg)
|
|
|
|
else:
|
2020-05-02 17:23:47 +00:00
|
|
|
redirect(u)
|
2019-12-30 10:41:09 +00:00
|
|
|
|
|
|
|
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")
|