mirror of
https://github.com/Jerryplusy/crystelf-plugin.git
synced 2025-10-14 13:49:18 +00:00
Compare commits
No commits in common. "726dc3ef354e91b4254896423d8b21ccc964bfe5" and "067954c06fa91a06e2ae96de2ef24bc582d7bb1a" have entirely different histories.
726dc3ef35
...
067954c06f
@ -7,8 +7,7 @@ const fsp = fs.promises;
|
|||||||
const pluginConfigPath = Path.defaultConfigPath;
|
const pluginConfigPath = Path.defaultConfigPath;
|
||||||
const dataConfigPath = Path.config;
|
const dataConfigPath = Path.config;
|
||||||
const configFile = path.join(dataConfigPath, 'config.json');
|
const configFile = path.join(dataConfigPath, 'config.json');
|
||||||
let configCache = {};
|
let configCache = {}; // 缓存
|
||||||
let watchers = [];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化配置
|
* 初始化配置
|
||||||
@ -81,43 +80,9 @@ 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 = {
|
const configControl = {
|
||||||
async init() {
|
async init() {
|
||||||
await init();
|
await init();
|
||||||
watchConfigs();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
get(key) {
|
get(key) {
|
||||||
@ -161,7 +126,6 @@ const configControl = {
|
|||||||
|
|
||||||
async reload() {
|
async reload() {
|
||||||
await init();
|
await init();
|
||||||
watchConfigs();
|
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -20,7 +20,8 @@
|
|||||||
"chalk": "^5.4.1",
|
"chalk": "^5.4.1",
|
||||||
"form-data": "^4.0.2",
|
"form-data": "^4.0.2",
|
||||||
"openai": "^4.89.0",
|
"openai": "^4.89.0",
|
||||||
"rss-parser": "^3.13.0"
|
"rss-parser": "^3.13.0",
|
||||||
|
"ws": "^8.18.1"
|
||||||
},
|
},
|
||||||
"imports": {},
|
"imports": {},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user