mirror of
https://github.com/zedeus/nitter.git
synced 2024-12-23 03:45:36 +00:00
Fix crash on protected profiles
This commit is contained in:
parent
8000a814df
commit
a3285e8410
|
@ -49,11 +49,10 @@ proc fetchJson(url: Uri; headers: HttpHeaders): Future[JsonNode] {.async.} =
|
|||
var resp = ""
|
||||
try:
|
||||
resp = await client.getContent($url)
|
||||
result = parseJson(resp)
|
||||
except:
|
||||
return nil
|
||||
|
||||
return parseJson(resp)
|
||||
|
||||
proc getGuestToken(): Future[string] {.async.} =
|
||||
if getTime() - tokenUpdated < tokenLifetime:
|
||||
return token
|
||||
|
@ -166,7 +165,7 @@ proc getTimeline*(username: string; after=""): Future[Timeline] {.async.} =
|
|||
url &= "&max_position=" & cleanAfter
|
||||
|
||||
let json = await fetchJson(base / url, headers)
|
||||
let html = parseHtml(json["items_html"].to(string))
|
||||
if json.isNil: return Timeline()
|
||||
|
||||
result = Timeline(
|
||||
hasMore: json["has_more_items"].to(bool),
|
||||
|
@ -177,6 +176,7 @@ proc getTimeline*(username: string; after=""): Future[Timeline] {.async.} =
|
|||
if json["new_latent_count"].to(int) == 0:
|
||||
return
|
||||
|
||||
let html = parseHtml(json["items_html"].to(string))
|
||||
result.tweets = parseTweets(html)
|
||||
await getVideos(result.tweets)
|
||||
|
||||
|
|
|
@ -53,6 +53,7 @@
|
|||
#end proc
|
||||
#
|
||||
#proc renderTimeline*(timeline: Timeline; profile: Profile; beginning: bool): string =
|
||||
#var retweets: Tweets
|
||||
<div id="tweets">
|
||||
#if profile.protected:
|
||||
<div class="timeline-protected">
|
||||
|
@ -60,18 +61,20 @@
|
|||
<p class="timeline-protected-explanation">Only confirmed followers have access to @${profile.username}'s Tweets.</p>
|
||||
</div>
|
||||
#end if
|
||||
#
|
||||
#if not beginning:
|
||||
<div class="show-more status-el">
|
||||
<a href="/${profile.username}">Load newest tweets</a>
|
||||
</div>
|
||||
#end if
|
||||
#var retweets: Tweets
|
||||
#
|
||||
#for tweet in timeline.tweets:
|
||||
#if tweet in retweets: continue
|
||||
#elif tweet.retweetBy.isSome: retweets.add tweet
|
||||
#end if
|
||||
${renderTweet(tweet, "timeline-tweet")}
|
||||
#if tweet in retweets: continue
|
||||
#elif tweet.retweetBy.isSome: retweets.add tweet
|
||||
#end if
|
||||
${renderTweet(tweet, "timeline-tweet")}
|
||||
#end for
|
||||
#
|
||||
#if timeline.hasMore:
|
||||
<div class="show-more">
|
||||
<a href="/${profile.username}?after=${timeline.minId}">Load older tweets</a>
|
||||
|
@ -81,6 +84,7 @@
|
|||
<h2 class="timeline-end" style="text-align: center;">No more tweets.</h2>
|
||||
</div>
|
||||
#end if
|
||||
#
|
||||
#if timeline.tweets.len == 0:
|
||||
<div class="timeline-protected">
|
||||
<h2 class="timeline-protected-header" style="text-align: center;">No tweets found.</h2>
|
||||
|
|
Loading…
Reference in a new issue