fix: PluginService自动从.example模板创建config.yaml (Windows兼容)

根因: Sentinel的config.yaml被gitignore, 首次运行时
load_plugin()要求config.yaml存在才能继续, 但Sentinel的
自动复制逻辑在initialize()中, 太晚了。

修复: PluginService.load_plugin()检测缺失时自动复制模板

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
qinglong
2026-06-14 10:24:08 +08:00
parent cb6beca067
commit 00c97e4af2
2 changed files with 11 additions and 4 deletions
+1
View File
@@ -4,6 +4,7 @@ import logging
import asyncio import asyncio
import os import os
import time import time
import shutil
import yaml import yaml
import urllib.request import urllib.request
import json as _json import json as _json
+10 -4
View File
@@ -312,12 +312,18 @@ class PluginService:
logger.error(f"插件目录不存在: {plugin_path}") logger.error(f"插件目录不存在: {plugin_path}")
return False return False
# 检查插件配置文件 # 检查插件配置文件 (自动从 .example 模板创建)
config_file = plugin_path / "config.yaml" config_file = plugin_path / "config.yaml"
if not config_file.exists(): if not config_file.exists():
logger.error(f"插件配置文件不存在: {config_file}") template = plugin_path / "config.yaml.example"
return False if template.exists():
import shutil as _shutil
_shutil.copy(template, config_file)
logger.info(f"📋 从模板创建插件配置: {config_file}")
else:
logger.error(f"插件配置文件不存在: {config_file}")
return False
# 加载插件配置 # 加载插件配置
with open(config_file, 'r', encoding='utf-8') as f: with open(config_file, 'r', encoding='utf-8') as f:
plugin_config = yaml.safe_load(f) plugin_config = yaml.safe_load(f)