- Added user authentication and registration endpoints with JWT support. - Created tag management routes for creating and deleting tags. - Implemented value-added service (VAS) endpoints for managing storage packs and orders. - Developed WebDAV account management routes for creating, updating, and deleting accounts. - Introduced slave router for handling file uploads, downloads, and aria2 task management. - Enhanced JWT utility functions for token creation and secret key management. - Established lifespan management for FastAPI application startup and shutdown processes. - Integrated password handling utilities with Argon2 hashing and two-factor authentication support.
33 lines
975 B
Python
33 lines
975 B
Python
from sqlmodel import SQLModel
|
|
from sqlalchemy.ext.asyncio import AsyncEngine, create_async_engine
|
|
from sqlmodel.ext.asyncio.session import AsyncSession
|
|
from utils.conf import appmeta
|
|
from sqlalchemy.orm import sessionmaker
|
|
from typing import AsyncGenerator
|
|
|
|
ASYNC_DATABASE_URL = appmeta.database_url
|
|
|
|
engine: AsyncEngine = create_async_engine(
|
|
ASYNC_DATABASE_URL,
|
|
echo=appmeta.debug,
|
|
connect_args={
|
|
"check_same_thread": False
|
|
} if ASYNC_DATABASE_URL.startswith("sqlite") else None,
|
|
future=True,
|
|
# pool_size=POOL_SIZE,
|
|
# max_overflow=64,
|
|
)
|
|
|
|
_async_session_factory = sessionmaker(engine, class_=AsyncSession)
|
|
|
|
async def get_session() -> AsyncGenerator[AsyncSession, None]:
|
|
async with _async_session_factory() as session:
|
|
yield session
|
|
|
|
async def init_db(
|
|
url: str = ASYNC_DATABASE_URL
|
|
):
|
|
"""创建数据库结构"""
|
|
async with engine.begin() as conn:
|
|
await conn.run_sync(SQLModel.metadata.create_all)
|
|
|