diff --git a/manifest.json b/manifest.json index e199eaf5..a0da57af 100644 --- a/manifest.json +++ b/manifest.json @@ -4,7 +4,7 @@ "name": "NapCatQQ", "slug": "NapCat.Framework", "description": "高性能的 OneBot 11 协议实现", - "version": "2.2.38", + "version": "2.2.39", "icon": "./logo.png", "authors": [ { diff --git a/package.json b/package.json index 89db0265..52ff6fa4 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "napcat", "private": true, "type": "module", - "version": "2.2.38", + "version": "2.2.39", "scripts": { "build:framework": "vite build --mode framework", "build:shell": "vite build --mode shell", diff --git a/src/common/version.ts b/src/common/version.ts index c2b87813..5e35740f 100644 --- a/src/common/version.ts +++ b/src/common/version.ts @@ -1 +1 @@ -export const napCatVersion = '2.2.38'; +export const napCatVersion = '2.2.39'; diff --git a/src/onebot/network/active-websocket.ts b/src/onebot/network/active-websocket.ts index ec6c3002..3224fb77 100644 --- a/src/onebot/network/active-websocket.ts +++ b/src/onebot/network/active-websocket.ts @@ -131,23 +131,24 @@ export class OB11ActiveWebSocketAdapter implements IOB11NetworkAdapter { private async handleMessage(message: any) { let receiveData: { action: ActionName, params?: any, echo?: any } = { action: ActionName.Unknown, params: {} }; let echo = undefined; + try { - try { - receiveData = JSON.parse(message.toString()); - echo = receiveData.echo; - this.logger.logDebug('[OneBot] [WebSocket Client] 收到正向Websocket消息', receiveData); - } catch (e) { - this.checkStateAndReply(OB11Response.error('json解析失败,请检查数据格式', 1400, echo)); - return; - } - receiveData.params = (receiveData?.params) ? receiveData.params : {};//兼容类型验证 - const retdata = await this.actions.get(receiveData.action) - ?.websocketHandle(receiveData.params, echo ?? ''); - const packet = Object.assign({}, retdata); - this.checkStateAndReply(packet); + receiveData = JSON.parse(message.toString()); + echo = receiveData.echo; + this.logger.logDebug('[OneBot] [WebSocket Client] 收到正向Websocket消息', receiveData); } catch (e) { - this.logger.logError('[OneBot] [WebSocket Client] 发生错误', e); - this.checkStateAndReply(OB11Response.error('不支持的api ' + receiveData.action, 1404, echo)); + this.checkStateAndReply(OB11Response.error('json解析失败,请检查数据格式', 1400, echo)); + return; } + receiveData.params = (receiveData?.params) ? receiveData.params : {};//兼容类型验证 + const action = this.actions.get(receiveData.action); + if (!action) { + this.logger.logError('[OneBot] [WebSocket Client] 发生错误', '不支持的api ' + receiveData.action); + this.checkStateAndReply(OB11Response.error('不支持的api ' + receiveData.action, 1404, echo)); + return; + } + const retdata = await action?.websocketHandle(receiveData.params, echo ?? ''); + const packet = Object.assign({}, retdata); + this.checkStateAndReply(packet); } } diff --git a/src/onebot/network/passive-websocket.ts b/src/onebot/network/passive-websocket.ts index fe197f4f..70b2f371 100644 --- a/src/onebot/network/passive-websocket.ts +++ b/src/onebot/network/passive-websocket.ts @@ -146,22 +146,23 @@ export class OB11PassiveWebSocketAdapter implements IOB11NetworkAdapter { let receiveData: { action: ActionName, params?: any, echo?: any } = { action: ActionName.Unknown, params: {} }; let echo = undefined; try { - try { - receiveData = JSON.parse(message.toString()); - echo = receiveData.echo; - //this.logger.logDebug('收到正向Websocket消息', receiveData); - } catch (e) { - this.checkStateAndReply(OB11Response.error('json解析失败,请检查数据格式', 1400, echo), wsClient); - return; - } - receiveData.params = (receiveData?.params) ? receiveData.params : {};//兼容类型验证 - const retdata = await this.actions.get(receiveData.action)?.websocketHandle(receiveData.params, echo ?? ''); - const packet = Object.assign({}, retdata); - this.checkStateAndReply(packet, wsClient); + receiveData = JSON.parse(message.toString()); + echo = receiveData.echo; + //this.logger.logDebug('收到正向Websocket消息', receiveData); } catch (e) { - this.checkStateAndReply(OB11Response.error('不支持的api ' + receiveData.action, 1404, echo), wsClient); + this.checkStateAndReply(OB11Response.error('json解析失败,请检查数据格式', 1400, echo), wsClient); + return; } + receiveData.params = (receiveData?.params) ? receiveData.params : {};//兼容类型验证 + const action = this.actions.get(receiveData.action); + if (!action) { + this.logger.logError('[OneBot] [WebSocket Client] 发生错误', '不支持的api ' + receiveData.action); + this.checkStateAndReply(OB11Response.error('不支持的api ' + receiveData.action, 1404, echo), wsClient); + return; + } + const retdata = await action.websocketHandle(receiveData.params, echo ?? ''); + const packet = Object.assign({}, retdata); + this.checkStateAndReply(packet, wsClient); } - } diff --git a/src/webui/ui/NapCat.ts b/src/webui/ui/NapCat.ts index 8f80b3c6..d6e0f729 100644 --- a/src/webui/ui/NapCat.ts +++ b/src/webui/ui/NapCat.ts @@ -30,7 +30,7 @@ async function onSettingWindowCreated(view: Element) { SettingItem( 'Napcat', undefined, - SettingButton('V2.2.38', 'napcat-update-button', 'secondary'), + SettingButton('V2.2.39', 'napcat-update-button', 'secondary'), ), ]), SettingList([ diff --git a/static/assets/renderer.js b/static/assets/renderer.js index c82de3ff..707852cc 100644 --- a/static/assets/renderer.js +++ b/static/assets/renderer.js @@ -164,7 +164,7 @@ async function onSettingWindowCreated(view) { SettingItem( 'Napcat', void 0, - SettingButton("V2.2.38", "napcat-update-button", "secondary") + SettingButton("V2.2.39", "napcat-update-button", "secondary") ) ]), SettingList([