mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
fix: hot reload
This commit is contained in:
parent
b99fb247ac
commit
dde093d321
@ -53,12 +53,13 @@ export abstract class ConfigBase<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
save(configData: T = this.configData as T) {
|
save(newConfigData: T = this.configData as T) {
|
||||||
const logger = this.coreContext.context.logger;
|
const logger = this.coreContext.context.logger;
|
||||||
const selfInfo = this.coreContext.selfInfo;
|
const selfInfo = this.coreContext.selfInfo;
|
||||||
|
this.configData = newConfigData;
|
||||||
const configPath = this.getConfigPath(selfInfo.uin);
|
const configPath = this.getConfigPath(selfInfo.uin);
|
||||||
try {
|
try {
|
||||||
fs.writeFileSync(configPath, JSON.stringify(configData, this.getKeys(), 2));
|
fs.writeFileSync(configPath, JSON.stringify(newConfigData, this.getKeys(), 2));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
logger.logError(`保存配置文件 ${configPath} 时发生错误:`, e.message);
|
logger.logError(`保存配置文件 ${configPath} 时发生错误:`, e.message);
|
||||||
}
|
}
|
||||||
|
@ -116,6 +116,7 @@ export class NapCatOneBot11Adapter {
|
|||||||
await WebUiDataRuntime.setOnOB11ConfigChanged(async (newConfig: OB11Config) => {
|
await WebUiDataRuntime.setOnOB11ConfigChanged(async (newConfig: OB11Config) => {
|
||||||
const prev = this.configLoader.configData;
|
const prev = this.configLoader.configData;
|
||||||
this.configLoader.save(newConfig);
|
this.configLoader.save(newConfig);
|
||||||
|
this.context.logger.log(`OneBot11 配置更改:${JSON.stringify(prev)} -> ${JSON.stringify(newConfig)}`)
|
||||||
await this.reloadNetwork(prev, newConfig);
|
await this.reloadNetwork(prev, newConfig);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -126,7 +127,7 @@ export class NapCatOneBot11Adapter {
|
|||||||
HTTP上报服务 ${now.http.enablePost ? '已启动' : '未启动'}, 上报地址: ${now.http.postUrls}
|
HTTP上报服务 ${now.http.enablePost ? '已启动' : '未启动'}, 上报地址: ${now.http.postUrls}
|
||||||
WebSocket服务 ${now.ws.enable ? '已启动' : '未启动'}, ${now.ws.host}:${now.ws.port}
|
WebSocket服务 ${now.ws.enable ? '已启动' : '未启动'}, ${now.ws.host}:${now.ws.port}
|
||||||
WebSocket反向服务 ${now.reverseWs.enable ? '已启动' : '未启动'}, 反向地址: ${now.reverseWs.urls}`;
|
WebSocket反向服务 ${now.reverseWs.enable ? '已启动' : '未启动'}, 反向地址: ${now.reverseWs.urls}`;
|
||||||
this.context.logger.log(`[Notice] [OneBot11] 热重载完成 ${serviceInfo}`);
|
this.context.logger.log(`[Notice] [OneBot11] 热重载 ${serviceInfo}`);
|
||||||
|
|
||||||
// check difference in passive http (Http)
|
// check difference in passive http (Http)
|
||||||
if (prev.http.enable !== now.http.enable) {
|
if (prev.http.enable !== now.http.enable) {
|
||||||
@ -153,14 +154,14 @@ export class NapCatOneBot11Adapter {
|
|||||||
} else {
|
} else {
|
||||||
if (now.http.enablePost) {
|
if (now.http.enablePost) {
|
||||||
const { added, removed } = this.findDifference<string>(prev.http.postUrls, now.http.postUrls);
|
const { added, removed } = this.findDifference<string>(prev.http.postUrls, now.http.postUrls);
|
||||||
added.forEach(url => {
|
|
||||||
this.networkManager.registerAdapterAndOpen(new OB11ActiveHttpAdapter(
|
|
||||||
url, now.token, this.core
|
|
||||||
));
|
|
||||||
});
|
|
||||||
await this.networkManager.closeAdapterByPredicate(
|
await this.networkManager.closeAdapterByPredicate(
|
||||||
adapter => adapter instanceof OB11ActiveHttpAdapter && removed.includes(adapter.url),
|
adapter => adapter instanceof OB11ActiveHttpAdapter && removed.includes(adapter.url),
|
||||||
);
|
);
|
||||||
|
for (const url of added) {
|
||||||
|
await this.networkManager.registerAdapterAndOpen(new OB11ActiveHttpAdapter(
|
||||||
|
url, now.token, this.core
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,14 +194,15 @@ export class NapCatOneBot11Adapter {
|
|||||||
} else {
|
} else {
|
||||||
if (now.reverseWs.enable) {
|
if (now.reverseWs.enable) {
|
||||||
const { added, removed } = this.findDifference<string>(prev.reverseWs.urls, now.reverseWs.urls);
|
const { added, removed } = this.findDifference<string>(prev.reverseWs.urls, now.reverseWs.urls);
|
||||||
added.forEach(url => {
|
console.log('rev ws', added, removed);
|
||||||
this.networkManager.registerAdapterAndOpen(new OB11ActiveWebSocketAdapter(
|
|
||||||
url, 5000, now.heartInterval, now.token, this.core, this.actions
|
|
||||||
));
|
|
||||||
});
|
|
||||||
await this.networkManager.closeAdapterByPredicate(
|
await this.networkManager.closeAdapterByPredicate(
|
||||||
adapter => adapter instanceof OB11ActiveWebSocketAdapter && removed.includes(adapter.url),
|
adapter => adapter instanceof OB11ActiveWebSocketAdapter && removed.includes(adapter.url),
|
||||||
);
|
);
|
||||||
|
for (const url of added) {
|
||||||
|
await this.networkManager.registerAdapterAndOpen(new OB11ActiveWebSocketAdapter(
|
||||||
|
url, 5000, now.heartInterval, now.token, this.core, this.actions
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user