2026-01-25 19:27:44 +08:00

101 lines
2.7 KiB
Python

"""
Creative Studio 配置管理
支持环境变量和配置文件
"""
from pydantic_settings import BaseSettings
from functools import lru_cache
from typing import List
import os
class Settings(BaseSettings):
"""应用配置"""
# ============================================
# 应用配置
# ============================================
app_name: str = "Creative Studio"
app_version: str = "1.0.0"
debug: bool = True
environment: str = "development"
# 服务器配置
host: str = "0.0.0.0"
port: int = 8000
# ============================================
# GLM API 配置
# ============================================
zai_api_key: str
zai_model: str = "glm-4.7"
# ============================================
# 数据库配置
# ============================================
mongodb_url: str = "mongodb://localhost:27017"
mongodb_database: str = "creative_studio"
redis_url: str = "redis://localhost:6379/0"
# ============================================
# 安全配置
# ============================================
secret_key: str
algorithm: str = "HS256"
access_token_expire_minutes: int = 60
refresh_token_expire_days: int = 7
# ============================================
# 文件存储配置
# ============================================
storage_path: str = "./storage"
max_file_size: int = 100 # MB
# ============================================
# Celery 配置
# ============================================
celery_broker_url: str = "redis://localhost:6379/1"
celery_result_backend: str = "redis://localhost:6379/2"
# ============================================
# CORS 配置
# ============================================
allowed_origins: str = "http://localhost:5173,http://localhost:3000"
# ============================================
# 日志配置
# ============================================
log_level: str = "INFO"
log_file: str = "./logs/app.log"
# ============================================
# Skill 存储配置
# ============================================
skills_dir: str = "./skills_storage"
@property
def cors_origins(self) -> List[str]:
"""解析 CORS 允许的源"""
return [origin.strip() for origin in self.allowed_origins.split(",")]
class Config:
env_file = ".env"
env_file_encoding = "utf-8"
case_sensitive = False
@lru_cache()
def get_settings() -> Settings:
"""
获取配置单例
使用:
from app.config import settings
settings = get_settings()
"""
return Settings()
# 导出配置实例
settings = get_settings()