- 修复Redis认证 (配置密码) - 启动Python管理后台 (端口9531, 15个功能开关) - 统一版本号 0.2.7 - 更新docker-compose.yml (镜像版本/Redis URL/Admin服务)
69 lines
1.6 KiB
Python
69 lines
1.6 KiB
Python
"""
|
|
Feature Flags 统一管理 v2.1.0
|
|
环境变量 + 配置文件双层控制
|
|
"""
|
|
|
|
import os
|
|
from typing import Dict
|
|
|
|
|
|
class FeatureFlags:
|
|
"""功能开关管理器"""
|
|
|
|
# 所有功能及其默认值
|
|
DEFAULTS: Dict[str, bool] = {
|
|
# 核心功能
|
|
"quark_pid": True,
|
|
"seo": True,
|
|
"link_monitor": True,
|
|
|
|
# 增强功能
|
|
"tmdb": True,
|
|
"telegram_bot": False,
|
|
"subscription": False,
|
|
"alist": False,
|
|
|
|
# 转存平台
|
|
"transfer_quark": True,
|
|
"transfer_baidu": False,
|
|
"transfer_aliyun": False,
|
|
"transfer_uc": False,
|
|
"transfer_xunlei": False,
|
|
"transfer_pan115": False,
|
|
"transfer_pan123": False,
|
|
"transfer_cloud189": False,
|
|
}
|
|
|
|
def __init__(self):
|
|
self._flags: Dict[str, bool] = {}
|
|
self._load()
|
|
|
|
def _load(self):
|
|
for key, default in self.DEFAULTS.items():
|
|
env_key = f"FEATURE_{key.upper()}"
|
|
val = os.getenv(env_key, str(default)).lower()
|
|
self._flags[key] = val in ("true", "1", "yes", "on")
|
|
|
|
def is_enabled(self, feature: str) -> bool:
|
|
return self._flags.get(feature, False)
|
|
|
|
def enable(self, feature: str):
|
|
self._flags[feature] = True
|
|
|
|
def disable(self, feature: str):
|
|
self._flags[feature] = False
|
|
|
|
def list_all(self) -> Dict[str, bool]:
|
|
return dict(self._flags)
|
|
|
|
def get_enabled_platforms(self) -> list:
|
|
return [
|
|
k.replace("transfer_", "")
|
|
for k, v in self._flags.items()
|
|
if k.startswith("transfer_") and v
|
|
]
|
|
|
|
|
|
# 全局单例
|
|
features = FeatureFlags()
|