|
|
@ -4,6 +4,8 @@ from contextlib import asynccontextmanager |
|
|
|
from pydantic import BaseModel, Field |
|
|
|
from typing import Sequence |
|
|
|
from dotenv import load_dotenv |
|
|
|
from fastapi.middleware.cors import CORSMiddleware |
|
|
|
from fastapi.responses import ORJSONResponse |
|
|
|
import asyncio |
|
|
|
import os |
|
|
|
from clickhouse_sqlalchemy import ( |
|
|
@ -36,8 +38,8 @@ class HostBase(BaseModel): |
|
|
|
url: str |
|
|
|
|
|
|
|
class HostDescription(BaseModel): |
|
|
|
description: str | None |
|
|
|
delay: int | None |
|
|
|
description: str | None =None |
|
|
|
delay: int | None =None |
|
|
|
|
|
|
|
|
|
|
|
class HostLive(BaseModel): |
|
|
@ -123,6 +125,7 @@ class BackgroundTask: |
|
|
|
bgtask = BackgroundTask() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@asynccontextmanager |
|
|
|
async def lifespan(app: FastAPI): |
|
|
|
# Load the ML model |
|
|
@ -139,6 +142,13 @@ async def lifespan(app: FastAPI): |
|
|
|
|
|
|
|
app = FastAPI(lifespan=lifespan) |
|
|
|
|
|
|
|
app.add_middleware( |
|
|
|
CORSMiddleware, |
|
|
|
allow_origins=["*"], |
|
|
|
allow_credentials=True, |
|
|
|
allow_methods=["*"], |
|
|
|
allow_headers=["*"], |
|
|
|
) |
|
|
|
|
|
|
|
@app.get("/") |
|
|
|
async def show_hosts() -> Sequence[HostSchema]: |
|
|
|