feat: 全屏个股详情预览 + Tailwind 改版 + 账号鉴权
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
"""应用配置(pydantic-settings)。可由 .env / 环境变量覆盖。"""
|
||||
from pydantic import model_validator
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
|
||||
@@ -7,8 +8,18 @@ class Settings(BaseSettings):
|
||||
|
||||
app_name: str = "Stock Backtest"
|
||||
|
||||
# 默认 SQLite 零配置;切 Postgres/TimescaleDB 只改这一行
|
||||
database_url: str = "sqlite+aiosqlite:///./stock.db"
|
||||
# 开发、测试、生产统一使用 PostgreSQL,避免不同数据库行为产生偏差。
|
||||
database_url: str = "postgresql+asyncpg://postgres:postgres@localhost:5432/stock"
|
||||
|
||||
# ---- 鉴权 ----
|
||||
auth_cookie_name: str = "stock_session"
|
||||
auth_cookie_secure: bool = False # 生产 HTTPS 必须覆盖为 true
|
||||
auth_session_hours: int = 12
|
||||
auth_max_failed_logins: int = 5
|
||||
auth_lock_minutes: int = 15
|
||||
auth_min_password_length: int = 12
|
||||
cors_origins: str = "http://localhost:5173"
|
||||
expose_api_docs: bool = True
|
||||
|
||||
# 真实数据源
|
||||
tushare_token: str = "" # Tushare Pro token(主数据源)
|
||||
@@ -33,5 +44,17 @@ class Settings(BaseSettings):
|
||||
commission_min: float = 5.0 # 最低 5 元
|
||||
slippage_rate: float = 0.0005 # 滑点近似(按价格比例)
|
||||
|
||||
@model_validator(mode="after")
|
||||
def require_postgresql(self) -> "Settings":
|
||||
if not self.database_url.startswith("postgresql+asyncpg://"):
|
||||
raise ValueError("DATABASE_URL 必须使用 postgresql+asyncpg://,本项目不再支持 SQLite")
|
||||
if self.auth_session_hours <= 0:
|
||||
raise ValueError("AUTH_SESSION_HOURS 必须大于 0")
|
||||
return self
|
||||
|
||||
@property
|
||||
def allowed_origins(self) -> list[str]:
|
||||
return [origin.strip() for origin in self.cors_origins.split(",") if origin.strip()]
|
||||
|
||||
|
||||
settings = Settings()
|
||||
|
||||
Reference in New Issue
Block a user