feat: 更新@kevisual/api依赖版本至0.0.62,优化WsProxyManager和请求处理逻辑

This commit is contained in:
2026-03-06 00:05:34 +08:00
parent b31f2840b9
commit 53204291ce
4 changed files with 38 additions and 13 deletions

View File

@@ -59,7 +59,7 @@
}, },
"devDependencies": { "devDependencies": {
"@aws-sdk/client-s3": "^3.1002.0", "@aws-sdk/client-s3": "^3.1002.0",
"@kevisual/api": "^0.0.60", "@kevisual/api": "^0.0.62",
"@kevisual/cnb": "^0.0.33", "@kevisual/cnb": "^0.0.33",
"@kevisual/context": "^0.0.8", "@kevisual/context": "^0.0.8",
"@kevisual/convex": "^0.0.4", "@kevisual/convex": "^0.0.4",

10
pnpm-lock.yaml generated
View File

@@ -66,8 +66,8 @@ importers:
specifier: ^3.1002.0 specifier: ^3.1002.0
version: 3.1002.0 version: 3.1002.0
'@kevisual/api': '@kevisual/api':
specifier: ^0.0.60 specifier: ^0.0.62
version: 0.0.60(react-dom@19.2.4(react@19.2.4))(react@19.2.4) version: 0.0.62(react-dom@19.2.4(react@19.2.4))(react@19.2.4)
'@kevisual/cnb': '@kevisual/cnb':
specifier: ^0.0.33 specifier: ^0.0.33
version: 0.0.33(dotenv@17.3.1)(ioredis@5.9.3) version: 0.0.33(dotenv@17.3.1)(ioredis@5.9.3)
@@ -863,8 +863,8 @@ packages:
'@kevisual/ai@0.0.26': '@kevisual/ai@0.0.26':
resolution: {integrity: sha512-lhaMpxi+vgqPdyBKiuNbSil4hy13tNLbDiqCtG0qUXKtvoowK6xMx269pSSYkYBivczM8g8I0XEouuJceUpJPg==} resolution: {integrity: sha512-lhaMpxi+vgqPdyBKiuNbSil4hy13tNLbDiqCtG0qUXKtvoowK6xMx269pSSYkYBivczM8g8I0XEouuJceUpJPg==}
'@kevisual/api@0.0.60': '@kevisual/api@0.0.62':
resolution: {integrity: sha512-NTFDx1ns/iGli2fUJLJZRWu8nf5VkXV+sOQUqGGAJvrvGATvXSuITu6mD4P/aDQakx4hzQUPr9wDTZoNk7+RqQ==} resolution: {integrity: sha512-GB8Ho2absXoXoZP2GKyuoRqRqjdwtV0JR512DXBaKJR2sIPn1KvuglbBiX+zPjDBBskv/ApvZKOoSwj1OmkrKQ==}
'@kevisual/auth@2.0.3': '@kevisual/auth@2.0.3':
resolution: {integrity: sha512-4xpijaIhlCTr/DlJaV/gmkCQeg45EO1yxWpRvUX+1jCdVbuxSR0wZrF0SD9oybnjmKWMKDNPLsXyduFjMGcItA==} resolution: {integrity: sha512-4xpijaIhlCTr/DlJaV/gmkCQeg45EO1yxWpRvUX+1jCdVbuxSR0wZrF0SD9oybnjmKWMKDNPLsXyduFjMGcItA==}
@@ -3494,7 +3494,7 @@ snapshots:
'@kevisual/permission': 0.0.4 '@kevisual/permission': 0.0.4
'@kevisual/query': 0.0.52 '@kevisual/query': 0.0.52
'@kevisual/api@0.0.60(react-dom@19.2.4(react@19.2.4))(react@19.2.4)': '@kevisual/api@0.0.62(react-dom@19.2.4(react@19.2.4))(react@19.2.4)':
dependencies: dependencies:
'@kevisual/context': 0.0.8 '@kevisual/context': 0.0.8
'@kevisual/js-filter': 0.0.5 '@kevisual/js-filter': 0.0.5

View File

@@ -161,6 +161,11 @@ export class WsProxyManager {
this.wssMap.delete(oldId); this.wssMap.delete(oldId);
this.wssMap.set(newId, value); this.wssMap.set(newId, value);
value.id = newId; value.id = newId;
// @ts-ignore
if (value.ws?.data) {
// @ts-ignore
value.ws.data.userApp = newId;
}
logger.debug(`WsProxyManager changeId: ${oldId} -> ${newId}`); logger.debug(`WsProxyManager changeId: ${oldId} -> ${newId}`);
} }
} }
@@ -218,11 +223,11 @@ export class WsProxyManager {
}, this.PING_INTERVAL); }, this.PING_INTERVAL);
} }
async createNewConnection(opts: { ws: any; user: string, userApp: string, isLogin?: boolean }) { async createNewConnection(opts: { ws: any; user: string, userApp: string, isLogin?: boolean }) {
const id = opts.userApp; let id = opts.userApp;
let realId: string = id; let realId: string = id;
const isLogin = opts.isLogin || false; const isLogin = opts.isLogin || false;
const has = this.wssMap.has(id); const has = this.wssMap.has(id);
const registryId = '-registry-' + generateRegistryId(); // 生成一个随机六位字符串作为注册 ID let registryId = '-registry-' + generateRegistryId(); // 生成一个随机六位字符串作为注册 ID
let isNeedVerify = !isLogin; let isNeedVerify = !isLogin;
if (has) { if (has) {
const value = this.wssMap.get(id); const value = this.wssMap.get(id);
@@ -236,8 +241,10 @@ export class WsProxyManager {
wsMessage.sendConnected(); wsMessage.sendConnected();
return { wsMessage, isNew: false, id: id }; return { wsMessage, isNew: false, id: id };
} else { } else {
// 没有关闭,需要重新注册鉴权一下, 生成新的 id 连接. // 没有关闭 生成新的 id 连接.
isNeedVerify = true; id = id + '-mult-' + generateRegistryId(4);
realId = id;
logger.debug('之前的连接未关闭,使用新的 ID 连接 ws', id);
} }
} }
} }
@@ -251,6 +258,6 @@ export class WsProxyManager {
} }
} }
// 生成一个随机六位字符串作为注册 ID // 生成一个随机六位字符串作为注册 ID
const generateRegistryId = () => { const generateRegistryId = (len = 6) => {
return Math.random().toString(36).substring(2, 8); return Math.random().toString(36).substring(2, 2 + len);
} }

View File

@@ -123,7 +123,7 @@ const handleRequest = async (req: IncomingMessage, res: ServerResponse, opts?: {
const client = wsProxyManager.get(appId!)!; const client = wsProxyManager.get(appId!)!;
if (!client) { if (!client) {
res.writeHead(404, { 'Content-Type': 'application/json' }); res.writeHead(404, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ message: '应用未找到' })); res.end(JSON.stringify({ code: 404, message: '应用未找到' }));
return; return;
} }
if (path === 'connected') { if (path === 'connected') {
@@ -132,6 +132,24 @@ const handleRequest = async (req: IncomingMessage, res: ServerResponse, opts?: {
res.end(JSON.stringify({ code: 200, message: '应用已连接' })); res.end(JSON.stringify({ code: 200, message: '应用已连接' }));
return; return;
} }
if (path === 'rename') {
const newId = url.searchParams.get('newId') || '';
if (!newId) {
res.writeHead(400, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ code: 400, message: 'newId 参数缺失' }));
return;
}
const wsMessage = wsProxyManager.get(newId!)!;
if (wsMessage) {
res.writeHead(400, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ code: 400, message: 'newId 已存在' }));
return;
}
wsProxyManager.changeId(appId, newId);
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ code: 200, message: '应用重命名成功' }));
return;
}
} }
res.writeHead(200, { 'Content-Type': 'application/json' }); res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ code: 200, data: { ids, infoList } })); res.end(JSON.stringify({ code: 200, data: { ids, infoList } }));