1
0
mirror of https://github.com/zedeus/nitter.git synced 2026-01-28 14:22:48 -05:00

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

13
src/api/resolver.nim Normal file
View File

@@ -0,0 +1,13 @@
import asyncdispatch, httpclient
import ".."/[formatters, types]
proc resolve*(url: string; prefs: Prefs): Future[string] {.async.} =
let client = newAsyncHttpClient(maxRedirects=0)
try:
let resp = await client.request(url, $HttpHead)
result = resp.headers["location"].replaceUrl(prefs)
except:
discard
finally:
client.close()