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

...

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 os
from fastapi import FastAPI
from fastapi.responses import HTMLResponse
from fastapi import FastAPI, Body
from fastapi.websockets import WebSocket, WebSocketDisconnect
import config
@ -40,9 +38,6 @@ class ConnectionManager:
asyncio.ensure_future(connection.send_json(data))
connection_manager = ConnectionManager()
api = FastAPI(
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(
path='/ws/scripts',
)
async def _(
websocket: WebSocket,
):
await connection_manager.connect(websocket)
await scripts_cm.connect(websocket)
try:
await connection_manager.broadcast(scripts)
await scripts_cm.broadcast(scripts)
while True:
await connection_manager.broadcast(await websocket.receive_json())
await websocket.receive_json()
except WebSocketDisconnect:
connection_manager.disconnect(websocket)
scripts_cm.disconnect(websocket)