05f07ee544
Simplify runtime configuration and remove legacy database and settings surface so new installs are easier to operate. Refresh deployment assets, docs, and order execution behavior to keep the packaged app aligned with the current backend. Made-with: Cursor
99 lines
2.8 KiB
Python
99 lines
2.8 KiB
Python
"""
|
|
应用主配置
|
|
"""
|
|
import os
|
|
|
|
class MetaConfig(type):
|
|
# ==================== 服务配置 ====================
|
|
# 服务启动参数通常由环境变量或命令行参数决定,不建议从数据库读取
|
|
|
|
@property
|
|
def HOST(cls):
|
|
return os.getenv('PYTHON_API_HOST', '0.0.0.0')
|
|
|
|
@property
|
|
def PORT(cls):
|
|
return int(os.getenv('PYTHON_API_PORT', 5000))
|
|
|
|
@property
|
|
def DEBUG(cls):
|
|
return os.getenv('PYTHON_API_DEBUG', 'False').lower() == 'true'
|
|
|
|
@property
|
|
def APP_NAME(cls):
|
|
return 'QuantDinger Python API'
|
|
|
|
@property
|
|
def VERSION(cls):
|
|
return '2.0.0'
|
|
|
|
# ==================== 认证配置 ====================
|
|
@property
|
|
def SECRET_KEY(cls):
|
|
return os.getenv('SECRET_KEY', 'quantdinger-secret-key-change-me')
|
|
|
|
@property
|
|
def ADMIN_USER(cls):
|
|
return os.getenv('ADMIN_USER', 'quantdinger')
|
|
|
|
@property
|
|
def ADMIN_PASSWORD(cls):
|
|
return os.getenv('ADMIN_PASSWORD', '123456')
|
|
|
|
# ==================== 日志配置 ====================
|
|
# 日志配置通常在应用启动最早阶段需要,建议保持环境变量
|
|
|
|
@property
|
|
def LOG_LEVEL(cls):
|
|
return os.getenv('LOG_LEVEL', 'INFO')
|
|
|
|
@property
|
|
def LOG_DIR(cls):
|
|
return os.getenv('LOG_DIR', 'logs')
|
|
|
|
@property
|
|
def LOG_FILE(cls):
|
|
return os.getenv('LOG_FILE', 'app.log')
|
|
|
|
@property
|
|
def LOG_MAX_BYTES(cls):
|
|
return int(os.getenv('LOG_MAX_BYTES', 10 * 1024 * 1024))
|
|
|
|
@property
|
|
def LOG_BACKUP_COUNT(cls):
|
|
return int(os.getenv('LOG_BACKUP_COUNT', 5))
|
|
|
|
# ==================== 安全配置 ====================
|
|
|
|
@property
|
|
def RATE_LIMIT(cls):
|
|
from app.utils.config_loader import load_addon_config
|
|
val = load_addon_config().get('app', {}).get('rate_limit')
|
|
return int(val) if val is not None else int(os.getenv('RATE_LIMIT', 100))
|
|
|
|
# ==================== 功能开关 ====================
|
|
|
|
@property
|
|
def ENABLE_CACHE(cls):
|
|
from app.utils.config_loader import load_addon_config
|
|
val = load_addon_config().get('app', {}).get('enable_cache')
|
|
if val is not None:
|
|
return bool(val)
|
|
return os.getenv('ENABLE_CACHE', 'False').lower() == 'true'
|
|
|
|
@property
|
|
def ENABLE_REQUEST_LOG(cls):
|
|
from app.utils.config_loader import load_addon_config
|
|
val = load_addon_config().get('app', {}).get('enable_request_log')
|
|
if val is not None:
|
|
return bool(val)
|
|
return os.getenv('ENABLE_REQUEST_LOG', 'True').lower() == 'true'
|
|
|
|
class Config(metaclass=MetaConfig):
|
|
"""应用配置类"""
|
|
|
|
@classmethod
|
|
def get_log_path(cls) -> str:
|
|
"""获取日志文件完整路径"""
|
|
return os.path.join(cls.LOG_DIR, cls.LOG_FILE)
|