Include username in status requests

This commit is contained in:
Zed 2019-06-27 20:13:46 +02:00
parent a801b01142
commit a43950dcf5
2 changed files with 4 additions and 5 deletions

View File

@ -14,10 +14,9 @@ const
timelineParams = "?include_available_features=1&include_entities=1&include_new_items_bar=false&reset_error_state=false" timelineParams = "?include_available_features=1&include_entities=1&include_new_items_bar=false&reset_error_state=false"
showUrl = "i/profiles/show/$1" & timelineParams showUrl = "i/profiles/show/$1" & timelineParams
timelineUrl = showUrl % "$1/timeline/tweets" timelineUrl = showUrl % "$1/timeline/tweets"
timelineMediaUrl = showUrl % "$1/media_timeline"
profilePopupUrl = "i/profiles/popup" profilePopupUrl = "i/profiles/popup"
profileIntentUrl = "intent/user" profileIntentUrl = "intent/user"
tweetUrl = "i/status/" tweetUrl = "status"
videoUrl = "videos/tweet/config/$1.json" videoUrl = "videos/tweet/config/$1.json"
tokenUrl = "guest/activate.json" tokenUrl = "guest/activate.json"
@ -198,7 +197,7 @@ proc getTimeline*(username: string; after=""): Future[Timeline] {.async.} =
result.tweets = parseTweets(html) result.tweets = parseTweets(html)
await getVideos(result.tweets) await getVideos(result.tweets)
proc getTweet*(id: string): Future[Conversation] {.async.} = proc getTweet*(username: string; id: string): Future[Conversation] {.async.} =
let headers = newHttpHeaders({ let headers = newHttpHeaders({
"Accept": "application/json, text/javascript, */*; q=0.01", "Accept": "application/json, text/javascript, */*; q=0.01",
"Referer": $base, "Referer": $base,
@ -211,7 +210,7 @@ proc getTweet*(id: string): Future[Conversation] {.async.} =
}) })
let let
url = base / tweetUrl / id url = base / username / tweetUrl / id
html = await fetchHtml(url, headers) html = await fetchHtml(url, headers)
if html.isNil: if html.isNil:

View File

@ -43,7 +43,7 @@ routes:
get "/@name/status/@id": get "/@name/status/@id":
cond '.' notin @"name" cond '.' notin @"name"
let conversation = await getTweet(@"id") let conversation = await getTweet(@"name", @"id")
if conversation.isNil or conversation.tweet.id.len == 0: if conversation.isNil or conversation.tweet.id.len == 0:
resp Http404, showError("Tweet not found") resp Http404, showError("Tweet not found")