mirror of
https://github.com/zedeus/nitter.git
synced 2024-12-14 12:06:29 +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
|
||||
ps = genParams({"userId": id}, after)
|
||||
url = consts.favorites / (id & ".json") ? ps
|
||||
headers = genHeaders()
|
||||
headers.add("Cookie", cfg.cookieHeader)
|
||||
headers.add("x-csrf-token", cfg.xCsrfToken)
|
||||
headers = newHttpHeaders({
|
||||
"Cookie": cfg.cookieHeader,
|
||||
"x-csrf-token": cfg.xCsrfToken
|
||||
})
|
||||
result = parseTimeline(await fetch(url, Api.favorites, headers), after)
|
||||
|
||||
proc getMediaTimeline*(id: string; after=""): Future[Timeline] {.async.} =
|
||||
|
|
|
@ -50,7 +50,7 @@ template updateToken() =
|
|||
reset = parseInt(resp.headers[rlReset])
|
||||
token.setRateLimit(api, remaining, reset)
|
||||
|
||||
template fetchImpl(result, headers, fetchBody) {.dirty.} =
|
||||
template fetchImpl(result, additional_headers, fetchBody) {.dirty.} =
|
||||
once:
|
||||
pool = HttpPool()
|
||||
|
||||
|
@ -60,6 +60,9 @@ template fetchImpl(result, headers, fetchBody) {.dirty.} =
|
|||
|
||||
try:
|
||||
var resp: AsyncResponse
|
||||
var headers = genHeaders(token)
|
||||
for key, value in additional_headers.pairs():
|
||||
headers.add(key, value)
|
||||
pool.use(headers):
|
||||
template getContent =
|
||||
resp = await c.get($url)
|
||||
|
@ -96,9 +99,9 @@ template fetchImpl(result, headers, fetchBody) {.dirty.} =
|
|||
release(token, invalid=true)
|
||||
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
|
||||
fetchImpl(body, headers):
|
||||
fetchImpl(body, additional_headers):
|
||||
if body.startsWith('{') or body.startsWith('['):
|
||||
result = parseJson(body)
|
||||
else:
|
||||
|
@ -113,8 +116,8 @@ proc fetch*(url: Uri; api: Api; headers: HttpHeaders = genHeaders()): Future[Jso
|
|||
release(token, invalid=true)
|
||||
raise rateLimitError()
|
||||
|
||||
proc fetchRaw*(url: Uri; api: Api; headers: HttpHeaders = genHeaders()): Future[string] {.async.} =
|
||||
fetchImpl(result, headers):
|
||||
proc fetchRaw*(url: Uri; api: Api; additional_headers: HttpHeaders = newHttpHeaders()): Future[string] {.async.} =
|
||||
fetchImpl(result, additional_headers):
|
||||
if not (result.startsWith('{') or result.startsWith('[')):
|
||||
echo resp.status, ": ", result, " --- url: ", url
|
||||
result.setLen(0)
|
||||
|
|
Loading…
Reference in a new issue