0.0.3
Some checks are pending
deploy / deploy (push) Waiting to run

This commit is contained in:
2023-11-30 09:42:41 +03:00
parent 851ab77f7b
commit 9849788cb6
4 changed files with 29 additions and 23 deletions

View File

@@ -1,5 +1,5 @@
from functools import wraps
from httpx import AsyncClient
import aiohttp
from orm.author import Author
from services.db import local_session
@@ -21,16 +21,16 @@ async def check_auth(req):
"variables": None,
}
async with AsyncClient(timeout=30.0) as client:
response = await client.post(AUTH_URL, headers=headers, json=gql)
print(f"[services.auth] {AUTH_URL} response: {response.status_code}")
if response.status_code != 200:
return False, None
r = response.json()
if r:
user_id = r.get("data", {}).get(query_name, {}).get("user", {}).get("id", None)
is_authenticated = user_id is not None
return is_authenticated, user_id
async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=30.0)) as session:
async with session.post(AUTH_URL, headers=headers, json=gql) as response:
print(f"[services.auth] {AUTH_URL} response: {response.status}")
if response.status != 200:
return False, None
r = await response.json()
if r:
user_id = r.get("data", {}).get(query_name, {}).get("user", {}).get("id", None)
is_authenticated = user_id is not None
return is_authenticated, user_id
return False, None

View File

@@ -1,22 +1,22 @@
from typing import List, Any
from httpx import AsyncClient
import aiohttp
from settings import API_BASE
headers = {"Content-Type": "application/json"}
async def _request_endpoint(query_name, body):
async with AsyncClient() as client:
async with aiohttp.ClientSession() as session:
try:
response = await client.post(API_BASE, headers=headers, json=body)
print(f"[services.core] {query_name}: [{response.status_code}] {len(response.text)} bytes")
if response.status_code != 200:
return []
r = response.json()
if r:
return r.get("data", {}).get(query_name, {})
else:
raise Exception("json response error")
async with session.post(API_BASE, headers=headers, json=body) as response:
print(f"[services.core] {query_name}: [{response.status}] {len(await response.text())} bytes")
if response.status != 200:
return []
r = await response.json()
if r:
return r.get("data", {}).get(query_name, {})
else:
raise Exception("json response error")
except Exception:
import traceback