Compare commits

...

2 Commits

Author SHA1 Message Date
726dc3ef35 feat:配置支持热更新 2025-09-25 00:06:11 +08:00
9dbce60c49 fix:删除无用包 2025-09-24 23:30:46 +08:00
2 changed files with 38 additions and 3 deletions

View File

@ -7,7 +7,8 @@ const fsp = fs.promises;
const pluginConfigPath = Path.defaultConfigPath;
const dataConfigPath = Path.config;
const configFile = path.join(dataConfigPath, 'config.json');
let configCache = {}; // 缓存
let configCache = {};
let watchers = [];
/**
* 初始化配置
@ -80,9 +81,43 @@ async function init() {
}
}
/**
* 配置文件热更新
*/
function watchConfigs() {
for (const w of watchers) {
w.close();
}
watchers = [];
fsp.readdir(dataConfigPath).then((files) => {
files
.filter((f) => f.endsWith('.json'))
.forEach((file) => {
const filePath = path.join(dataConfigPath, file);
const watcher = fs.watch(filePath, async (eventType) => {
if (eventType === 'change') {
try {
const data = await fc.readJSON(filePath);
const name = path.basename(file, '.json');
configCache[name] = data;
if (configCache.debug) {
logger.info(`[crystelf-plugin] 配置热更新: ${file}`);
}
} catch (e) {
logger.warn(`[crystelf-plugin] 热更新读取失败 ${file}:`, e);
}
}
});
watchers.push(watcher);
});
});
}
const configControl = {
async init() {
await init();
watchConfigs();
},
get(key) {
@ -126,6 +161,7 @@ const configControl = {
async reload() {
await init();
watchConfigs();
return true;
},
};

View File

@ -20,8 +20,7 @@
"chalk": "^5.4.1",
"form-data": "^4.0.2",
"openai": "^4.89.0",
"rss-parser": "^3.13.0",
"ws": "^8.18.1"
"rss-parser": "^3.13.0"
},
"imports": {},
"devDependencies": {