Fix crash when profile doesn't exist
This commit is contained in:
parent
d6b8b386fa
commit
06a54a5c32
3 changed files with 16 additions and 12 deletions
|
@ -539,7 +539,7 @@ nav {
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
display: flex;
|
display: flex;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0 2px;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -118,6 +118,9 @@ proc getProfileFallback(username: string; headers: HttpHeaders): Future[Profile]
|
||||||
url = base / profileIntentUrl ? {"screen_name": username}
|
url = base / profileIntentUrl ? {"screen_name": username}
|
||||||
html = await fetchHtml(url, headers)
|
html = await fetchHtml(url, headers)
|
||||||
|
|
||||||
|
if html.isNil:
|
||||||
|
return Profile()
|
||||||
|
|
||||||
result = parseIntentProfile(html)
|
result = parseIntentProfile(html)
|
||||||
|
|
||||||
proc getProfile*(username: string): Future[Profile] {.async.} =
|
proc getProfile*(username: string): Future[Profile] {.async.} =
|
||||||
|
@ -139,6 +142,9 @@ proc getProfile*(username: string): Future[Profile] {.async.} =
|
||||||
url = base / profilePopupUrl ? params
|
url = base / profilePopupUrl ? params
|
||||||
html = await fetchHtml(url, headers, jsonKey="html")
|
html = await fetchHtml(url, headers, jsonKey="html")
|
||||||
|
|
||||||
|
if html.isNil:
|
||||||
|
return Profile()
|
||||||
|
|
||||||
if not html.querySelector(".ProfileCard-sensitiveWarningContainer").isNil:
|
if not html.querySelector(".ProfileCard-sensitiveWarningContainer").isNil:
|
||||||
return await getProfileFallback(username, headers)
|
return await getProfileFallback(username, headers)
|
||||||
|
|
||||||
|
|
|
@ -16,15 +16,13 @@ proc getCachedProfile*(username: string; force=false): Future[Profile] {.async.}
|
||||||
withDb:
|
withDb:
|
||||||
try:
|
try:
|
||||||
result.getOne("username = ?", username)
|
result.getOne("username = ?", username)
|
||||||
doAssert(not result.outdated())
|
doAssert not result.outdated()
|
||||||
except:
|
except AssertionError:
|
||||||
if result.id == 0:
|
var profile = await getProfile(username)
|
||||||
result = await getProfile(username)
|
profile.id = result.id
|
||||||
|
result = profile
|
||||||
|
result.update()
|
||||||
|
except KeyError:
|
||||||
|
result = await getProfile(username)
|
||||||
|
if result.username.len > 0:
|
||||||
result.insert()
|
result.insert()
|
||||||
elif result.outdated():
|
|
||||||
let
|
|
||||||
profile = await getProfile(username)
|
|
||||||
oldId = result.id
|
|
||||||
result = profile
|
|
||||||
result.id = oldId
|
|
||||||
result.update()
|
|
||||||
|
|
Loading…
Reference in a new issue