2024-07-16 15:55:45 +02:00
|
|
|
from contextlib import asynccontextmanager
|
|
|
|
|
|
|
|
|
|
from fastapi import FastAPI
|
|
|
|
|
|
|
|
|
|
from poo import PooRecorder
|
|
|
|
|
|
|
|
|
|
recorder = PooRecorder()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@asynccontextmanager
|
2024-07-17 16:44:30 +02:00
|
|
|
async def _lifespan(_app: FastAPI): # noqa: ANN202
|
2024-07-16 15:55:45 +02:00
|
|
|
await recorder.start()
|
|
|
|
|
yield
|
|
|
|
|
await recorder.stop()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app = FastAPI(lifespan=_lifespan)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.put("/record/s={status}")
|
|
|
|
|
async def record(status: str) -> dict:
|
2024-07-17 16:44:30 +02:00
|
|
|
await recorder.record(status)
|
2024-07-16 15:55:45 +02:00
|
|
|
return {"status": status}
|