mirror of
https://github.com/zedeus/nitter
synced 2026-09-05 22:59:31 +00:00
Use TweetResultByRestId for embeds
This commit is contained in:
parent
6d41157603
commit
ccde22aa0b
4 changed files with 23 additions and 4 deletions
|
|
@ -230,6 +230,13 @@ proc getGraphTweetResult*(id: string): Future[Tweet] {.async.} =
|
|||
js = await fetch(url)
|
||||
result = parseGraphTweetResult(js)
|
||||
|
||||
proc getTweetByRestId*(id: string): Future[Tweet] {.async.} =
|
||||
if id.len == 0: return
|
||||
let
|
||||
url = apiReq(graphTweetResultByRestId, tweetByRestIdVars % id, articleFieldToggles)
|
||||
js = await fetch(url)
|
||||
result = parseTweetByRestId(js)
|
||||
|
||||
proc getGraphTweet(id: string; after=""; mode = Relevance): Future[Conversation] {.async.} =
|
||||
if id.len == 0: return
|
||||
let
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ const
|
|||
graphCommunityModerators* = "GBMT3GOWy5dYsYC4XJfvow/moderatorsSliceTimeline_Query"
|
||||
graphCommunityHashtags* = "40DyrMxfCknGuZwE-keW_Q/CommunityHashtagsTimeline"
|
||||
|
||||
graphTweetResultByRestId* = "qtXMy1p5Y62uCskc_NUPJw/TweetResultByRestId"
|
||||
graphTweetResultByRestId* = "4hhGRbehkcUVTKf8n0f0xw/TweetResultByRestId"
|
||||
graphTweetResultsByRestIds* = "Sc9EUQTZNEH-wzegn-nHvQ/TweetResultsByRestIds"
|
||||
|
||||
graphBroadcast* = "FJLCzpXCLPM1jUZqmM7oEA/BroadcastQuery"
|
||||
|
|
@ -166,6 +166,14 @@ const
|
|||
|
||||
articleFieldToggles* = """{"withArticleRichContentState":true,"withArticlePlainText":false,"withArticleSummaryText":true,"withArticleVoiceOver":true}"""
|
||||
|
||||
tweetByRestIdVars* = """{
|
||||
"tweetId": "$1",
|
||||
"includePromotedContent": false,
|
||||
"withBirdwatchNotes": false,
|
||||
"withVoice": false,
|
||||
"withCommunity": false
|
||||
}""".replace(" ", "").replace("\n", "")
|
||||
|
||||
communityTweetsVars* = """{
|
||||
"communityId": "$1", $2
|
||||
"count": 20,
|
||||
|
|
|
|||
|
|
@ -751,6 +751,10 @@ proc parseGraphTweetResult*(js: JsonNode): Tweet =
|
|||
with tweet, js{"data", "tweet_result", "result"}:
|
||||
result = parseGraphTweet(tweet)
|
||||
|
||||
proc parseTweetByRestId*(js: JsonNode): Tweet =
|
||||
with tweet, js{"data", "tweetResult", "result"}:
|
||||
result = parseGraphTweet(tweet)
|
||||
|
||||
proc parseGraphTweetResults*(js: JsonNode): seq[Tweet] =
|
||||
let results = js{"data", "tweetResult"}
|
||||
if results.kind != JArray: return
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ proc createEmbedRouter*(cfg: Config) =
|
|||
router embed:
|
||||
get "/i/videos/tweet/@id":
|
||||
let
|
||||
tweet = await getGraphTweetResult(@"id")
|
||||
tweet = await getTweetByRestId(@"id")
|
||||
prefs = requestPrefs()
|
||||
|
||||
if tweet == nil:
|
||||
|
|
@ -45,7 +45,7 @@ proc createEmbedRouter*(cfg: Config) =
|
|||
|
||||
get "/@user/status/@id/embed":
|
||||
let
|
||||
tweet = await getGraphTweetResult(@"id")
|
||||
tweet = await getTweetByRestId(@"id")
|
||||
prefs = requestPrefs()
|
||||
path = getPath()
|
||||
|
||||
|
|
@ -71,7 +71,7 @@ proc createEmbedRouter*(cfg: Config) =
|
|||
if username.len == 0 or tweetId.len == 0:
|
||||
resp Http400, "Invalid tweet URL"
|
||||
|
||||
let tweet = await getGraphTweetResult(tweetId)
|
||||
let tweet = await getTweetByRestId(tweetId)
|
||||
if tweet == nil:
|
||||
resp Http404
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue