feat: 更新WsProxyManager注册逻辑,添加isLogin参数并优化HTML响应处理

This commit is contained in:
2026-03-05 04:31:45 +08:00
parent bbdf9f087d
commit 2518f6bba3
2 changed files with 13 additions and 9 deletions

View File

@@ -134,7 +134,7 @@ export class WsProxyManager {
} }
this.checkConnceted(); this.checkConnceted();
} }
register(id: string, opts?: { ws: WebSocket; user: string, id?: string }) { register(id: string, opts?: { ws: WebSocket; user: string, id?: string, isLogin: boolean }) {
if (this.wssMap.has(id)) { if (this.wssMap.has(id)) {
const value = this.wssMap.get(id); const value = this.wssMap.get(id);
if (value) { if (value) {
@@ -232,7 +232,7 @@ export class WsProxyManager {
logger.debug('之前的连接已关闭,复用注册 ID 连接 ws', id); logger.debug('之前的连接已关闭,复用注册 ID 连接 ws', id);
this.unregister(id); this.unregister(id);
await new Promise(resolve => setTimeout(resolve, 100)); await new Promise(resolve => setTimeout(resolve, 100));
const wsMessage = this.register(id, { ws: opts.ws, user: opts.user, id }); const wsMessage = this.register(id, { ws: opts.ws, user: opts.user, id, isLogin });
wsMessage.sendConnected(); wsMessage.sendConnected();
return { wsMessage, isNew: false, id: id }; return { wsMessage, isNew: false, id: id };
} else { } else {
@@ -246,7 +246,7 @@ export class WsProxyManager {
realId = id + registryId; realId = id + registryId;
logger.debug('未登录用户,使用临时注册 ID 连接 ws', realId); logger.debug('未登录用户,使用临时注册 ID 连接 ws', realId);
} }
const wsMessage = this.register(realId, { ws: opts.ws, user: opts.user, id: realId }); const wsMessage = this.register(realId, { ws: opts.ws, user: opts.user, id: realId, isLogin });
return { wsMessage, isNew: true, id: realId }; return { wsMessage, isNew: true, id: realId };
} }
} }

View File

@@ -59,9 +59,14 @@ export const UserV1Proxy = async (req: IncomingMessage, res: ServerResponse, opt
if (!client) { if (!client) {
if (isGet) { if (isGet) {
if (isAdmin) { if (isAdmin) {
const html = createStudioAppListHtml({ user, appIds: ids, userAppKey, infoList }); // const html = createStudioAppListHtml({ user, appIds: ids, userAppKey, infoList });
// res.writeHead(200, { 'Content-Type': 'text/html' });
// res.end(html);
// https://kevisual.cn/root/v1-manager/
const html = await fetch(`${baseProxyUrl}/root/v1-manager/index.html`).then(res => res.text());
res.writeHead(200, { 'Content-Type': 'text/html' }); res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(html); res.end(renderServerHtml({ user, appIds: ids, userAppKey, infoList }, html));
return true;
} else { } else {
opts?.createNotFoundPage?.('应用访问失败'); opts?.createNotFoundPage?.('应用访问失败');
} }
@@ -74,9 +79,9 @@ export const UserV1Proxy = async (req: IncomingMessage, res: ServerResponse, opt
const path = searchParams.get('path'); const path = searchParams.get('path');
if (!path) { if (!path) {
// 显示前端页面 // 显示前端页面
const html = fetch(`${baseProxyUrl}/root/router-studio/index.html`).then(res => res.text()); const html = await fetch(`${baseProxyUrl}/root/router-studio/index.html`).then(res => res.text());
res.writeHead(200, { 'Content-Type': 'text/html' }); res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(await html); res.end(html);
return true; return true;
} }
let message: any = data; let message: any = data;
@@ -106,7 +111,7 @@ const handleRequest = async (req: IncomingMessage, res: ServerResponse, opts?: {
// 获取所有的管理员的应用列表 // 获取所有的管理员的应用列表
const { ids, infoList } = wsProxyManager.getIdsInfo(user + '--'); const { ids, infoList } = wsProxyManager.getIdsInfo(user + '--');
if (isGet) { if (isGet) {
const html = createStudioAppListHtml({ user, appIds: ids, userAppKey, infoList }); const html = await fetch(`${baseProxyUrl}/root/v1-manager/index.html`).then(res => res.text());
res.writeHead(200, { 'Content-Type': 'text/html' }); res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(html); res.end(html);
return; return;
@@ -122,7 +127,6 @@ const handleRequest = async (req: IncomingMessage, res: ServerResponse, opts?: {
return; return;
} }
if (path === 'connected') { if (path === 'connected') {
client.sendConnected(); client.sendConnected();
res.writeHead(200, { 'Content-Type': 'application/json' }); res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ code: 200, message: '应用已连接' })); res.end(JSON.stringify({ code: 200, message: '应用已连接' }));