Сравнить коммиты

..

Нет общих коммитов. «b6661d3ebdb2c0cc51425d765509e1ad94895797» и «b9f96398e3a41c23ef4ef3a447bd26d4160ded7e» имеют совершенно разные истории.

Просмотреть файл

@ -1,6 +1,8 @@
import asyncio import asyncio
import os
from fastapi import FastAPI, Body from fastapi import FastAPI
from fastapi.responses import HTMLResponse
from fastapi.websockets import WebSocket, WebSocketDisconnect from fastapi.websockets import WebSocket, WebSocketDisconnect
import config import config
@ -38,6 +40,9 @@ class ConnectionManager:
asyncio.ensure_future(connection.send_json(data)) asyncio.ensure_future(connection.send_json(data))
connection_manager = ConnectionManager()
api = FastAPI( api = FastAPI(
title=config.Main.app_name, title=config.Main.app_name,
) )
@ -60,42 +65,16 @@ scripts = [
] ]
scripts_cm = ConnectionManager()
@api.post(
path='/api/scripts',
)
async def _(
script_id: int = Body(
validation_alias='id',
),
name: str = Body(),
time: str = Body(),
message_number: str = Body(
validation_alias='messageNumber',
),
is_enabled: bool = Body(
validation_alias='isEnabled',
),
):
i = script_id - 1
scripts[i]['name'] = name
scripts[i]['time'] = time
scripts[i]['messageNumber'] = message_number
scripts[i]['isEnabled'] = is_enabled
@api.websocket( @api.websocket(
path='/ws/scripts', path='/ws/scripts',
) )
async def _( async def _(
websocket: WebSocket, websocket: WebSocket,
): ):
await scripts_cm.connect(websocket) await connection_manager.connect(websocket)
try: try:
await scripts_cm.broadcast(scripts) await connection_manager.broadcast(scripts)
while True: while True:
await websocket.receive_json() await connection_manager.broadcast(await websocket.receive_json())
except WebSocketDisconnect: except WebSocketDisconnect:
scripts_cm.disconnect(websocket) connection_manager.disconnect(websocket)