Your Name 8eb8100cf4 fix: P0 安全加固 + 前端错误边界 + ESLint 修复
后端:
- 实现登出 API(清除 refresh token)
- 清除 videos.py 中已被 Celery 任务取代的死代码
- 添加速率限制中间件(60次/分钟,登录10次/分钟)
- 添加 SECRET_KEY/ENCRYPTION_KEY 默认值警告
- OSS STS 方法回退到 Policy 签名(不再抛异常)

前端:
- 添加全局 404/error/loading 页面
- 添加三端 error.tsx + loading.tsx 错误边界
- 修复 useId 条件调用违反 Hooks 规则
- 修复未转义引号和 Image 命名冲突
- 添加 ESLint 配置

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-09 17:18:04 +08:00

71 lines
2.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""应用配置"""
import warnings
from pydantic_settings import BaseSettings
from functools import lru_cache
class Settings(BaseSettings):
"""应用设置"""
# 应用
APP_NAME: str = "秒思智能审核平台"
APP_VERSION: str = "1.0.0"
DEBUG: bool = False
# 数据库
DATABASE_URL: str = "postgresql+asyncpg://postgres:postgres@localhost:5432/miaosi"
# Redis
REDIS_URL: str = "redis://localhost:6379/0"
# JWT
SECRET_KEY: str = "your-secret-key-change-in-production"
ALGORITHM: str = "HS256"
ACCESS_TOKEN_EXPIRE_MINUTES: int = 30
# AI 服务(使用 OneAPI/OneInAll 等中转服务商,不直连厂商)
# 中转服务商统一了不同 AI 厂商的接口,只需配置中转商的 API
AI_PROVIDER: str = "oneapi" # oneapi | oneinall | openrouter 等中转服务商
AI_API_KEY: str = "" # 中转服务商的 API Key
AI_API_BASE_URL: str = "" # 中转服务商的 Base URL如 https://api.oneinall.ai/v1
# 阿里云 OSS 配置
OSS_ACCESS_KEY_ID: str = ""
OSS_ACCESS_KEY_SECRET: str = ""
OSS_ENDPOINT: str = "oss-cn-hangzhou.aliyuncs.com"
OSS_BUCKET_NAME: str = "miaosi-files"
OSS_BUCKET_DOMAIN: str = "" # 公开访问域名,如 https://miaosi-files.oss-cn-hangzhou.aliyuncs.com
# 加密密钥
ENCRYPTION_KEY: str = ""
# 文件上传限制
MAX_FILE_SIZE_MB: int = 500 # 最大文件大小 500MB
def __init__(self, **kwargs):
super().__init__(**kwargs)
if self.SECRET_KEY == "your-secret-key-change-in-production":
warnings.warn(
"SECRET_KEY 使用默认值,请在 .env 中设置安全的密钥!",
UserWarning,
stacklevel=2,
)
if not self.ENCRYPTION_KEY:
warnings.warn(
"ENCRYPTION_KEY 未设置API 密钥将无法安全存储!",
UserWarning,
stacklevel=2,
)
class Config:
env_file = ".env"
case_sensitive = True
@lru_cache()
def get_settings() -> Settings:
"""获取配置单例"""
return Settings()
settings = get_settings()