mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
feat
This commit is contained in:
parent
fffa664400
commit
b2088824cc
@ -22,7 +22,7 @@
|
|||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"cosmokit": "^1.6.2",
|
"cosmokit": "^1.6.2",
|
||||||
"express": "^4.19.2",
|
"express": "^4.19.2",
|
||||||
"fast-xml-parser": "^4.4.1",
|
"fast-xml-parser": "^4.5.0",
|
||||||
"file-type": "^19.4.1",
|
"file-type": "^19.4.1",
|
||||||
"fluent-ffmpeg": "^2.1.3",
|
"fluent-ffmpeg": "^2.1.3",
|
||||||
"minato": "^3.5.1",
|
"minato": "^3.5.1",
|
||||||
@ -38,7 +38,7 @@
|
|||||||
"electron": "^31.4.0",
|
"electron": "^31.4.0",
|
||||||
"electron-vite": "^2.3.0",
|
"electron-vite": "^2.3.0",
|
||||||
"typescript": "^5.5.4",
|
"typescript": "^5.5.4",
|
||||||
"vite": "^5.4.2",
|
"vite": "^5.4.3",
|
||||||
"vite-plugin-cp": "^4.0.8"
|
"vite-plugin-cp": "^4.0.8"
|
||||||
},
|
},
|
||||||
"packageManager": "yarn@4.4.1"
|
"packageManager": "yarn@4.4.1"
|
||||||
|
@ -33,7 +33,8 @@ export class ConfigUtil {
|
|||||||
enableWsReverse: false,
|
enableWsReverse: false,
|
||||||
messagePostFormat: 'array',
|
messagePostFormat: 'array',
|
||||||
enableHttpHeart: false,
|
enableHttpHeart: false,
|
||||||
enableQOAutoQuote: false
|
enableQOAutoQuote: false,
|
||||||
|
listenLocalhost: false
|
||||||
}
|
}
|
||||||
const defaultConfig: Config = {
|
const defaultConfig: Config = {
|
||||||
enableLLOB: true,
|
enableLLOB: true,
|
||||||
|
@ -11,6 +11,7 @@ export interface OB11Config {
|
|||||||
messagePostFormat?: 'array' | 'string'
|
messagePostFormat?: 'array' | 'string'
|
||||||
enableHttpHeart?: boolean
|
enableHttpHeart?: boolean
|
||||||
enableQOAutoQuote: boolean // 快速操作回复自动引用原消息
|
enableQOAutoQuote: boolean // 快速操作回复自动引用原消息
|
||||||
|
listenLocalhost: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CheckVersion {
|
export interface CheckVersion {
|
||||||
|
@ -50,7 +50,8 @@ class OneBot11Adapter extends Service {
|
|||||||
this.ob11Http = new OB11Http(ctx, {
|
this.ob11Http = new OB11Http(ctx, {
|
||||||
port: config.httpPort,
|
port: config.httpPort,
|
||||||
token: config.token,
|
token: config.token,
|
||||||
actionMap
|
actionMap,
|
||||||
|
listenLocalhost: config.listenLocalhost
|
||||||
})
|
})
|
||||||
this.ob11HttpPost = new OB11HttpPost(ctx, {
|
this.ob11HttpPost = new OB11HttpPost(ctx, {
|
||||||
hosts: config.httpHosts,
|
hosts: config.httpHosts,
|
||||||
@ -62,7 +63,8 @@ class OneBot11Adapter extends Service {
|
|||||||
port: config.wsPort,
|
port: config.wsPort,
|
||||||
heartInterval: config.heartInterval,
|
heartInterval: config.heartInterval,
|
||||||
token: config.token,
|
token: config.token,
|
||||||
actionMap
|
actionMap,
|
||||||
|
listenLocalhost: config.listenLocalhost
|
||||||
})
|
})
|
||||||
this.ob11WebSocketReverseManager = new OB11WebSocketReverseManager(ctx, {
|
this.ob11WebSocketReverseManager = new OB11WebSocketReverseManager(ctx, {
|
||||||
hosts: config.wsHosts,
|
hosts: config.wsHosts,
|
||||||
@ -292,7 +294,7 @@ class OneBot11Adapter extends Service {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// HTTP 端口变化,重启服务
|
// HTTP 端口变化,重启服务
|
||||||
if (config.ob11.httpPort !== old.httpPort) {
|
if ((config.ob11.httpPort !== old.httpPort || config.ob11.listenLocalhost !== old.listenLocalhost) && config.ob11.enableHttp) {
|
||||||
await this.ob11Http.stop()
|
await this.ob11Http.stop()
|
||||||
this.ob11Http.start()
|
this.ob11Http.start()
|
||||||
}
|
}
|
||||||
@ -305,7 +307,7 @@ class OneBot11Adapter extends Service {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 正向 WebSocket 端口变化,重启服务
|
// 正向 WebSocket 端口变化,重启服务
|
||||||
if (config.ob11.wsPort !== old.wsPort) {
|
if ((config.ob11.wsPort !== old.wsPort || config.ob11.listenLocalhost !== old.listenLocalhost) && config.ob11.enableWs) {
|
||||||
await this.ob11WebSocket.stop()
|
await this.ob11WebSocket.stop()
|
||||||
this.ob11WebSocket.start()
|
this.ob11WebSocket.start()
|
||||||
llonebotError.wsServerError = ''
|
llonebotError.wsServerError = ''
|
||||||
|
@ -51,8 +51,9 @@ class OB11Http {
|
|||||||
this.expressAPP.get('/', (req: Request, res: Response) => {
|
this.expressAPP.get('/', (req: Request, res: Response) => {
|
||||||
res.send(`LLOneBot server 已启动`)
|
res.send(`LLOneBot server 已启动`)
|
||||||
})
|
})
|
||||||
this.server = this.expressAPP.listen(this.config.port, '0.0.0.0', () => {
|
const host = this.config.listenLocalhost ? '127.0.0.1' : '0.0.0.0'
|
||||||
this.ctx.logger.info(`HTTP server started 0.0.0.0:${this.config.port}`)
|
this.server = this.expressAPP.listen(this.config.port, host, () => {
|
||||||
|
this.ctx.logger.info(`HTTP server started ${host}:${this.config.port}`)
|
||||||
})
|
})
|
||||||
llonebotError.httpServerError = ''
|
llonebotError.httpServerError = ''
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
@ -136,6 +137,7 @@ namespace OB11Http {
|
|||||||
port: number
|
port: number
|
||||||
token?: string
|
token?: string
|
||||||
actionMap: Map<string, BaseAction<any, any>>
|
actionMap: Map<string, BaseAction<any, any>>
|
||||||
|
listenLocalhost: boolean
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,9 +21,14 @@ class OB11WebSocket {
|
|||||||
|
|
||||||
public start() {
|
public start() {
|
||||||
if (this.wsServer) return
|
if (this.wsServer) return
|
||||||
this.ctx.logger.info(`WebSocket server started 0.0.0.0:${this.config.port}`)
|
const host = this.config.listenLocalhost ? '127.0.0.1' : '0.0.0.0'
|
||||||
|
this.ctx.logger.info(`WebSocket server started ${host}:${this.config.port}`)
|
||||||
try {
|
try {
|
||||||
this.wsServer = new WebSocketServer({ port: this.config.port, maxPayload: 1024 * 1024 * 1024 })
|
this.wsServer = new WebSocketServer({
|
||||||
|
host,
|
||||||
|
port: this.config.port,
|
||||||
|
maxPayload: 1024 * 1024 * 1024
|
||||||
|
})
|
||||||
llonebotError.wsServerError = ''
|
llonebotError.wsServerError = ''
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
llonebotError.wsServerError = '正向 WebSocket 服务启动失败, ' + e.toString()
|
llonebotError.wsServerError = '正向 WebSocket 服务启动失败, ' + e.toString()
|
||||||
@ -165,6 +170,7 @@ namespace OB11WebSocket {
|
|||||||
heartInterval: number
|
heartInterval: number
|
||||||
token?: string
|
token?: string
|
||||||
actionMap: Map<string, BaseAction<any, any>>
|
actionMap: Map<string, BaseAction<any, any>>
|
||||||
|
listenLocalhost: boolean
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,7 +166,12 @@ async function onSettingWindowCreated(view: Element) {
|
|||||||
SettingItem(
|
SettingItem(
|
||||||
'快速操作回复自动引用原消息',
|
'快速操作回复自动引用原消息',
|
||||||
null,
|
null,
|
||||||
SettingSwitch('ob11.enableQOAutoQuote', config.ob11.enableQOAutoQuote, { 'control-display-id': 'config-ob11-enableQOAutoQuote' }),
|
SettingSwitch('ob11.enableQOAutoQuote', config.ob11.enableQOAutoQuote),
|
||||||
|
),
|
||||||
|
SettingItem(
|
||||||
|
'HTTP、正向 WebSocket 服务仅监听 127.0.0.1',
|
||||||
|
'而不是 0.0.0.0',
|
||||||
|
SettingSwitch('ob11.listenLocalhost', config.ob11.listenLocalhost),
|
||||||
),
|
),
|
||||||
SettingItem('', null, SettingButton('保存', 'config-ob11-save', 'primary')),
|
SettingItem('', null, SettingButton('保存', 'config-ob11-save', 'primary')),
|
||||||
]),
|
]),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user