steam-server/app/main.py

43 lines
954 B
Python
Raw Permalink Normal View History

2024-12-12 20:04:36 +08:00
from app.middleware.cors import add_cors_middleware
2024-12-17 20:07:29 +08:00
from app.routes import stream
2024-12-12 20:04:36 +08:00
from app.tasks.cleanup_task import cleanup_streams
from fastapi import FastAPI
from contextlib import asynccontextmanager
import asyncio
2024-12-16 14:31:28 +08:00
from linxyun.core import Linxyun
from linxyun.config import Config, Upload
2024-12-12 20:04:36 +08:00
@asynccontextmanager
async def lifespan(app: FastAPI):
# 启动定时清理任务
asyncio.create_task(cleanup_streams())
yield # FastAPI 会在这里执行应用关闭时的清理任务
print("停止服务")
2024-12-16 14:31:28 +08:00
# 创建 config
config = Config(
2024-12-17 20:07:29 +08:00
entCode="56",
2024-12-16 14:31:28 +08:00
project="smartroadlamp",
role={
"1101": ["/**"],
"1102": ["/**"]
},
white_list=[
"/**"
],
upload=Upload(img_quality=0.5)
)
linxyun = Linxyun(config)
2024-12-12 20:04:36 +08:00
app = FastAPI(lifespan=lifespan)
# 添加跨域中间件
add_cors_middleware(app)
2024-12-13 18:21:25 +08:00
# 添加鉴权中间件
2024-12-17 20:07:29 +08:00
# linxyun.add_security_middleware(app)
2024-12-16 14:31:28 +08:00
2024-12-12 20:04:36 +08:00
app.include_router(stream.router)
2024-12-13 18:21:25 +08:00