- 新增皮肤包上传/列表/删除 API(基于 upload_key) - 构建时自动解压 ZIP 皮肤包应用到项目 - 配置和皮肤包迁移到 backend/data/ 目录,切分支不会丢失 - 旧式目录皮肤自动迁移为 ZIP 格式 - 前端皮肤包管理 UI(上传、删除、下拉选择) - .gitignore 排除运行时数据目录
83 lines
2.7 KiB
Python
83 lines
2.7 KiB
Python
"""项目配置 — 从环境变量读取,支持 .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"
|
||
|
||
# 持久化数据目录(不随分支变化,存放运行时配置和皮肤包)
|
||
DATA_DIR = Path(os.getenv("DATA_DIR", str(Path(__file__).parent / "data")))
|
||
DATA_DIR.mkdir(parents=True, exist_ok=True)
|
||
|
||
# config.json 路径(持久化,不随分支变化)
|
||
CONFIG_JSON_PATH = DATA_DIR / "config.json"
|
||
|
||
# 皮肤包存储目录(持久化,不随分支变化)
|
||
SKINS_DIR = DATA_DIR / "skins"
|
||
|
||
# 打包基础目录
|
||
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
|