mirror of
https://github.com/zedeus/nitter.git
synced 2024-12-14 20:16:31 +00:00
fixed token issue that broke all pages besides the favorites / likes timeline
This commit is contained in:
parent
7d2a558e89
commit
a6dd229444
2 changed files with 12 additions and 8 deletions
|
@ -70,9 +70,10 @@ proc getFavorites*(id: string; cfg: Config; after=""): Future[Timeline] {.async.
|
||||||
let
|
let
|
||||||
ps = genParams({"userId": id}, after)
|
ps = genParams({"userId": id}, after)
|
||||||
url = consts.favorites / (id & ".json") ? ps
|
url = consts.favorites / (id & ".json") ? ps
|
||||||
headers = genHeaders()
|
headers = newHttpHeaders({
|
||||||
headers.add("Cookie", cfg.cookieHeader)
|
"Cookie": cfg.cookieHeader,
|
||||||
headers.add("x-csrf-token", cfg.xCsrfToken)
|
"x-csrf-token": cfg.xCsrfToken
|
||||||
|
})
|
||||||
result = parseTimeline(await fetch(url, Api.favorites, headers), after)
|
result = parseTimeline(await fetch(url, Api.favorites, headers), after)
|
||||||
|
|
||||||
proc getMediaTimeline*(id: string; after=""): Future[Timeline] {.async.} =
|
proc getMediaTimeline*(id: string; after=""): Future[Timeline] {.async.} =
|
||||||
|
|
|
@ -50,7 +50,7 @@ template updateToken() =
|
||||||
reset = parseInt(resp.headers[rlReset])
|
reset = parseInt(resp.headers[rlReset])
|
||||||
token.setRateLimit(api, remaining, reset)
|
token.setRateLimit(api, remaining, reset)
|
||||||
|
|
||||||
template fetchImpl(result, headers, fetchBody) {.dirty.} =
|
template fetchImpl(result, additional_headers, fetchBody) {.dirty.} =
|
||||||
once:
|
once:
|
||||||
pool = HttpPool()
|
pool = HttpPool()
|
||||||
|
|
||||||
|
@ -60,6 +60,9 @@ template fetchImpl(result, headers, fetchBody) {.dirty.} =
|
||||||
|
|
||||||
try:
|
try:
|
||||||
var resp: AsyncResponse
|
var resp: AsyncResponse
|
||||||
|
var headers = genHeaders(token)
|
||||||
|
for key, value in additional_headers.pairs():
|
||||||
|
headers.add(key, value)
|
||||||
pool.use(headers):
|
pool.use(headers):
|
||||||
template getContent =
|
template getContent =
|
||||||
resp = await c.get($url)
|
resp = await c.get($url)
|
||||||
|
@ -96,9 +99,9 @@ template fetchImpl(result, headers, fetchBody) {.dirty.} =
|
||||||
release(token, invalid=true)
|
release(token, invalid=true)
|
||||||
raise rateLimitError()
|
raise rateLimitError()
|
||||||
|
|
||||||
proc fetch*(url: Uri; api: Api; headers: HttpHeaders = genHeaders()): Future[JsonNode] {.async.} =
|
proc fetch*(url: Uri; api: Api; additional_headers: HttpHeaders = newHttpHeaders()): Future[JsonNode] {.async.} =
|
||||||
var body: string
|
var body: string
|
||||||
fetchImpl(body, headers):
|
fetchImpl(body, additional_headers):
|
||||||
if body.startsWith('{') or body.startsWith('['):
|
if body.startsWith('{') or body.startsWith('['):
|
||||||
result = parseJson(body)
|
result = parseJson(body)
|
||||||
else:
|
else:
|
||||||
|
@ -113,8 +116,8 @@ proc fetch*(url: Uri; api: Api; headers: HttpHeaders = genHeaders()): Future[Jso
|
||||||
release(token, invalid=true)
|
release(token, invalid=true)
|
||||||
raise rateLimitError()
|
raise rateLimitError()
|
||||||
|
|
||||||
proc fetchRaw*(url: Uri; api: Api; headers: HttpHeaders = genHeaders()): Future[string] {.async.} =
|
proc fetchRaw*(url: Uri; api: Api; additional_headers: HttpHeaders = newHttpHeaders()): Future[string] {.async.} =
|
||||||
fetchImpl(result, headers):
|
fetchImpl(result, additional_headers):
|
||||||
if not (result.startsWith('{') or result.startsWith('[')):
|
if not (result.startsWith('{') or result.startsWith('[')):
|
||||||
echo resp.status, ": ", result, " --- url: ", url
|
echo resp.status, ": ", result, " --- url: ", url
|
||||||
result.setLen(0)
|
result.setLen(0)
|
||||||
|
|
Loading…
Reference in a new issue