iOSBuildServer/backend/config.py
shen e18f33d60f fix: 认证系统、登录兼容性、运行时配置、钉钉通知及代码清理
- 实现 JWT 认证中间件,保护配置管理和任务删除接口
- 修复 ConfigView 登录按钮(Vue 3 inject 替代 $root)
- 页面刷新时通过 /api/auth/me 校验 token 有效性
- max_concurrent_builds 修改后运行时即时生效
- 实现钉钉 webhook 通知(构建成功/失败自动推送)
- 删除未使用的 useWebSocket composable
- log_streamer 使用 LOG_QUEUE_MAX_SIZE 配置常量
2026-06-08 20:35:05 +08:00

76 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.

"""项目配置 — 从环境变量读取,支持 .env 文件"""
import os
from pathlib import Path
# 自动加载 .env 文件(如果存在)
_env_file = Path(__file__).parent.parent / ".env"
if _env_file.exists():
with open(_env_file) as f:
for line in f:
line = line.strip()
if line and not line.startswith("#") and "=" in line:
key, _, value = line.partition("=")
os.environ.setdefault(key.strip(), value.strip())
# 项目根目录iOS 源码,也作为 AutoPacking 脚本来源)
PROJECT_ROOT = Path(os.getenv("PROJECT_ROOT", "/Users/shen/Work/Code/Readoor"))
# AutoPacking 目录
AUTOPACKING_DIR = PROJECT_ROOT / "AutoPacking"
# config.json 路径
CONFIG_JSON_PATH = AUTOPACKING_DIR / "config.json"
# 打包基础目录
BUILD_BASE_DIR = Path(os.getenv("BUILD_BASE_DIR", "/Users/shen/Documents"))
# Git 分支源码目录
# GIT_SOURCE_BASE: 分支源码的根目录,每个分支一个子目录
# GIT_REMOTE_URL: 远程仓库地址,分支目录不存在时自动 clone
GIT_SOURCE_BASE = Path(os.getenv("GIT_SOURCE_BASE", str(PROJECT_ROOT.parent / "ReadoorBranches")))
GIT_REMOTE_URL = os.getenv("GIT_REMOTE_URL", "")
def get_source_dir(branch: str) -> Path:
"""获取指定分支的源码目录"""
return GIT_SOURCE_BASE / branch
# 需要拷贝的目录和文件
COPY_ITEMS = [
"readoor",
"readoor.xcodeproj",
"readoorTests",
"AutoPacking",
"podfile",
"Pods",
"Podfile.lock",
"readoor.xcworkspace",
]
# 服务端口
BACKEND_PORT = int(os.getenv("BACKEND_PORT", "8000"))
# 数据库路径
DATABASE_URL = f"sqlite:///{Path(__file__).parent / 'build_server.db'}"
# WebSocket 日志队列最大长度
LOG_QUEUE_MAX_SIZE = 1000
# 默认最大并行打包数
DEFAULT_MAX_CONCURRENT_BUILDS = int(os.getenv("MAX_CONCURRENT_BUILDS", "2"))
# 默认打包目录保留时间(小时)
DEFAULT_BUILD_DIR_RETENTION_HOURS = int(os.getenv("BUILD_DIR_RETENTION_HOURS", "24"))
# 打包超时时间(小时)
BUILD_TIMEOUT_HOURS = int(os.getenv("BUILD_TIMEOUT_HOURS", "1"))
# 管理员账号配置
ADMIN_USERNAME = os.getenv("ADMIN_USERNAME", "admin")
ADMIN_PASSWORD = os.getenv("ADMIN_PASSWORD", "admin123")
# JWT 配置
JWT_SECRET = os.getenv("JWT_SECRET", "ios-build-server-secret-key-change-in-production")
JWT_ALGORITHM = "HS256"
JWT_EXPIRE_HOURS = 24