47 lines
1.3 KiB
Python
47 lines
1.3 KiB
Python
"""打包选择 API"""
|
|
from fastapi import APIRouter
|
|
|
|
from .config import load_config
|
|
|
|
router = APIRouter(prefix="/api", tags=["apps"])
|
|
|
|
# 每个 App 都只能使用明确允许的 Scheme。
|
|
_APP_SCHEME_RULES = {
|
|
"申学": ("readoorShenXue",),
|
|
"申学APP": ("readoorShenXue",),
|
|
"英汉大词典测试": ("readoorDict",),
|
|
"英汉大词典": ("readoorDict",),
|
|
}
|
|
_DEFAULT_SCHEME_NAMES = ("readoor31", "readoor31OtherPay")
|
|
|
|
|
|
def get_allowed_scheme_names(app: dict) -> tuple[str, ...]:
|
|
"""返回 App 可使用的 Scheme 名称。"""
|
|
return _APP_SCHEME_RULES.get(app.get("name", ""), _DEFAULT_SCHEME_NAMES)
|
|
|
|
|
|
@router.get("/apps")
|
|
async def get_apps_for_build():
|
|
"""获取 apps 列表(供打包选择)"""
|
|
config = load_config()
|
|
apps = {}
|
|
for app_id, app in config.get("apps", {}).items():
|
|
app_data = app.copy()
|
|
app_data["allowed_scheme_names"] = list(get_allowed_scheme_names(app))
|
|
apps[app_id] = app_data
|
|
return apps
|
|
|
|
|
|
@router.get("/schemes")
|
|
async def get_schemes_for_build():
|
|
"""获取 schemes 列表(供打包选择)"""
|
|
config = load_config()
|
|
return config.get("schemes", {})
|
|
|
|
|
|
@router.get("/branches")
|
|
async def get_branches_for_build():
|
|
"""获取分支列表(供打包选择)"""
|
|
config = load_config()
|
|
return config.get("branches", ["main"])
|