From 82e728b1fc726b1859ec2bf903911f641f0a5583 Mon Sep 17 00:00:00 2001 From: AURUMVORXX Date: Sat, 6 Sep 2025 16:35:14 +0500 Subject: [PATCH] =?UTF-8?q?feat:=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=20send?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pyg2o/server.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/pyg2o/server.py b/src/pyg2o/server.py index d486b2e..a525703 100644 --- a/src/pyg2o/server.py +++ b/src/pyg2o/server.py @@ -49,6 +49,17 @@ class Server: return request + @classmethod + async def send(cls, connection: WebSocket, message: str, uuid: str): + data = { + 'uuid': uuid, + 'data': message, + } + data = json.dumps(data) + # Меняем синтаксис под Squirrel + data = data.replace("'", '\\"').replace('True', 'true').replace('False', 'false') + await connection.send_text(data) + @classmethod def _make_request(cls): request_id = str(uuid4()) @@ -65,8 +76,8 @@ class Server: @classmethod def _register_routes(cls, app): @app.websocket('/pyg2o') - async def pyg2o(websocket: WebSocket): - await cls._handle_connection(websocket) + async def pyg2o(websocket: WebSocket, token: str, topics: str): + await cls._handle_connection(websocket, token, topics) _ = pyg2o @@ -85,9 +96,9 @@ class Server: cls._topics[topic].discard(connection) @classmethod - async def _handle_connection(cls, connection: WebSocket): + async def _handle_connection(cls, connection: WebSocket, token: str, topics: str): - if not await cls._process_headers(connection): + if not await cls._process_query_params(connection, token, topics): await connection.close() return @@ -108,10 +119,7 @@ class Server: cls._logger.exception(f'Ошибка WebSocket подключения: {e}') @classmethod - async def _process_headers(cls, connection: WebSocket) -> bool: - headers = connection.headers - token = headers.get('Authorization') - topics = headers.get('Subscribe') + async def _process_query_params(cls, connection: WebSocket, token: str, topics: str) -> bool: if token not in cls._static_tokens and token not in cls._temp_tokens: return False