mirror of
https://github.com/zedeus/nitter.git
synced 2025-02-13 00:55:21 +00:00
fix sleeps, better exception handling
This commit is contained in:
parent
98cc15e78c
commit
ab321c9b10
2 changed files with 19 additions and 10 deletions
11
src/auth.nim
11
src/auth.nim
|
@ -210,11 +210,17 @@ proc updateAccountPool*(cfg: Config) {.async.} =
|
||||||
if not cfg.guestAccountsUsePool:
|
if not cfg.guestAccountsUsePool:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# wait for a few seconds before fetching guest accounts, so that
|
||||||
|
# /.well-known/... is served correctly
|
||||||
|
await sleepAsync(10 * 1000)
|
||||||
|
|
||||||
while true:
|
while true:
|
||||||
if accountPool.len == 0:
|
if accountPool.len == 0:
|
||||||
let pool = HttpPool()
|
let pool = HttpPool()
|
||||||
|
|
||||||
log "fetching more accounts from service"
|
log "fetching more accounts from service"
|
||||||
|
|
||||||
|
try:
|
||||||
pool.use(newHttpHeaders()):
|
pool.use(newHttpHeaders()):
|
||||||
let resp = await c.get("$1?id=$2&auth=$3" % [cfg.guestAccountsPoolUrl, cfg.guestAccountsPoolId, cfg.guestAccountsPoolAuth])
|
let resp = await c.get("$1?id=$2&auth=$3" % [cfg.guestAccountsPoolUrl, cfg.guestAccountsPoolId, cfg.guestAccountsPoolAuth])
|
||||||
let guestAccounts = await resp.body
|
let guestAccounts = await resp.body
|
||||||
|
@ -225,9 +231,12 @@ proc updateAccountPool*(cfg: Config) {.async.} =
|
||||||
if line != "":
|
if line != "":
|
||||||
accountPool.add parseGuestAccount(line)
|
accountPool.add parseGuestAccount(line)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
log "failed to fetch from accounts service: ", e.msg
|
||||||
|
|
||||||
accountPool.keepItIf(not it.hasExpired)
|
accountPool.keepItIf(not it.hasExpired)
|
||||||
|
|
||||||
await sleepAsync(3600)
|
await sleepAsync(3600 * 1000)
|
||||||
|
|
||||||
proc getAuthHash*(cfg: Config): string =
|
proc getAuthHash*(cfg: Config): string =
|
||||||
if cfg.guestAccountsPoolAuth == "":
|
if cfg.guestAccountsPoolAuth == "":
|
||||||
|
|
|
@ -7,6 +7,6 @@ import ".."/[types, auth]
|
||||||
|
|
||||||
proc createAuthRouter*(cfg: Config) =
|
proc createAuthRouter*(cfg: Config) =
|
||||||
router auth:
|
router auth:
|
||||||
get "/.well-known/nitter-request-auth":
|
get "/.well-known/nitter-auth":
|
||||||
cond cfg.guestAccountsUsePool
|
cond cfg.guestAccountsUsePool
|
||||||
resp Http200, {"content-type": "text/plain"}, getAuthHash(cfg)
|
resp Http200, {"content-type": "text/plain"}, getAuthHash(cfg)
|
||||||
|
|
Loading…
Reference in a new issue