diff --git a/src/api.nim b/src/api.nim index a5fee3f..7f29791 100644 --- a/src/api.nim +++ b/src/api.nim @@ -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 } diff --git a/src/experimental/parser/graphql.nim b/src/experimental/parser/graphql.nim index 69837ab..7d84833 100644 --- a/src/experimental/parser/graphql.nim +++ b/src/experimental/parser/graphql.nim @@ -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]( diff --git a/src/parser.nim b/src/parser.nim index 920cae7..f26f9b8 100644 --- a/src/parser.nim +++ b/src/parser.nim @@ -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 diff --git a/src/routes/activityspoof.nim b/src/routes/activityspoof.nim index c779546..e40d8df 100644 --- a/src/routes/activityspoof.nim +++ b/src/routes/activityspoof.nim @@ -14,17 +14,17 @@ export mastoapi proc createActivityPubRouter*(cfg: Config) = router activityspoof: + get "/api/v1/accounts/?": + resp Http200, {"Content-Type": "application/json"}, """[]""" + get "/api/v1/accounts/@id": let id = @"id" - if id.len == 0: - resp Http200, {"Content-Type": "application/json"}, """[]""" + 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: - let tmpuser = await getGraphUserById(id) - username = tmpuser.username - if username.len > 0: - resp Http404, {"Content-Type": "application/json"}, """{"error":"Invalid account 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: