some-fixes
Some checks failed
deploy / deploy (push) Failing after 1m12s

This commit is contained in:
2023-11-22 15:09:24 +03:00
parent 4530b2a1e9
commit 856a331836
15 changed files with 63 additions and 90 deletions

View File

@@ -1,23 +1,17 @@
from functools import wraps
from httpx import AsyncClient, HTTPError
from settings import AUTH_URL
INTERNAL_AUTH_SERVER = "auth.discours.io" not in AUTH_URL
async def check_auth(req):
print("%r" % req)
token = req.headers.get("Authorization")
headers = {"Authorization": token, "Content-Type": "application/json"} # "Bearer " + removed
print(f"[services.auth] checking auth token: {token}")
query_name = "getSession" if INTERNAL_AUTH_SERVER else "session"
query_type = "mutation" if INTERNAL_AUTH_SERVER else "query"
query_name = "getSession" if "v2." in AUTH_URL else "session"
query_type = "mutation" if "v2." in AUTH_URL else "query"
operation = "GetUserId"
headers = {"Authorization": token, "Content-Type": "application/json"} # "Bearer " + removed
gql = {
"query": query_type + " " + operation + " { " + query_name + " { user { id } } " + " }",
"operationName": operation,
@@ -26,21 +20,15 @@ async def check_auth(req):
async with AsyncClient(timeout=30.0) as client:
response = await client.post(AUTH_URL, headers=headers, json=gql)
print(f"[services.auth] response: {response.status_code} {response.text}")
print(f"[services.auth] {AUTH_URL} response: {response.status_code}")
if response.status_code != 200:
return False, None
r = response.json()
try:
user_id = (
r.get("data", {}).get(query_name, {}).get("user", {}).get("id", None)
if INTERNAL_AUTH_SERVER
else r.get("data", {}).get(query_name, {}).get("user", {}).get("id", None)
)
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
except Exception as e:
print(f"{e}: {r}")
return False, None
return False, None
def login_required(f):

View File

@@ -1,65 +1,62 @@
from httpx import AsyncClient
from settings import API_BASE
from typing import List
from models.member import ChatMember
headers = {"Content-Type": "application/json"}
INTERNAL_AUTH_SERVER = "v2." in API_BASE
async def get_all_authors():
async def get_all_authors() -> List[ChatMember]:
query_name = "authorsAll"
query_type = "query"
operation = "AuthorsAll"
query_fields = "id slug userpic name"
headers = {"Content-Type": "application/json"} # "Bearer " + removed
gql = {
"query": query_type + " " + operation + " { " + query_name + " { " + query_fields + " } " + " }",
"operationName": operation,
"variables": None,
}
async with AsyncClient() as client:
try:
response = await client.post(API_BASE, headers=headers, json=gql)
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, [])
except Exception:
import traceback
traceback.print_exc()
if response.status_code != 200:
return None
r = response.json()
return r.get("data", {}).get(query_name)
return []
async def get_my_followings():
async def get_my_followings() -> List[ChatMember]:
query_name = "loadMySubscriptions"
query_type = "query"
operation = "LoadMySubscriptions"
query_fields = "id slug userpic name"
headers = {"Content-Type": "application/json"} # "Bearer " + removed
gql = {
"query": query_type + " " + operation + " { " + query_name + " { authors {" + query_fields + "} } " + " }",
"operationName": operation,
"variables": None,
}
async with AsyncClient() as client:
try:
response = await client.post(API_BASE, headers=headers, json=gql)
response = await client.post(API_BASE, headers=headers, json=gql)
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, {}).get("authors", [])
except Exception:
import traceback
traceback.print_exc()
if response.status_code != 200:
return None
r = response.json()
data = r.get("data")
if data:
d = data.get(query_name)
if d:
authors = d.get("authors", [])
return authors
return []
return []

View File

@@ -1,11 +1,11 @@
import json
from services.rediscache import redis
from validators.chat import Message, ChatUpdate
from models.chat import Message, ChatUpdate
async def notify_message(message: Message, action="create"):
channel_name = f"message:{message["chat_id"]}"
channel_name = f"message:{message['chat_id']}"
data = {"payload": message, "action": action}
try:
await redis.publish(channel_name, json.dumps(data))

View File

@@ -1,5 +1,4 @@
import redis.asyncio as aredis
from settings import REDIS_URL

View File

@@ -2,15 +2,4 @@ from ariadne import QueryType, MutationType
query = QueryType()
mutation = MutationType()
@query.field("_service")
def resolve_service(*_):
# Load the full SDL from your SDL file
with open("inbox.graphql", "r") as file:
full_sdl = file.read()
return {"sdl": full_sdl}
resolvers = [query, mutation]