up
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
"""应用配置:环境变量(.env)+ 业务参数(config.yaml)"""
|
||||
from functools import lru_cache
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import yaml
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent # server/
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
"""环境配置(连接串、密钥等,均不入库)"""
|
||||
|
||||
model_config = SettingsConfigDict(
|
||||
env_file=BASE_DIR / ".env", env_file_encoding="utf-8", extra="ignore"
|
||||
)
|
||||
|
||||
# 服务
|
||||
app_env: str = "dev"
|
||||
app_host: str = "0.0.0.0"
|
||||
app_port: int = 8000
|
||||
|
||||
# 数据库 / Redis
|
||||
database_url: str = "mysql+aiomysql://root:root@127.0.0.1:3306/video?charset=utf8mb4"
|
||||
redis_url: str = "redis://127.0.0.1:6379/0"
|
||||
celery_broker_url: str = "redis://127.0.0.1:6379/1"
|
||||
celery_result_backend: str = "redis://127.0.0.1:6379/2"
|
||||
|
||||
# JWT
|
||||
jwt_secret: str = "please-change-me-in-production"
|
||||
jwt_algorithm: str = "HS256"
|
||||
access_token_ttl: int = 2 * 3600
|
||||
refresh_token_ttl: int = 30 * 24 * 3600
|
||||
admin_token_ttl: int = 12 * 3600
|
||||
|
||||
# 对象存储
|
||||
oss_endpoint: str = ""
|
||||
oss_bucket: str = ""
|
||||
oss_access_key_id: str = ""
|
||||
oss_access_key_secret: str = ""
|
||||
|
||||
# 支付渠道
|
||||
alipay_app_id: str = ""
|
||||
alipay_private_key: str = ""
|
||||
alipay_public_key: str = ""
|
||||
alipay_notify_url: str = ""
|
||||
alipay_return_url: str = ""
|
||||
wechat_mchid: str = ""
|
||||
wechat_app_id: str = ""
|
||||
wechat_api_v3_key: str = ""
|
||||
wechat_private_key: str = ""
|
||||
wechat_cert_serial_no: str = "" # 商户 API 证书序列号
|
||||
wechat_platform_cert: str = "" # 微信支付平台证书(PEM,回调验签用)
|
||||
wechat_notify_url: str = ""
|
||||
wechat_api_base: str = "https://api.mch.weixin.qq.com"
|
||||
tron_api_key: str = ""
|
||||
|
||||
# 短信 / 邮件
|
||||
sms_access_key_id: str = ""
|
||||
sms_access_key_secret: str = ""
|
||||
sms_sign_name: str = ""
|
||||
smtp_host: str = ""
|
||||
smtp_port: int = 465
|
||||
smtp_user: str = ""
|
||||
smtp_password: str = ""
|
||||
|
||||
|
||||
@lru_cache
|
||||
def get_settings() -> Settings:
|
||||
return Settings()
|
||||
|
||||
|
||||
@lru_cache
|
||||
def get_biz_config() -> dict[str, Any]:
|
||||
"""业务参数(积分/会员/激励等默认值,后台 system_configs 可覆盖部分项)"""
|
||||
with open(BASE_DIR / "config.yaml", encoding="utf-8") as f:
|
||||
return yaml.safe_load(f) or {}
|
||||
|
||||
|
||||
settings = get_settings()
|
||||
biz_config = get_biz_config()
|
||||
Reference in New Issue
Block a user