core-api-fix
All checks were successful
deploy / deploy (push) Successful in 1m17s

This commit is contained in:
Untone 2023-11-06 19:25:28 +03:00
parent aefb94de66
commit 1fe3d774bf

View File

@ -6,17 +6,19 @@ from settings import API_BASE
from validators.member import ChatMember from validators.member import ChatMember
headers = {"Content-Type": "application/json"} headers = {"Content-Type": "application/json"}
INTERNAL_AUTH_SERVER = 'v2.' in API_BASE
async def get_author(author_id): async def get_author(author_id):
query_name = "GetAuthor" if INTERNAL_AUTH_SERVER else "GetAuthorById"
query_type = "query"
operation = "GetAuthorById"
query_fields = "id slug userpic name lastSeen" if INTERNAL_AUTH_SERVER else "id slug userpic name last_seen"
headers = {"Content-Type": "application/json"} # "Bearer " + removed
gql = { gql = {
"query": """query GetAuthorById($author_id: Int!) { "query": query_type + " " + operation + " { " + query_name + " { " + query_fields + " } " + " }",
getAuthorById(author_id: $author_id) { "operationName": operation,
id slug userpic name lastSeen "variables": None,
}
}""",
"operation": "GetAuthorById",
"variables": {"author_id": int(author_id)},
} }
async with AsyncClient() as client: async with AsyncClient() as client:
try: try:
@ -30,10 +32,10 @@ async def get_author(author_id):
r = response.json() r = response.json()
a = r.get("data", {}).get("getAuthorById") a = r.get("data", {}).get("getAuthorById")
if a: if a:
last_seen = a.get("lastSeen") ts_value = a.get("lastSeen", a.get("last_seen"))
dt = datetime.strptime(last_seen, "%Y-%m-%dT%H:%M:%S.%f") dt = datetime.strptime(ts_value, "%Y-%m-%dT%H:%M:%S.%f")
timestamp = int(dt.timestamp()) timestamp = int(dt.timestamp())
a["lastSeen"] = timestamp a["last_seen"] = timestamp
author: ChatMember = a author: ChatMember = a
return author return author