mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
refactor: webui config
This commit is contained in:
parent
7b09479cd2
commit
6980a9f3fc
@ -58,9 +58,6 @@ export abstract class HttpServerBase {
|
|||||||
this.expressAPP.get('/', (req: Request, res: Response) => {
|
this.expressAPP.get('/', (req: Request, res: Response) => {
|
||||||
res.send(`${this.name}已启动`);
|
res.send(`${this.name}已启动`);
|
||||||
});
|
});
|
||||||
this.expressAPP.on('error', (err) => {
|
|
||||||
logError('HTTP服务启动失败', err.toString());
|
|
||||||
});
|
|
||||||
this.listen(port, host);
|
this.listen(port, host);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
logError('HTTP服务启动失败', e.toString());
|
logError('HTTP服务启动失败', e.toString());
|
||||||
@ -117,6 +114,8 @@ export abstract class HttpServerBase {
|
|||||||
this.server = this.expressAPP.listen(port, host, () => {
|
this.server = this.expressAPP.listen(port, host, () => {
|
||||||
const info = `${this.name} started ${host}:${port}`;
|
const info = `${this.name} started ${host}:${port}`;
|
||||||
log(info);
|
log(info);
|
||||||
|
}).on('error', (err) => {
|
||||||
|
logError('HTTP服务启动失败', err.toString());
|
||||||
});
|
});
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
logError('HTTP服务启动失败, 请检查监听的ip地址和端口', e.stack.toString());
|
logError('HTTP服务启动失败, 请检查监听的ip地址和端口', e.stack.toString());
|
||||||
|
@ -259,22 +259,44 @@ export class NapCatOnebot11 {
|
|||||||
// throw new Error('Invalid configuration object');
|
// throw new Error('Invalid configuration object');
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
// 先设置
|
||||||
|
ob11Config.save(NewOb11);
|
||||||
|
|
||||||
const isHttpChanged = !isEqual(NewOb11.http.port, ob11Config.http.port) && NewOb11.http.enable;
|
const isHttpChanged = !isEqual(NewOb11.http.port, ob11Config.http.port) && NewOb11.http.enable;
|
||||||
|
const isHttpEnableChanged = !isEqual(NewOb11.http.enable, ob11Config.http.enable);
|
||||||
|
|
||||||
|
const isHttpPostChanged = !isEqual(NewOb11.http.postUrls, ob11Config.http.postUrls);
|
||||||
|
const isEnanleHttpPostChanged = !isEqual(NewOb11.http.enablePost, ob11Config.http.enablePost);
|
||||||
|
|
||||||
const isWsChanged = !isEqual(NewOb11.ws.port, ob11Config.ws.port);
|
const isWsChanged = !isEqual(NewOb11.ws.port, ob11Config.ws.port);
|
||||||
const isEnableWsChanged = !isEqual(NewOb11.ws.enable, ob11Config.ws.enable);
|
const isEnableWsChanged = !isEqual(NewOb11.ws.enable, ob11Config.ws.enable);
|
||||||
|
|
||||||
const isEnableWsReverseChanged = !isEqual(NewOb11.reverseWs.enable, ob11Config.reverseWs.enable);
|
const isEnableWsReverseChanged = !isEqual(NewOb11.reverseWs.enable, ob11Config.reverseWs.enable);
|
||||||
const isWsReverseUrlsChanged = !isEqual(NewOb11.reverseWs.urls, ob11Config.reverseWs.urls);
|
const isWsReverseUrlsChanged = !isEqual(NewOb11.reverseWs.urls, ob11Config.reverseWs.urls);
|
||||||
|
|
||||||
|
const isEnableHeartBeatChanged = !isEqual(NewOb11.heartInterval, ob11Config.heartInterval);
|
||||||
|
// http重启逻辑
|
||||||
if (isHttpChanged) {
|
if (isHttpChanged) {
|
||||||
ob11HTTPServer.restart(NewOb11.http.port, NewOb11.http.host);
|
ob11HTTPServer.restart(NewOb11.http.port, NewOb11.http.host);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!NewOb11.http.enable) {
|
if (isHttpEnableChanged) {
|
||||||
ob11HTTPServer.stop();
|
if (NewOb11.http.enable) {
|
||||||
} else {
|
ob11HTTPServer.start(NewOb11.http.port, NewOb11.http.host);
|
||||||
ob11HTTPServer.start(NewOb11.http.port, NewOb11.http.host);
|
} else {
|
||||||
|
ob11HTTPServer.stop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
// http post重启逻辑
|
||||||
|
|
||||||
|
// if(isHttpPostChanged){
|
||||||
|
// logDebug('http post urls changed, restart http server');
|
||||||
|
// }
|
||||||
|
// if(isEnanleHttpPostChanged){
|
||||||
|
// logDebug('http post enable changed, restart http server');
|
||||||
|
// }
|
||||||
|
|
||||||
|
// ws重启逻辑
|
||||||
if (isWsChanged) {
|
if (isWsChanged) {
|
||||||
ob11WebsocketServer.restart(NewOb11.ws.port);
|
ob11WebsocketServer.restart(NewOb11.ws.port);
|
||||||
}
|
}
|
||||||
@ -287,6 +309,7 @@ export class NapCatOnebot11 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 反向ws重启逻辑
|
||||||
if (isEnableWsReverseChanged) {
|
if (isEnableWsReverseChanged) {
|
||||||
if (NewOb11.reverseWs.enable) {
|
if (NewOb11.reverseWs.enable) {
|
||||||
ob11ReverseWebsockets.start();
|
ob11ReverseWebsockets.start();
|
||||||
@ -294,16 +317,6 @@ export class NapCatOnebot11 {
|
|||||||
ob11ReverseWebsockets.stop();
|
ob11ReverseWebsockets.stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (NewOb11.reverseWs.enable && isWsReverseUrlsChanged) {
|
|
||||||
logDebug('反向ws地址有变化, 重启反向ws服务');
|
|
||||||
ob11ReverseWebsockets.restart();
|
|
||||||
}
|
|
||||||
if (NewOb11.http.enableHeart) {
|
|
||||||
httpHeart.start();
|
|
||||||
} else if (!NewOb11.http.enableHeart) {
|
|
||||||
httpHeart.stop();
|
|
||||||
}
|
|
||||||
ob11Config.save(NewOb11);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logError('热重载配置失败', e);
|
logError('热重载配置失败', e);
|
||||||
}
|
}
|
||||||
|
@ -35,10 +35,13 @@ setTimeout(() => {
|
|||||||
}, 0);
|
}, 0);
|
||||||
|
|
||||||
|
|
||||||
class HTTPHeart{
|
class HTTPHeart {
|
||||||
intervalId: NodeJS.Timeout | null = null;
|
intervalId: NodeJS.Timeout | null = null;
|
||||||
start(){
|
start(NewHeartInterval: number | undefined = undefined) {
|
||||||
const { heartInterval, } = ob11Config;
|
let { heartInterval } = ob11Config;
|
||||||
|
if (NewHeartInterval && !Number.isNaN(NewHeartInterval)) {
|
||||||
|
heartInterval = NewHeartInterval;
|
||||||
|
}
|
||||||
if (this.intervalId) {
|
if (this.intervalId) {
|
||||||
clearInterval(this.intervalId);
|
clearInterval(this.intervalId);
|
||||||
}
|
}
|
||||||
@ -48,8 +51,8 @@ class HTTPHeart{
|
|||||||
}, heartInterval);
|
}, heartInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
stop(){
|
stop() {
|
||||||
if (this.intervalId){
|
if (this.intervalId) {
|
||||||
clearInterval(this.intervalId);
|
clearInterval(this.intervalId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user