okay everything account related fixed
This commit is contained in:
parent
ce4dc8a9e2
commit
536f9d7fab
@ -8,8 +8,9 @@ proc getGraphUser*(username: string): Future[User] {.async.} =
|
||||
if username.len == 0: return
|
||||
let
|
||||
variables = """{"screen_name":"$1"}""" % username
|
||||
params = {"variables": variables, "features": gqlFeatures}
|
||||
js = await fetchRaw(graphUser ? params, Api.userScreenName)
|
||||
fieldToggles = """{"withAuxiliaryUserLabels":true}"""
|
||||
params = {"variables": variables, "features": gqlFeatures, "fieldToggles": fieldToggles}
|
||||
js = await fetch(graphUser ? params, Api.userScreenName)
|
||||
result = parseGraphUser(js)
|
||||
|
||||
proc getGraphUserById*(id: string): Future[User] {.async.} =
|
||||
@ -17,7 +18,7 @@ proc getGraphUserById*(id: string): Future[User] {.async.} =
|
||||
let
|
||||
variables = """{"userId":"$1"}""" % id
|
||||
params = {"variables": variables, "features": gqlFeatures}
|
||||
js = await fetchRaw(graphUserById ? params, Api.userRestId)
|
||||
js = await fetch(graphUserById ? params, Api.userRestId)
|
||||
result = parseGraphUser(js)
|
||||
|
||||
proc getGraphUserTweets*(id: string; kind: TimelineKind; after=""): Future[Profile] {.async.} =
|
||||
@ -77,7 +78,7 @@ proc getFavorites*(id: string; cfg: Config; after=""): Future[Profile] {.async.}
|
||||
"userId": id,
|
||||
"includePromotedContent":false,
|
||||
"withClientEventToken":false,
|
||||
"withBirdwatchNotes":false,
|
||||
"withBirdwatchNotes":true,
|
||||
"withVoice":true,
|
||||
"withV2Timeline":false
|
||||
}
|
||||
|
||||
@ -3,19 +3,19 @@ import jsony
|
||||
import user, ../types/[graphuser, graphlistmembers]
|
||||
from ../../types import User, VerifiedType, Result, Query, QueryKind
|
||||
|
||||
proc parseGraphUser*(json: string): User =
|
||||
if json.len == 0 or json[0] != '{':
|
||||
return
|
||||
|
||||
let raw = json.fromJson(GraphUser)
|
||||
|
||||
if raw.data.userResult.result.unavailableReason.get("") == "Suspended":
|
||||
return User(suspended: true)
|
||||
|
||||
result = raw.data.userResult.result.legacy
|
||||
result.id = raw.data.userResult.result.restId
|
||||
if result.verifiedType == VerifiedType.none and raw.data.userResult.result.isBlueVerified:
|
||||
result.verifiedType = blue
|
||||
#proc parseGraphUser*(json: string): User =
|
||||
# if json.len == 0 or json[0] != '{':
|
||||
# return
|
||||
#
|
||||
# let raw = json.fromJson(GraphUser)
|
||||
#
|
||||
# if raw.data.userResult.result.unavailableReason.get("") == "Suspended":
|
||||
# return User(suspended: true)
|
||||
#
|
||||
# result = raw.data.userResult.result.legacy
|
||||
# result.id = raw.data.userResult.result.restId
|
||||
# if result.verifiedType == VerifiedType.none and raw.data.userResult.result.isBlueVerified:
|
||||
# result.verifiedType = blue
|
||||
|
||||
proc parseGraphListMembers*(json, cursor: string): Result[User] =
|
||||
result = Result[User](
|
||||
|
||||
@ -29,16 +29,16 @@ proc parseUser(js: JsonNode; id=""): User =
|
||||
|
||||
result.expandUserEntities(js)
|
||||
|
||||
proc parseGraphUser(js: JsonNode): User =
|
||||
var user = js{"user_result", "result"}
|
||||
if user.isNull:
|
||||
user = ? js{"user_results", "result"}
|
||||
if user.isNull:
|
||||
user = js{"data", "user", "result"}
|
||||
if user.isNull:
|
||||
user = ? js{"data", "user", "result"}
|
||||
proc parseGraphUser*(js: JsonNode): User =
|
||||
echo "node: ", $js
|
||||
|
||||
result = parseUser(user{"legacy"})
|
||||
var user = js{"data", "user", "result"}
|
||||
if user.isNull:
|
||||
user = js{"user_results", "result"}
|
||||
if user.isNull:
|
||||
user = js{"user_result", "result"}
|
||||
|
||||
result = parseUser(user{"legacy"}, user{"rest_id"}.getStr)
|
||||
|
||||
if result.verifiedType == VerifiedType.none and user{"is_blue_verified"}.getBool(false):
|
||||
result.verifiedType = blue
|
||||
|
||||
@ -14,18 +14,18 @@ export mastoapi
|
||||
|
||||
proc createActivityPubRouter*(cfg: Config) =
|
||||
router activityspoof:
|
||||
get "/api/v1/accounts/@id":
|
||||
let id = @"id"
|
||||
if id.len == 0:
|
||||
get "/api/v1/accounts/?":
|
||||
resp Http200, {"Content-Type": "application/json"}, """[]"""
|
||||
|
||||
var username = await getCachedUsername(id)
|
||||
if username.len > 0:
|
||||
let tmpuser = await getGraphUserById(id)
|
||||
username = tmpuser.username
|
||||
if username.len > 0:
|
||||
get "/api/v1/accounts/@id":
|
||||
let id = @"id"
|
||||
if id.len > 19 or id.any(c => not c.isDigit):
|
||||
resp Http404, {"Content-Type": "application/json"}, """{"error":"Invalid account ID"}"""
|
||||
|
||||
var username = await getCachedUsername(id)
|
||||
if username.len == 0:
|
||||
resp Http404, {"Content-Type": "application/json"}, """{"error":"User not found"}"""
|
||||
|
||||
let user = await getCachedUser(username)
|
||||
if user.suspended or user.id.len == 0:
|
||||
resp Http404, {"Content-Type": "application/json"}, """{"error":"User not found"}"""
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user