mirror of
https://github.com/zedeus/nitter.git
synced 2026-04-16 02:32:14 -04:00
@@ -34,6 +34,8 @@ proxyAuth = ""
|
|||||||
apiProxy = "" # nitter-proxy host, e.g. localhost:7000
|
apiProxy = "" # nitter-proxy host, e.g. localhost:7000
|
||||||
disableTid = false # enable this if cookie-based auth is failing
|
disableTid = false # enable this if cookie-based auth is failing
|
||||||
maxConcurrentReqs = 2 # max requests at a time per session to avoid race conditions
|
maxConcurrentReqs = 2 # max requests at a time per session to avoid race conditions
|
||||||
|
maxRetries = 1 # max number of retries on rate limit errors
|
||||||
|
retryDelayMs = 150 # delay in ms between retries
|
||||||
|
|
||||||
# Change default preferences here, see src/prefs_impl.nim for a complete list
|
# Change default preferences here, see src/prefs_impl.nim for a complete list
|
||||||
[Preferences]
|
[Preferences]
|
||||||
|
|||||||
@@ -14,10 +14,18 @@ var
|
|||||||
pool: HttpPool
|
pool: HttpPool
|
||||||
disableTid: bool
|
disableTid: bool
|
||||||
apiProxy: string
|
apiProxy: string
|
||||||
|
maxRetries: int
|
||||||
|
retryDelayMs: int
|
||||||
|
|
||||||
proc setDisableTid*(disable: bool) =
|
proc setDisableTid*(disable: bool) =
|
||||||
disableTid = disable
|
disableTid = disable
|
||||||
|
|
||||||
|
proc setMaxRetries*(n: int) =
|
||||||
|
maxRetries = n
|
||||||
|
|
||||||
|
proc setRetryDelayMs*(ms: int) =
|
||||||
|
retryDelayMs = ms
|
||||||
|
|
||||||
proc setApiProxy*(url: string) =
|
proc setApiProxy*(url: string) =
|
||||||
apiProxy = ""
|
apiProxy = ""
|
||||||
if url.len > 0:
|
if url.len > 0:
|
||||||
@@ -120,6 +128,10 @@ template fetchImpl(result, fetchBody) {.dirty.} =
|
|||||||
badClient = true
|
badClient = true
|
||||||
raise newException(BadClientError, "Bad client")
|
raise newException(BadClientError, "Bad client")
|
||||||
|
|
||||||
|
if resp.status == $Http404 and result.len == 0:
|
||||||
|
echo "[sessions] transient 404 (empty body), retrying: ", url.path
|
||||||
|
raise rateLimitError()
|
||||||
|
|
||||||
if resp.headers.hasKey(rlRemaining):
|
if resp.headers.hasKey(rlRemaining):
|
||||||
let
|
let
|
||||||
remaining = parseInt(resp.headers[rlRemaining])
|
remaining = parseInt(resp.headers[rlRemaining])
|
||||||
@@ -165,11 +177,15 @@ template fetchImpl(result, fetchBody) {.dirty.} =
|
|||||||
release(session)
|
release(session)
|
||||||
|
|
||||||
template retry(bod) =
|
template retry(bod) =
|
||||||
try:
|
for i in 0 ..< maxRetries:
|
||||||
bod
|
try:
|
||||||
except RateLimitError:
|
bod
|
||||||
echo "[sessions] Rate limited, retrying ", req.cookie.endpoint, " request..."
|
break
|
||||||
bod
|
except RateLimitError:
|
||||||
|
echo "[sessions] Rate limited, retrying ", req.cookie.endpoint,
|
||||||
|
" request (", i, "/", maxRetries, ")..."
|
||||||
|
if retryDelayMs > 0:
|
||||||
|
await sleepAsync(retryDelayMs)
|
||||||
|
|
||||||
proc fetch*(req: ApiReq): Future[JsonNode] {.async.} =
|
proc fetch*(req: ApiReq): Future[JsonNode] {.async.} =
|
||||||
retry:
|
retry:
|
||||||
|
|||||||
@@ -49,7 +49,9 @@ proc getConfig*(path: string): (Config, parseCfg.Config) =
|
|||||||
proxyAuth: cfg.get("Config", "proxyAuth", ""),
|
proxyAuth: cfg.get("Config", "proxyAuth", ""),
|
||||||
apiProxy: cfg.get("Config", "apiProxy", ""),
|
apiProxy: cfg.get("Config", "apiProxy", ""),
|
||||||
disableTid: cfg.get("Config", "disableTid", false),
|
disableTid: cfg.get("Config", "disableTid", false),
|
||||||
maxConcurrentReqs: cfg.get("Config", "maxConcurrentReqs", 2)
|
maxConcurrentReqs: cfg.get("Config", "maxConcurrentReqs", 2),
|
||||||
|
maxRetries: cfg.get("Config", "maxRetries", 1),
|
||||||
|
retryDelayMs: cfg.get("Config", "retryDelayMs", 150)
|
||||||
)
|
)
|
||||||
|
|
||||||
return (conf, cfg)
|
return (conf, cfg)
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ setHttpProxy(cfg.proxy, cfg.proxyAuth)
|
|||||||
setApiProxy(cfg.apiProxy)
|
setApiProxy(cfg.apiProxy)
|
||||||
setDisableTid(cfg.disableTid)
|
setDisableTid(cfg.disableTid)
|
||||||
setMaxConcurrentReqs(cfg.maxConcurrentReqs)
|
setMaxConcurrentReqs(cfg.maxConcurrentReqs)
|
||||||
|
setMaxRetries(cfg.maxRetries)
|
||||||
|
setRetryDelayMs(cfg.retryDelayMs)
|
||||||
initAboutPage(cfg.staticDir)
|
initAboutPage(cfg.staticDir)
|
||||||
|
|
||||||
waitFor initRedisPool(cfg)
|
waitFor initRedisPool(cfg)
|
||||||
|
|||||||
@@ -310,6 +310,8 @@ type
|
|||||||
apiProxy*: string
|
apiProxy*: string
|
||||||
disableTid*: bool
|
disableTid*: bool
|
||||||
maxConcurrentReqs*: int
|
maxConcurrentReqs*: int
|
||||||
|
maxRetries*: int
|
||||||
|
retryDelayMs*: int
|
||||||
|
|
||||||
rssCacheTime*: int
|
rssCacheTime*: int
|
||||||
listCacheTime*: int
|
listCacheTime*: int
|
||||||
|
|||||||
Reference in New Issue
Block a user