COS 迁移: - 后端签名服务改为 COS HMAC-SHA1 表单直传签名 - config.py: OSS_* 配置项替换为 COS_SECRET_ID/KEY/REGION/BUCKET_NAME/CDN_DOMAIN - upload.py: UploadPolicyResponse 改为 COS 字段 - 前端 useOSSUpload hook: FormData 字段改为 COS 格式 - 前端 api.ts: UploadPolicyResponse 类型对齐 部署配置: - docker-compose.yml: 新增 Nginx + 前端容器,数据卷宿主机持久化 - Nginx: HTTPS + HTTP/2 + SSE 长连接 + API/前端反向代理 - backup.sh: PostgreSQL 每日备份 → 本地 + COS - .env.example: 更新为 COS 配置模板 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
87 lines
2.5 KiB
Python
87 lines
2.5 KiB
Python
"""应用配置"""
|
||
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
|
||
ENVIRONMENT: str = "development" # development | staging | production
|
||
|
||
# CORS(逗号分隔的允许来源列表)
|
||
CORS_ORIGINS: str = "http://localhost:3000"
|
||
|
||
# 数据库
|
||
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
|
||
|
||
# 腾讯云 COS 配置
|
||
COS_SECRET_ID: str = ""
|
||
COS_SECRET_KEY: str = ""
|
||
COS_REGION: str = "ap-guangzhou"
|
||
COS_BUCKET_NAME: str = "miaosi-files-1250000000"
|
||
COS_CDN_DOMAIN: str = "" # CDN 自定义域名,空则用 COS 源站
|
||
|
||
# 邮件 SMTP
|
||
SMTP_HOST: str = ""
|
||
SMTP_PORT: int = 465
|
||
SMTP_USER: str = ""
|
||
SMTP_PASSWORD: str = ""
|
||
SMTP_FROM_NAME: str = "秒思智能审核平台"
|
||
SMTP_USE_SSL: bool = True
|
||
|
||
# 验证码
|
||
VERIFICATION_CODE_EXPIRE_MINUTES: int = 5
|
||
VERIFICATION_CODE_LENGTH: int = 6
|
||
|
||
# 加密密钥
|
||
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()
|