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