Use TweetResultByRestId for embeds

This commit is contained in:
Zed 2026-08-08 23:00:19 +07:00
commit ccde22aa0b
4 changed files with 23 additions and 4 deletions

View file

@ -230,6 +230,13 @@ proc getGraphTweetResult*(id: string): Future[Tweet] {.async.} =
js = await fetch(url) js = await fetch(url)
result = parseGraphTweetResult(js) 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.} = proc getGraphTweet(id: string; after=""; mode = Relevance): Future[Conversation] {.async.} =
if id.len == 0: return if id.len == 0: return
let let

View file

@ -35,7 +35,7 @@ const
graphCommunityModerators* = "GBMT3GOWy5dYsYC4XJfvow/moderatorsSliceTimeline_Query" graphCommunityModerators* = "GBMT3GOWy5dYsYC4XJfvow/moderatorsSliceTimeline_Query"
graphCommunityHashtags* = "40DyrMxfCknGuZwE-keW_Q/CommunityHashtagsTimeline" graphCommunityHashtags* = "40DyrMxfCknGuZwE-keW_Q/CommunityHashtagsTimeline"
graphTweetResultByRestId* = "qtXMy1p5Y62uCskc_NUPJw/TweetResultByRestId" graphTweetResultByRestId* = "4hhGRbehkcUVTKf8n0f0xw/TweetResultByRestId"
graphTweetResultsByRestIds* = "Sc9EUQTZNEH-wzegn-nHvQ/TweetResultsByRestIds" graphTweetResultsByRestIds* = "Sc9EUQTZNEH-wzegn-nHvQ/TweetResultsByRestIds"
graphBroadcast* = "FJLCzpXCLPM1jUZqmM7oEA/BroadcastQuery" graphBroadcast* = "FJLCzpXCLPM1jUZqmM7oEA/BroadcastQuery"
@ -166,6 +166,14 @@ const
articleFieldToggles* = """{"withArticleRichContentState":true,"withArticlePlainText":false,"withArticleSummaryText":true,"withArticleVoiceOver":true}""" articleFieldToggles* = """{"withArticleRichContentState":true,"withArticlePlainText":false,"withArticleSummaryText":true,"withArticleVoiceOver":true}"""
tweetByRestIdVars* = """{
"tweetId": "$1",
"includePromotedContent": false,
"withBirdwatchNotes": false,
"withVoice": false,
"withCommunity": false
}""".replace(" ", "").replace("\n", "")
communityTweetsVars* = """{ communityTweetsVars* = """{
"communityId": "$1", $2 "communityId": "$1", $2
"count": 20, "count": 20,

View file

@ -751,6 +751,10 @@ proc parseGraphTweetResult*(js: JsonNode): Tweet =
with tweet, js{"data", "tweet_result", "result"}: with tweet, js{"data", "tweet_result", "result"}:
result = parseGraphTweet(tweet) result = parseGraphTweet(tweet)
proc parseTweetByRestId*(js: JsonNode): Tweet =
with tweet, js{"data", "tweetResult", "result"}:
result = parseGraphTweet(tweet)
proc parseGraphTweetResults*(js: JsonNode): seq[Tweet] = proc parseGraphTweetResults*(js: JsonNode): seq[Tweet] =
let results = js{"data", "tweetResult"} let results = js{"data", "tweetResult"}
if results.kind != JArray: return if results.kind != JArray: return

View file

@ -32,7 +32,7 @@ proc createEmbedRouter*(cfg: Config) =
router embed: router embed:
get "/i/videos/tweet/@id": get "/i/videos/tweet/@id":
let let
tweet = await getGraphTweetResult(@"id") tweet = await getTweetByRestId(@"id")
prefs = requestPrefs() prefs = requestPrefs()
if tweet == nil: if tweet == nil:
@ -45,7 +45,7 @@ proc createEmbedRouter*(cfg: Config) =
get "/@user/status/@id/embed": get "/@user/status/@id/embed":
let let
tweet = await getGraphTweetResult(@"id") tweet = await getTweetByRestId(@"id")
prefs = requestPrefs() prefs = requestPrefs()
path = getPath() path = getPath()
@ -71,7 +71,7 @@ proc createEmbedRouter*(cfg: Config) =
if username.len == 0 or tweetId.len == 0: if username.len == 0 or tweetId.len == 0:
resp Http400, "Invalid tweet URL" resp Http400, "Invalid tweet URL"
let tweet = await getGraphTweetResult(tweetId) let tweet = await getTweetByRestId(tweetId)
if tweet == nil: if tweet == nil:
resp Http404 resp Http404