Open Maopaoya M0-M2: 用户体系+权限开关+后台 / 渠道管理 / 单角色扮演(记忆可篡改+世界书+TTS) / 动态小说管线(实体抽取→建档→立绘→世界书注册) / AES-GCM数据加密+登录解密迁移 / 液态玻璃UI
This commit is contained in:
+39
@@ -0,0 +1,39 @@
|
||||
from fastapi import FastAPI, Request
|
||||
from fastapi.responses import FileResponse, JSONResponse
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
|
||||
from .db.session import init_db
|
||||
from .api.routers import auth, admin, channels, characters, chat
|
||||
|
||||
app = FastAPI(title="Open Maopaoya", docs_url="/api/docs", openapi_url="/api/openapi.json")
|
||||
|
||||
for r in (auth.router, admin.router, channels.router, characters.router, chat.router):
|
||||
app.include_router(r, prefix="/api")
|
||||
|
||||
|
||||
@app.on_event("startup")
|
||||
async def startup():
|
||||
await init_db()
|
||||
# 首个管理员
|
||||
from .db.session import SessionLocal
|
||||
from .db import repos
|
||||
from .models.entities import User
|
||||
from .core import security
|
||||
from .core.config import settings
|
||||
import os
|
||||
async with SessionLocal() as db:
|
||||
users = await repos.UserRepo.all(db)
|
||||
if not users:
|
||||
salt = os.urandom(16)
|
||||
db.add(User(username=settings.first_admin_user,
|
||||
password_hash=security.hash_password(settings.first_admin_pass),
|
||||
kdf_salt=salt.hex(), is_admin=True))
|
||||
await db.commit()
|
||||
|
||||
|
||||
@app.exception_handler(Exception)
|
||||
async def error_handler(request: Request, exc: Exception):
|
||||
return JSONResponse(status_code=500, content={"detail": str(exc)[:300]})
|
||||
|
||||
|
||||
app.mount("/", StaticFiles(directory="web", html=True), name="web")
|
||||
Reference in New Issue
Block a user