添加 @kevisual/api 依赖,更新 WebSocket 消息发送逻辑,支持上下文参数
This commit is contained in:
@@ -73,6 +73,7 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@aws-sdk/client-s3": "^3.981.0",
|
"@aws-sdk/client-s3": "^3.981.0",
|
||||||
|
"@kevisual/api": "^0.0.44",
|
||||||
"@kevisual/code-center-module": "0.0.24",
|
"@kevisual/code-center-module": "0.0.24",
|
||||||
"@kevisual/context": "^0.0.4",
|
"@kevisual/context": "^0.0.4",
|
||||||
"@kevisual/file-listener": "^0.0.2",
|
"@kevisual/file-listener": "^0.0.2",
|
||||||
|
|||||||
33
pnpm-lock.yaml
generated
33
pnpm-lock.yaml
generated
@@ -85,6 +85,9 @@ importers:
|
|||||||
'@aws-sdk/client-s3':
|
'@aws-sdk/client-s3':
|
||||||
specifier: ^3.981.0
|
specifier: ^3.981.0
|
||||||
version: 3.981.0
|
version: 3.981.0
|
||||||
|
'@kevisual/api':
|
||||||
|
specifier: ^0.0.44
|
||||||
|
version: 0.0.44
|
||||||
'@kevisual/code-center-module':
|
'@kevisual/code-center-module':
|
||||||
specifier: 0.0.24
|
specifier: 0.0.24
|
||||||
version: 0.0.24(dotenv@17.2.3)
|
version: 0.0.24(dotenv@17.2.3)
|
||||||
@@ -841,6 +844,9 @@ packages:
|
|||||||
'@kevisual/ai@0.0.24':
|
'@kevisual/ai@0.0.24':
|
||||||
resolution: {integrity: sha512-7jvZk1/L//VIClK7usuNgN4ZA9Etgbooka1Sj5quE/0UywR+NNnwqXVZ89Y1fBhI1TkhauDsdJBAtcQ7r/vbVw==}
|
resolution: {integrity: sha512-7jvZk1/L//VIClK7usuNgN4ZA9Etgbooka1Sj5quE/0UywR+NNnwqXVZ89Y1fBhI1TkhauDsdJBAtcQ7r/vbVw==}
|
||||||
|
|
||||||
|
'@kevisual/api@0.0.44':
|
||||||
|
resolution: {integrity: sha512-KA2b17pxW1pTPWa4zsTSRTiGTmwdkIesV1ig51MyISUllita5VPqZ6UYYDJQTHuPzYcIkuodQ9iWTEZNM9AkFw==}
|
||||||
|
|
||||||
'@kevisual/auth@1.0.5':
|
'@kevisual/auth@1.0.5':
|
||||||
resolution: {integrity: sha512-GwsLj7unKXi7lmMiIIgdig4LwwLiDJnOy15HHZR5gMbyK6s5/uJiMY5RXPB2+onGzTNDqFo/hXjsD2wkerHPVg==}
|
resolution: {integrity: sha512-GwsLj7unKXi7lmMiIIgdig4LwwLiDJnOy15HHZR5gMbyK6s5/uJiMY5RXPB2+onGzTNDqFo/hXjsD2wkerHPVg==}
|
||||||
|
|
||||||
@@ -1892,6 +1898,10 @@ packages:
|
|||||||
function-bind@1.1.2:
|
function-bind@1.1.2:
|
||||||
resolution: {integrity: sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==}
|
resolution: {integrity: sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==}
|
||||||
|
|
||||||
|
fuse.js@7.1.0:
|
||||||
|
resolution: {integrity: sha512-trLf4SzuuUxfusZADLINj+dE8clK1frKdmqiJNb1Es75fmI5oY6X2mxLVUciLLjxqw/xr72Dhy+lER6dGd02FQ==}
|
||||||
|
engines: {node: '>=10'}
|
||||||
|
|
||||||
get-intrinsic@1.2.4:
|
get-intrinsic@1.2.4:
|
||||||
resolution: {integrity: sha512-5uYhsJH8VJBTv7oslg4BznJYhDoRI6waYCxMmCdnTrcCrHA/fCFKoTFz2JKKE0HdDFUF7/oQuhzumXJK7paBRQ==}
|
resolution: {integrity: sha512-5uYhsJH8VJBTv7oslg4BznJYhDoRI6waYCxMmCdnTrcCrHA/fCFKoTFz2JKKE0HdDFUF7/oQuhzumXJK7paBRQ==}
|
||||||
engines: {node: '>= 0.4'}
|
engines: {node: '>= 0.4'}
|
||||||
@@ -2287,6 +2297,9 @@ packages:
|
|||||||
pako@0.2.9:
|
pako@0.2.9:
|
||||||
resolution: {integrity: sha512-NUcwaKxUxWrZLpDG+z/xZaCgQITkA/Dv4V/T6bw7VON6l1Xz/VnrBqrYjZQ12TamKHzITTfOEIYUj48y2KXImA==}
|
resolution: {integrity: sha512-NUcwaKxUxWrZLpDG+z/xZaCgQITkA/Dv4V/T6bw7VON6l1Xz/VnrBqrYjZQ12TamKHzITTfOEIYUj48y2KXImA==}
|
||||||
|
|
||||||
|
path-browserify-esm@1.0.6:
|
||||||
|
resolution: {integrity: sha512-9nUwYvvu/yq1PYrUyYCihNWmpzacaRYF6gGbjLWErrZ4MRDWyfPN7RpE8E7tsw8eqBU/rr7mcoTXbS+Vih8uUA==}
|
||||||
|
|
||||||
path-key@3.1.1:
|
path-key@3.1.1:
|
||||||
resolution: {integrity: sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==}
|
resolution: {integrity: sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==}
|
||||||
engines: {node: '>=8'}
|
engines: {node: '>=8'}
|
||||||
@@ -2625,6 +2638,9 @@ packages:
|
|||||||
resolution: {integrity: sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==}
|
resolution: {integrity: sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==}
|
||||||
engines: {node: '>=0.10.0'}
|
engines: {node: '>=0.10.0'}
|
||||||
|
|
||||||
|
spark-md5@3.0.2:
|
||||||
|
resolution: {integrity: sha512-wcFzz9cDfbuqe0FZzfi2or1sgyIrsDwmPwfZC4hiNidPdPINjeUwNfv5kldczoEAcjl9Y1L3SM7Uz2PUEQzxQw==}
|
||||||
|
|
||||||
split-on-first@1.1.0:
|
split-on-first@1.1.0:
|
||||||
resolution: {integrity: sha512-43ZssAJaMusuKWL8sKUBQXHWOpq8d6CfN/u1p4gUzfJkM05C8rxTmYrkIPTXapZpORA6LkkzcUulJ8FqA7Uudw==}
|
resolution: {integrity: sha512-43ZssAJaMusuKWL8sKUBQXHWOpq8d6CfN/u1p4gUzfJkM05C8rxTmYrkIPTXapZpORA6LkkzcUulJ8FqA7Uudw==}
|
||||||
engines: {node: '>=6'}
|
engines: {node: '>=6'}
|
||||||
@@ -3622,6 +3638,17 @@ snapshots:
|
|||||||
'@kevisual/permission': 0.0.3
|
'@kevisual/permission': 0.0.3
|
||||||
'@kevisual/query': 0.0.38
|
'@kevisual/query': 0.0.38
|
||||||
|
|
||||||
|
'@kevisual/api@0.0.44':
|
||||||
|
dependencies:
|
||||||
|
'@kevisual/js-filter': 0.0.5
|
||||||
|
'@kevisual/load': 0.0.6
|
||||||
|
es-toolkit: 1.44.0
|
||||||
|
eventemitter3: 5.0.4
|
||||||
|
fuse.js: 7.1.0
|
||||||
|
nanoid: 5.1.6
|
||||||
|
path-browserify-esm: 1.0.6
|
||||||
|
spark-md5: 3.0.2
|
||||||
|
|
||||||
'@kevisual/auth@1.0.5': {}
|
'@kevisual/auth@1.0.5': {}
|
||||||
|
|
||||||
'@kevisual/auth@2.0.3': {}
|
'@kevisual/auth@2.0.3': {}
|
||||||
@@ -4838,6 +4865,8 @@ snapshots:
|
|||||||
|
|
||||||
function-bind@1.1.2: {}
|
function-bind@1.1.2: {}
|
||||||
|
|
||||||
|
fuse.js@7.1.0: {}
|
||||||
|
|
||||||
get-intrinsic@1.2.4:
|
get-intrinsic@1.2.4:
|
||||||
dependencies:
|
dependencies:
|
||||||
es-errors: 1.3.0
|
es-errors: 1.3.0
|
||||||
@@ -5254,6 +5283,8 @@ snapshots:
|
|||||||
|
|
||||||
pako@0.2.9: {}
|
pako@0.2.9: {}
|
||||||
|
|
||||||
|
path-browserify-esm@1.0.6: {}
|
||||||
|
|
||||||
path-key@3.1.1: {}
|
path-key@3.1.1: {}
|
||||||
|
|
||||||
path-parse@1.0.7: {}
|
path-parse@1.0.7: {}
|
||||||
@@ -5674,6 +5705,8 @@ snapshots:
|
|||||||
|
|
||||||
source-map@0.6.1: {}
|
source-map@0.6.1: {}
|
||||||
|
|
||||||
|
spark-md5@3.0.2: {}
|
||||||
|
|
||||||
split-on-first@1.1.0: {}
|
split-on-first@1.1.0: {}
|
||||||
|
|
||||||
split2@4.2.0: {}
|
split2@4.2.0: {}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { nanoid } from 'nanoid';
|
|||||||
import { WebSocket } from 'ws';
|
import { WebSocket } from 'ws';
|
||||||
import { logger } from '../logger.ts';
|
import { logger } from '../logger.ts';
|
||||||
import { EventEmitter } from 'eventemitter3';
|
import { EventEmitter } from 'eventemitter3';
|
||||||
|
|
||||||
class WsMessage {
|
class WsMessage {
|
||||||
ws: WebSocket;
|
ws: WebSocket;
|
||||||
user?: string;
|
user?: string;
|
||||||
@@ -16,7 +17,7 @@ class WsMessage {
|
|||||||
this.emitter.emit(data.id, data?.data);
|
this.emitter.emit(data.id, data?.data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async sendData(data: any, opts?: { timeout?: number }) {
|
async sendData(data: any, context?: any, opts?: { timeout?: number }) {
|
||||||
if (this.ws.readyState !== WebSocket.OPEN) {
|
if (this.ws.readyState !== WebSocket.OPEN) {
|
||||||
return { code: 500, message: 'WebSocket is not open' };
|
return { code: 500, message: 'WebSocket is not open' };
|
||||||
}
|
}
|
||||||
@@ -25,7 +26,10 @@ class WsMessage {
|
|||||||
const message = JSON.stringify({
|
const message = JSON.stringify({
|
||||||
id,
|
id,
|
||||||
type: 'proxy',
|
type: 'proxy',
|
||||||
data,
|
data: {
|
||||||
|
message: data,
|
||||||
|
context: context || {},
|
||||||
|
},
|
||||||
});
|
});
|
||||||
logger.info('ws-proxy sendData', message);
|
logger.info('ws-proxy sendData', message);
|
||||||
this.ws.send(message);
|
this.ws.send(message);
|
||||||
|
|||||||
@@ -74,7 +74,10 @@ export const UserV1Proxy = async (req: IncomingMessage, res: ServerResponse, opt
|
|||||||
res.end(await html);
|
res.end(await html);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
const value = await client.sendData(data);
|
// const { token, cookies, ...rest } = data;
|
||||||
|
const value = await client.sendData(data, {
|
||||||
|
state: { tokenUser: loginUser.tokenUser },
|
||||||
|
});
|
||||||
if (value) {
|
if (value) {
|
||||||
res.writeHead(200, { 'Content-Type': 'application/json' });
|
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||||
res.end(JSON.stringify(value));
|
res.end(JSON.stringify(value));
|
||||||
|
|||||||
@@ -282,6 +282,8 @@ app
|
|||||||
ctx.throw('app 未发现');
|
ctx.throw('app 未发现');
|
||||||
}
|
}
|
||||||
if (detect) {
|
if (detect) {
|
||||||
|
const appKey = appList.key;
|
||||||
|
const version = appList.version;
|
||||||
// 自动检测最新版本
|
// 自动检测最新版本
|
||||||
const res = await callDetectAppVersion({ appKey, version, username: username || tokenUser.username }, ctx.query.token);
|
const res = await callDetectAppVersion({ appKey, version, username: username || tokenUser.username }, ctx.query.token);
|
||||||
if (res.code !== 200) {
|
if (res.code !== 200) {
|
||||||
|
|||||||
Reference in New Issue
Block a user