This commit is contained in:
parent
bb48a8ef11
commit
517de93ccd
4
main.py
4
main.py
|
@ -9,9 +9,9 @@ from sentry_sdk.integrations.ariadne import AriadneIntegration
|
||||||
from sentry_sdk.integrations.redis import RedisIntegration
|
from sentry_sdk.integrations.redis import RedisIntegration
|
||||||
from starlette.applications import Starlette
|
from starlette.applications import Starlette
|
||||||
|
|
||||||
from services.schema import resolvers
|
|
||||||
from services.rediscache import redis
|
from services.rediscache import redis
|
||||||
from settings import DEV_SERVER_PID_FILE_NAME, SENTRY_DSN, MODE
|
from services.schema import resolvers
|
||||||
|
from settings import DEV_SERVER_PID_FILE_NAME, MODE, SENTRY_DSN
|
||||||
|
|
||||||
import_module("resolvers")
|
import_module("resolvers")
|
||||||
schema = make_executable_schema(load_schema_from_path("inbox.graphql"), resolvers) # type: ignore
|
schema = make_executable_schema(load_schema_from_path("inbox.graphql"), resolvers) # type: ignore
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from typing import TypedDict, Optional, List
|
from typing import List, Optional, TypedDict
|
||||||
|
|
||||||
from models.member import ChatMember
|
from models.member import ChatMember
|
||||||
from models.message import Message
|
from models.message import Message
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from typing import TypedDict, Optional
|
from typing import Optional, TypedDict
|
||||||
|
|
||||||
|
|
||||||
class ChatMember(TypedDict):
|
class ChatMember(TypedDict):
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from typing import TypedDict, Optional
|
from typing import Optional, TypedDict
|
||||||
|
|
||||||
|
|
||||||
class Message(TypedDict):
|
class Message(TypedDict):
|
||||||
|
|
|
@ -6,27 +6,27 @@ authors = ["Tony Rewin <anton.rewin@gmail.com>"]
|
||||||
|
|
||||||
[tool.poetry.dependencies]
|
[tool.poetry.dependencies]
|
||||||
python = "^3.12"
|
python = "^3.12"
|
||||||
sentry-sdk = "^1.32.0"
|
sentry-sdk = "^1.39.1"
|
||||||
redis = { extras = ["hiredis"], version = "^5.0.1" }
|
redis = { extras = ["hiredis"], version = "^5.0.1" }
|
||||||
ariadne = "^0.21"
|
ariadne = "^0.21"
|
||||||
starlette = "^0.32"
|
starlette = "^0.34.0"
|
||||||
uvicorn = "^0.24"
|
uvicorn = "^0.24"
|
||||||
itsdangerous = "^2.1.2"
|
itsdangerous = "^2.1.2"
|
||||||
aiohttp = "^3.9.1"
|
aiohttp = "^3.9.1"
|
||||||
|
|
||||||
[tool.poetry.group.dev.dependencies]
|
[tool.poetry.group.dev.dependencies]
|
||||||
setuptools = "^69.0.2"
|
setuptools = "^69.0.2"
|
||||||
|
isort = "^5.13.2"
|
||||||
|
pyright = "^1.1.341"
|
||||||
|
mypy = "^1.7.1"
|
||||||
|
ruff = "^0.1.8"
|
||||||
|
black = "^23.12.0"
|
||||||
|
pytest = "^7.4.3"
|
||||||
|
|
||||||
[build-system]
|
[build-system]
|
||||||
requires = ["poetry-core"]
|
requires = ["poetry-core"]
|
||||||
build-backend = "poetry.core.masonry.api"
|
build-backend = "poetry.core.masonry.api"
|
||||||
|
|
||||||
[tool.poetry.dev-dependencies]
|
|
||||||
pytest = "^7.4.2"
|
|
||||||
black = { version = "^23.9.1", python = ">=3.12" }
|
|
||||||
ruff = { version = "^0.1.0", python = ">=3.12" }
|
|
||||||
setuptools = "^69.0.2"
|
|
||||||
|
|
||||||
[tool.black]
|
[tool.black]
|
||||||
line-length = 120
|
line-length = 120
|
||||||
target-version = ['py312']
|
target-version = ['py312']
|
||||||
|
|
|
@ -1,12 +1,7 @@
|
||||||
from resolvers.chats import create_chat, delete_chat, update_chat
|
from resolvers.chats import create_chat, delete_chat, update_chat
|
||||||
from resolvers.load import load_chats, load_messages_by, load_recipients
|
from resolvers.load import load_chats, load_messages_by, load_recipients
|
||||||
from resolvers.messages import (
|
from resolvers.messages import create_message, delete_message, mark_as_read, update_message
|
||||||
create_message,
|
from resolvers.search import search_messages, search_recipients
|
||||||
delete_message,
|
|
||||||
update_message,
|
|
||||||
mark_as_read,
|
|
||||||
)
|
|
||||||
from resolvers.search import search_recipients, search_messages
|
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
# inbox
|
# inbox
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import json
|
import json
|
||||||
import uuid
|
|
||||||
import time
|
import time
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
from models.chat import Chat, ChatUpdate
|
||||||
from services.auth import login_required
|
from services.auth import login_required
|
||||||
|
from services.presence import notify_chat
|
||||||
from services.rediscache import redis
|
from services.rediscache import redis
|
||||||
from services.schema import mutation
|
from services.schema import mutation
|
||||||
from models.chat import Chat, ChatUpdate
|
|
||||||
from services.presence import notify_chat
|
|
||||||
|
|
||||||
|
|
||||||
@mutation.field("update_chat")
|
@mutation.field("update_chat")
|
||||||
|
|
|
@ -2,13 +2,13 @@ import asyncio
|
||||||
import json
|
import json
|
||||||
from typing import Any, Dict, List, Optional, Union
|
from typing import Any, Dict, List, Optional, Union
|
||||||
|
|
||||||
from services.auth import login_required
|
from models.chat import ChatPayload, Message
|
||||||
from services.core import get_my_followed, get_all_authors
|
|
||||||
from services.rediscache import redis
|
|
||||||
from services.schema import query
|
|
||||||
from models.chat import Message, ChatPayload
|
|
||||||
from models.member import ChatMember
|
from models.member import ChatMember
|
||||||
from resolvers.chats import create_chat
|
from resolvers.chats import create_chat
|
||||||
|
from services.auth import login_required
|
||||||
|
from services.core import get_all_authors, get_my_followed
|
||||||
|
from services.rediscache import redis
|
||||||
|
from services.schema import query
|
||||||
|
|
||||||
|
|
||||||
async def get_unread_counter(chat_id: str, member_id: int) -> int:
|
async def get_unread_counter(chat_id: str, member_id: int) -> int:
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
from models.chat import Message
|
||||||
from services.auth import login_required
|
from services.auth import login_required
|
||||||
from services.presence import notify_message
|
from services.presence import notify_message
|
||||||
from services.rediscache import redis
|
from services.rediscache import redis
|
||||||
from services.schema import mutation
|
from services.schema import mutation
|
||||||
from models.chat import Message
|
|
||||||
|
|
||||||
|
|
||||||
@mutation.field("create_message")
|
@mutation.field("create_message")
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import json
|
import json
|
||||||
from datetime import datetime, timezone, timedelta
|
from datetime import datetime, timedelta, timezone
|
||||||
from typing import Dict, Union, List, Any
|
from typing import Any, Dict, List, Union
|
||||||
|
|
||||||
from resolvers.load import load_messages
|
from resolvers.load import load_messages
|
||||||
from services.auth import login_required
|
from services.auth import login_required
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
from services.core import get_author
|
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
from aiohttp.web import HTTPUnauthorized
|
from aiohttp.web import HTTPUnauthorized
|
||||||
|
|
||||||
|
from services.core import get_author
|
||||||
from settings import AUTH_URL
|
from settings import AUTH_URL
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,7 +13,7 @@ async def check_auth(req) -> (bool, int | None):
|
||||||
# Logging the authentication token
|
# Logging the authentication token
|
||||||
print(f"[services.auth] checking auth token: {token}")
|
print(f"[services.auth] checking auth token: {token}")
|
||||||
query_name = "validate_jwt_token"
|
query_name = "validate_jwt_token"
|
||||||
opeation = "ValidateToken"
|
operation = "ValidateToken"
|
||||||
headers = {
|
headers = {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
}
|
}
|
||||||
|
@ -20,14 +21,14 @@ async def check_auth(req) -> (bool, int | None):
|
||||||
variables = {
|
variables = {
|
||||||
"params": {
|
"params": {
|
||||||
"token_type": "access_token",
|
"token_type": "access_token",
|
||||||
"token": token.encode("utf-8"),
|
"token": token,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gql = {
|
gql = {
|
||||||
"query": f"query {opeation}($params: ValidateJWTTokenInput!) {{ {query_name}(params: $params) {{ is_valid claims }} }}",
|
"query": f"query {operation}($params: ValidateJWTTokenInput!) {{ {query_name}(params: $params) {{ is_valid claims }} }}",
|
||||||
"variables": variables,
|
"variables": variables,
|
||||||
"operationName": opeation,
|
"operationName": operation,
|
||||||
}
|
}
|
||||||
print(f"[services.auth] Graphql: {gql}")
|
print(f"[services.auth] Graphql: {gql}")
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
|
from typing import Any, List
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
from settings import API_BASE
|
|
||||||
from typing import List, Any
|
|
||||||
from models.member import ChatMember
|
from models.member import ChatMember
|
||||||
|
from settings import API_BASE
|
||||||
|
|
||||||
headers = {"Content-Type": "application/json"}
|
headers = {"Content-Type": "application/json"}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
from models.chat import ChatUpdate, Message
|
||||||
from services.rediscache import redis
|
from services.rediscache import redis
|
||||||
from models.chat import Message, ChatUpdate
|
|
||||||
|
|
||||||
|
|
||||||
async def notify_message(message: Message, action="create"):
|
async def notify_message(message: Message, action="create"):
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import redis.asyncio as aredis
|
import redis.asyncio as aredis
|
||||||
|
|
||||||
from settings import REDIS_URL
|
from settings import REDIS_URL
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from ariadne import QueryType, MutationType
|
from ariadne import MutationType, QueryType
|
||||||
|
|
||||||
query = QueryType()
|
query = QueryType()
|
||||||
mutation = MutationType()
|
mutation = MutationType()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user