Merge remote-tracking branch 'upstream/guest_accounts'
This commit is contained in:
commit
e4e7fe5f00
3 changed files with 32 additions and 19 deletions
|
@ -134,11 +134,19 @@ template fetchImpl(result, additional_headers, fetchBody) {.dirty.} =
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
raise e
|
raise e
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
echo "error: ", e.name, ", msg: ", e.msg, ", accountId: ", account.id, ", url: ", url
|
let id = if account.isNil: "null" else: account.id
|
||||||
|
echo "error: ", e.name, ", msg: ", e.msg, ", accountId: ", id, ", url: ", url
|
||||||
raise rateLimitError()
|
raise rateLimitError()
|
||||||
finally:
|
finally:
|
||||||
release(account)
|
release(account)
|
||||||
|
|
||||||
|
template retry(bod) =
|
||||||
|
try:
|
||||||
|
bod
|
||||||
|
except RateLimitError:
|
||||||
|
echo "[accounts] Rate limited, retrying ", api, " request..."
|
||||||
|
bod
|
||||||
|
|
||||||
proc fetch*(url: Uri; api: Api; additional_headers: HttpHeaders = newHttpHeaders()): Future[JsonNode] {.async.} =
|
proc fetch*(url: Uri; api: Api; additional_headers: HttpHeaders = newHttpHeaders()): Future[JsonNode] {.async.} =
|
||||||
|
|
||||||
if len(cfg.cookieHeader) != 0:
|
if len(cfg.cookieHeader) != 0:
|
||||||
|
@ -146,6 +154,7 @@ proc fetch*(url: Uri; api: Api; additional_headers: HttpHeaders = newHttpHeaders
|
||||||
if len(cfg.xCsrfToken) != 0:
|
if len(cfg.xCsrfToken) != 0:
|
||||||
additional_headers.add("x-csrf-token", cfg.xCsrfToken)
|
additional_headers.add("x-csrf-token", cfg.xCsrfToken)
|
||||||
|
|
||||||
|
retry:
|
||||||
var body: string
|
var body: string
|
||||||
fetchImpl(body, additional_headers):
|
fetchImpl(body, additional_headers):
|
||||||
if body.startsWith('{') or body.startsWith('['):
|
if body.startsWith('{') or body.startsWith('['):
|
||||||
|
@ -161,6 +170,7 @@ proc fetch*(url: Uri; api: Api; additional_headers: HttpHeaders = newHttpHeaders
|
||||||
raise rateLimitError()
|
raise rateLimitError()
|
||||||
|
|
||||||
proc fetchRaw*(url: Uri; api: Api; additional_headers: HttpHeaders = newHttpHeaders()): Future[string] {.async.} =
|
proc fetchRaw*(url: Uri; api: Api; additional_headers: HttpHeaders = newHttpHeaders()): Future[string] {.async.} =
|
||||||
|
retry:
|
||||||
fetchImpl(result, additional_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
|
||||||
|
|
|
@ -443,6 +443,9 @@ proc parseGraphTweet(js: JsonNode; isLegacy=false): Tweet =
|
||||||
of "TweetWithVisibilityResults":
|
of "TweetWithVisibilityResults":
|
||||||
return parseGraphTweet(js{"tweet"}, isLegacy)
|
return parseGraphTweet(js{"tweet"}, isLegacy)
|
||||||
|
|
||||||
|
if not js.hasKey("legacy"):
|
||||||
|
return Tweet()
|
||||||
|
|
||||||
var jsCard = copy(js{if isLegacy: "card" else: "tweet_card", "legacy"})
|
var jsCard = copy(js{if isLegacy: "card" else: "tweet_card", "legacy"})
|
||||||
if jsCard.kind != JNull:
|
if jsCard.kind != JNull:
|
||||||
var values = newJObject()
|
var values = newJObject()
|
||||||
|
|
|
@ -37,7 +37,7 @@ proc proxyMedia*(req: jester.Request; url: string): Future[HttpCode] {.async.} =
|
||||||
try:
|
try:
|
||||||
let res = await client.get(url)
|
let res = await client.get(url)
|
||||||
if res.status != "200 OK":
|
if res.status != "200 OK":
|
||||||
echo "[media] Proxying media failed, status: $1, url: $2, body: $3" % [res.status, url, await res.body]
|
echo "[media] Proxying failed, status: $1, url: $2" % [res.status, url]
|
||||||
return Http404
|
return Http404
|
||||||
|
|
||||||
let hashed = $hash(url)
|
let hashed = $hash(url)
|
||||||
|
@ -66,7 +66,7 @@ proc proxyMedia*(req: jester.Request; url: string): Future[HttpCode] {.async.} =
|
||||||
await request.client.send(data)
|
await request.client.send(data)
|
||||||
data.setLen 0
|
data.setLen 0
|
||||||
except HttpRequestError, ProtocolError, OSError:
|
except HttpRequestError, ProtocolError, OSError:
|
||||||
echo "[media] Proxying media exception, error: $1, url: $2" % [getCurrentExceptionMsg(), url]
|
echo "[media] Proxying exception, error: $1, url: $2" % [getCurrentExceptionMsg(), url]
|
||||||
result = Http404
|
result = Http404
|
||||||
finally:
|
finally:
|
||||||
client.close()
|
client.close()
|
||||||
|
|
Loading…
Reference in a new issue