fix: InitService自动合并模板新增字段(解决旧config缺branch问题)

This commit is contained in:
qinglong
2026-06-14 10:39:03 +08:00
parent fb8bf393f2
commit 27115942ea
2 changed files with 19 additions and 2 deletions
+18 -1
View File
@@ -116,7 +116,24 @@ class InitService:
base_config_file = self.config_path / "base_config.yaml"
if base_config_file.exists():
with open(base_config_file, 'r', encoding='utf-8') as f:
self.configs['base'] = yaml.safe_load(f)
loaded = yaml.safe_load(f) or {}
# 合并模板中新增的字段 (不影响用户已修改的值)
template_file = self.config_path / "base_config.yaml.example"
if template_file.exists():
try:
with open(template_file, 'r', encoding='utf-8') as tf:
template = yaml.safe_load(tf) or {}
def _deep_merge(base, tpl):
for k, v in tpl.items():
if k not in base:
base[k] = v
elif isinstance(v, dict) and isinstance(base.get(k), dict):
_deep_merge(base[k], v)
_deep_merge(loaded, template)
self._save_config(base_config_file, loaded)
except Exception:
pass
self.configs['base'] = loaded
logger.debug("基础配置加载成功")
else:
# 从模板复制
+1 -1
View File
@@ -85,7 +85,7 @@ class UpdateService:
cfg = init.get_config("base").get("framework", {})
except Exception:
cfg = {}
self.branch = cfg.get("branch", "dev")
self.branch = cfg.get("branch", "main")
self.repo_url = cfg.get("repo_url", "https://git.yeij.top/AskaEth/SenSu").rstrip("/")
self.repo_name = self.repo_url.rstrip("/").split("/")[-1]
# ZIP 下载地址: Gitea 格式