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

...

2 Коммитов

Автор SHA1 Сообщение Дата
b6661d3ebd Merge remote-tracking branch 'origin/main'
# Conflicts:
#	api/main.py
2024-08-26 22:43:19 +03:00
b4f5a63d31 Разработана конечная точка для прослушивания сценариев 2024-08-26 22:42:20 +03:00

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

@ -1,8 +1,6 @@
import asyncio import asyncio
import os
from fastapi import FastAPI from fastapi import FastAPI, Body
from fastapi.responses import HTMLResponse
from fastapi.websockets import WebSocket, WebSocketDisconnect from fastapi.websockets import WebSocket, WebSocketDisconnect
import config import config
@ -40,9 +38,6 @@ 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,
) )
@ -65,16 +60,42 @@ 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 connection_manager.connect(websocket) await scripts_cm.connect(websocket)
try: try:
await connection_manager.broadcast(scripts) await scripts_cm.broadcast(scripts)
while True: while True:
await connection_manager.broadcast(await websocket.receive_json()) await websocket.receive_json()
except WebSocketDisconnect: except WebSocketDisconnect:
connection_manager.disconnect(websocket) scripts_cm.disconnect(websocket)