Files
ozon-seller-kit/server/config/settings.py
T

69 lines
2.3 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.
from functools import lru_cache
from pathlib import Path
from dotenv import load_dotenv
from pydantic_settings import BaseSettings, SettingsConfigDict
# .env 在仓库根(server/ 的上一级),供各部分共用
_ROOT_DIR = Path(__file__).resolve().parents[2]
load_dotenv(_ROOT_DIR / ".env")
class Settings(BaseSettings):
"""运行时与密钥。模型清单见 config/models.yaml。"""
model_config = SettingsConfigDict(
env_file=str(_ROOT_DIR / ".env"),
env_file_encoding="utf-8",
extra="ignore",
)
# ── AI 密钥 ──
deepseek_api_key: str = ""
openai_api_key: str = ""
dashscope_api_key: str = ""
# 华北2(北京)业务空间时需填:https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1
dashscope_base_http_api_url: str = ""
# ── 运行 ──
host: str = "127.0.0.1"
port: int = 8800
cors_origins: str = ""
# ── V2:数据层 ──
# 本地过渡用 SQLite;上线切 PostgreSQLpostgresql+asyncpg://user:pass@host:5432/ozon_seller
database_url: str = "sqlite+aiosqlite:///./data/app.db"
# ── V2:鉴权 ──
app_token: str = "" # MVP 单用户登录 token(换发 JWT 用)
secret_key: str = "" # 店铺凭证 AES-GCM 加密密钥 + JWT 签名密钥
jwt_expire_minutes: int = 60 * 24 * 7 # JWT 有效期(默认 7 天)
# ── V2:七牛(图片存储)──
qiniu_access_key: str = ""
qiniu_secret_key: str = ""
qiniu_bucket: str = ""
qiniu_domain: str = "" # 绑定域名,如 https://cdn.example.com
# 为空时用本地文件系统兜底(开发期),不为空时走七牛
storage_backend: str = "local" # local | qiniu
# ── V2:对外地址(插件/前端回写、生成图回调)──
app_base_url: str = "http://127.0.0.1:8800"
@property
def cors_origin_list(self) -> list[str]:
if not self.cors_origins.strip():
return []
return [o.strip() for o in self.cors_origins.split(",") if o.strip()]
@property
def use_qiniu(self) -> bool:
return self.storage_backend == "qiniu" and bool(
self.qiniu_access_key and self.qiniu_secret_key and self.qiniu_bucket
)
@lru_cache
def get_settings() -> Settings:
return Settings()