tried to fix account id lookup but failed gn

This commit is contained in:
Cynthia Foxwell 2025-04-09 01:20:29 -06:00
parent 4da3904b89
commit a5c9e78f5b
No known key found for this signature in database
4 changed files with 19 additions and 9 deletions

View File

@ -7,7 +7,7 @@ import experimental/parser as newParser
proc getGraphUser*(username: string): Future[User] {.async.} = proc getGraphUser*(username: string): Future[User] {.async.} =
if username.len == 0: return if username.len == 0: return
let let
variables = """{"screen_name": "$1"}""" % username variables = """{"screen_name":"$1"}""" % username
params = {"variables": variables, "features": gqlFeatures} params = {"variables": variables, "features": gqlFeatures}
js = await fetchRaw(graphUser ? params, Api.userScreenName) js = await fetchRaw(graphUser ? params, Api.userScreenName)
result = parseGraphUser(js) result = parseGraphUser(js)
@ -15,7 +15,7 @@ proc getGraphUser*(username: string): Future[User] {.async.} =
proc getGraphUserById*(id: string): Future[User] {.async.} = proc getGraphUserById*(id: string): Future[User] {.async.} =
if id.len == 0 or id.any(c => not c.isDigit): return if id.len == 0 or id.any(c => not c.isDigit): return
let let
variables = """{"rest_id": "$1"}""" % id variables = """{"userId":"$1"}""" % id
params = {"variables": variables, "features": gqlFeatures} params = {"variables": variables, "features": gqlFeatures}
js = await fetchRaw(graphUserById ? params, Api.userRestId) js = await fetchRaw(graphUserById ? params, Api.userRestId)
result = parseGraphUser(js) result = parseGraphUser(js)
@ -51,7 +51,7 @@ proc getGraphListBySlug*(name, list: string): Future[List] {.async.} =
proc getGraphList*(id: string): Future[List] {.async.} = proc getGraphList*(id: string): Future[List] {.async.} =
let let
variables = """{"listId": "$1"}""" % id variables = """{"listId":"$1"}""" % id
params = {"variables": variables, "features": gqlFeatures} params = {"variables": variables, "features": gqlFeatures}
result = parseGraphList(await fetch(graphListById ? params, Api.list)) result = parseGraphList(await fetch(graphListById ? params, Api.list))
@ -90,7 +90,7 @@ proc getFavorites*(id: string; cfg: Config; after=""): Future[Profile] {.async.}
proc getGraphTweetResult*(id: string): Future[Tweet] {.async.} = proc getGraphTweetResult*(id: string): Future[Tweet] {.async.} =
if id.len == 0: return if id.len == 0: return
let let
variables = """{"rest_id": "$1"}""" % id variables = """{"rest_id":"$1"}""" % id
params = {"variables": variables, "features": gqlFeatures} params = {"variables": variables, "features": gqlFeatures}
js = await fetch(graphTweetResult ? params, Api.tweetResult) js = await fetch(graphTweetResult ? params, Api.tweetResult)
result = parseGraphTweetResult(js) result = parseGraphTweetResult(js)

View File

@ -15,8 +15,8 @@ const
timelineApi = api / "2/timeline" timelineApi = api / "2/timeline"
graphql = api / "graphql" graphql = api / "graphql"
graphUser* = graphql / "u7wQyGi6oExe8_TRWGMq4Q/UserResultByScreenNameQuery" graphUser* = graphql / "32pL5BWe9WKeSK1MoPvFQQ/UserByScreenName"
graphUserById* = graphql / "oPppcargziU1uDQHAUmH-A/UserResultByIdQuery" graphUserById* = graphql / "5vdJ5sWkbSRDiiNZvwc2Yg/UserByRestId"
graphUserTweets* = graphql / "3JNH4e9dq1BifLxAa3UMWg/UserWithProfileTweetsQueryV2" graphUserTweets* = graphql / "3JNH4e9dq1BifLxAa3UMWg/UserWithProfileTweetsQueryV2"
graphUserTweetsAndReplies* = graphql / "8IS8MaO-2EN6GZZZb8jF0g/UserWithProfileTweetsAndRepliesQueryV2" graphUserTweetsAndReplies* = graphql / "8IS8MaO-2EN6GZZZb8jF0g/UserWithProfileTweetsAndRepliesQueryV2"
graphUserMedia* = graphql / "dexO_2tohK86JDudXXG3Yw/UserMedia" graphUserMedia* = graphql / "dexO_2tohK86JDudXXG3Yw/UserMedia"
@ -104,7 +104,10 @@ const
"profile_label_improvements_pcf_label_in_post_enabled": true, "profile_label_improvements_pcf_label_in_post_enabled": true,
"responsive_web_grok_image_annotation_enabled": false, "responsive_web_grok_image_annotation_enabled": false,
"responsive_web_grok_share_attachment_enabled": false, "responsive_web_grok_share_attachment_enabled": false,
"rweb_video_screen_enabled": false "rweb_video_screen_enabled": false,
"responsive_web_twitter_article_notes_tab_enabled": false,
"subscriptions_feature_can_gift_premium": false,
"hidden_profile_subscriptions_enabled": true
}""".replace(" ", "").replace("\n", "") }""".replace(" ", "").replace("\n", "")
tweetVariables* = """{ tweetVariables* = """{

View File

@ -33,6 +33,10 @@ proc parseGraphUser(js: JsonNode): User =
var user = js{"user_result", "result"} var user = js{"user_result", "result"}
if user.isNull: if user.isNull:
user = ? js{"user_results", "result"} user = ? js{"user_results", "result"}
if user.isNull:
user = js{"data", "user", "result"}
if user.isNull:
user = ? js{"data", "user", "result"}
result = parseUser(user{"legacy"}) result = parseUser(user{"legacy"})

View File

@ -19,7 +19,10 @@ proc createActivityPubRouter*(cfg: Config) =
if id.len == 0: if id.len == 0:
resp Http200, {"Content-Type": "application/json"}, """[]""" resp Http200, {"Content-Type": "application/json"}, """[]"""
let username = await getCachedUsername(id) var username = await getCachedUsername(id)
if username.len > 0:
let tmpuser = await getGraphUserById(id)
username = tmpuser.username
if username.len > 0: if username.len > 0:
resp Http404, {"Content-Type": "application/json"}, """{"error":"Invalid account ID"}""" resp Http404, {"Content-Type": "application/json"}, """{"error":"Invalid account ID"}"""