fixed token issue that broke all pages besides the favorites / likes timeline

This commit is contained in:
PrivacyDev 2023-04-05 01:14:30 -04:00
parent 7d2a558e89
commit a6dd229444
2 changed files with 12 additions and 8 deletions

View file

@ -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.} =

View file

@ -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)