Migrated to dragonion_core

This commit is contained in:
BarsTiger
2023-07-17 00:06:35 +03:00
parent 1497e0ced8
commit 7945194d5a
10 changed files with 9 additions and 93 deletions

View File

@@ -1,6 +1,6 @@
from attrs import define
from fastapi import WebSocket
from ..objects.webmessage import (
from dragonion_core.proto.web import (
webmessages_union,
webmessage_error_message_literal,
WebErrorMessage,

View File

@@ -3,7 +3,7 @@ from .connection import Connection
from typing import Dict
from fastapi import WebSocket
from ..objects.webmessage import (
from dragonion_core.proto.web import (
webmessages_union,
WebMessageMessage,
WebNotificationMessage,

View File

@@ -2,7 +2,7 @@ from .connection import Connection
from .room import Room
from typing import Dict
from ..objects.webmessage import (
from dragonion_core.proto.web import (
webmessage_error_message_literal
)

View File

@@ -1,69 +0,0 @@
from typing import Literal, Final, Union
from dataclasses_json import dataclass_json
from dataclasses import dataclass
webmessage_type_literal = Literal[
"connect", "message", "disconnect", "error", "notification"
]
webmessage_error_message_literal = Literal[
"unknown", "username_exists", "invalid_webmessage"
]
@dataclass_json
@dataclass
class _WebAnyMessage:
username: str | None = None
type: webmessage_type_literal = "message"
message: str | None = None
error_message: webmessage_error_message_literal | None = None
@dataclass_json
@dataclass
class WebMessageMessage:
username: str
message: str
type: Final = "message"
@dataclass_json
@dataclass
class WebErrorMessage:
error_message: webmessage_error_message_literal
type: Final = "error"
@dataclass_json
@dataclass
class WebUserMessage:
type: Literal["connect", "disconnect"]
username: str
@dataclass_json
@dataclass
class WebNotificationMessage:
message: str
type: Final = "notification"
webmessages_union = Union[
WebMessageMessage,
WebErrorMessage,
WebUserMessage,
WebNotificationMessage
]
class WebMessage:
@staticmethod
def from_json(data) -> webmessages_union:
return {
"connect": WebUserMessage.from_json,
"disconnect": WebUserMessage.from_json,
"message": WebMessageMessage.from_json,
"error": WebErrorMessage.from_json,
"notification": WebNotificationMessage.from_json
}[_WebAnyMessage.from_json(data).type](data)

View File

@@ -1,6 +1,6 @@
from fastapi import WebSocket, WebSocketDisconnect
from .managers.service import Service
from .objects.webmessage import (
from dragonion_core.proto.web import (
webmessages_union,
WebMessage
)

View File

@@ -1,7 +1,7 @@
import sys
from dragonion_server.utils.onion import Onion
from dragonion_server.utils.generated_auth.db import AuthFile
from dragonion_core.proto.file import AuthFile
from dragonion_server.utils.config.db import services
from rich import print

View File

@@ -1 +0,0 @@
pass

View File

@@ -1,15 +0,0 @@
import sqlitedict
class AuthFile(sqlitedict.SqliteDict):
"""
Valid AuthFile has fields:
host - .onion url of service
auth - v3 onion auth string in format, that can be written to .auth_private file
"""
def __init__(self, service):
super().__init__(
filename=f'{service}.auth',
tablename='auth',
autocommit=True
)

View File

@@ -12,13 +12,15 @@ psutil = "^5.9.5"
pynacl = "^1.5.0"
requests = "^2.31.0"
sqlitedict = "^2.1.0"
fastapi = "^0.99.0"
uvicorn = "^0.22.0"
fastapi = "^0.100.0"
uvicorn = "^0.23.0"
rich = "^13.4.2"
click = "^8.1.3"
attrs = "^23.1.0"
dataclasses-json = "^0.5.9"
websockets = "^11.0.3"
dragonion-core = { git = "https://github.com/dragonionx/dragonion-core.git" }
[tool.poetry.scripts]
dragonion-server = "dragonion_server:main"