🔨 优化会话连接逻辑.
This commit is contained in:
@@ -36,6 +36,7 @@ import java.util.Map;
|
||||
* @version 1.0.0
|
||||
* @since 2023-9-11 14:16
|
||||
*/
|
||||
// TODO 待优化
|
||||
public interface HostConfigService {
|
||||
|
||||
/**
|
||||
|
||||
@@ -141,6 +141,7 @@ public class ExecCommandServiceImpl implements ExecCommandService {
|
||||
// 查询主机信息
|
||||
List<HostDO> hosts = hostDAO.selectBatchIds(hostIdList);
|
||||
// 查询主机配置
|
||||
// TODO 待优化
|
||||
Map<Long, HostSshConfigModel> hostConfigMap = hostConfigService.buildHostConfigMap(hosts, HostTypeEnum.SSH);
|
||||
// 插入日志
|
||||
ExecLogDO execLog = ExecLogDO.builder()
|
||||
|
||||
@@ -388,6 +388,7 @@ public class ExecLogServiceImpl implements ExecLogService {
|
||||
}
|
||||
Valid.notEmpty(hostLogs, ErrorMessage.LOG_ABSENT);
|
||||
// 获取编码集
|
||||
// TODO 待优化
|
||||
List<Long> hostIdList = hostLogs.stream()
|
||||
.map(ExecHostLogDO::getHostId)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
@@ -28,11 +28,15 @@ export default abstract class BaseSession implements ITerminalSession {
|
||||
this.canWrite = canWrite;
|
||||
}
|
||||
|
||||
// 连接
|
||||
connect(): void {
|
||||
// 设置已连接
|
||||
setConnected(): void {
|
||||
this.connected = true;
|
||||
}
|
||||
|
||||
// 连接会话
|
||||
connect(): void {
|
||||
}
|
||||
|
||||
// 断开连接
|
||||
disconnect(): void {
|
||||
this.connected = false;
|
||||
|
||||
@@ -28,12 +28,23 @@ export default class SftpSession extends BaseSession implements ISftpSession {
|
||||
}
|
||||
|
||||
// 设置已连接
|
||||
connect(): void {
|
||||
super.connect();
|
||||
setConnected(): void {
|
||||
super.setConnected();
|
||||
// 连接回调
|
||||
this.resolver.connectCallback();
|
||||
}
|
||||
|
||||
// 连接会话
|
||||
connect(): void {
|
||||
super.connect();
|
||||
// 发送会话初始化请求
|
||||
this.channel.send(InputProtocol.CHECK, {
|
||||
sessionId: this.sessionId,
|
||||
hostId: this.hostId,
|
||||
connectType: this.type,
|
||||
});
|
||||
}
|
||||
|
||||
// 设置显示隐藏文件
|
||||
setShowHiddenFile(show: boolean): void {
|
||||
this.showHiddenFile = show;
|
||||
|
||||
@@ -7,7 +7,7 @@ import type { XtermAddons } from '@/types/xterm';
|
||||
import { defaultFontFamily } from '@/types/xterm';
|
||||
import { useTerminalStore } from '@/store';
|
||||
import { InputProtocol } from '@/types/protocol/terminal.protocol';
|
||||
import { PanelSessionType, TerminalShortcutType, TerminalSessionStatus } from '../types/const';
|
||||
import { PanelSessionType, TerminalSessionStatus, TerminalShortcutType } from '../types/const';
|
||||
import { Terminal } from '@xterm/xterm';
|
||||
import { FitAddon } from '@xterm/addon-fit';
|
||||
import { WebLinksAddon } from '@xterm/addon-web-links';
|
||||
@@ -205,8 +205,9 @@ export default class SshSession extends BaseSession implements ISshSession {
|
||||
}
|
||||
|
||||
// 设置已连接
|
||||
connect(): void {
|
||||
super.connect();
|
||||
setConnected(): void {
|
||||
super.setConnected();
|
||||
// 设置状态
|
||||
this.status = TerminalSessionStatus.CONNECTED;
|
||||
this.inst.focus();
|
||||
}
|
||||
@@ -221,6 +222,19 @@ export default class SshSession extends BaseSession implements ISshSession {
|
||||
}
|
||||
}
|
||||
|
||||
// 连接会话
|
||||
connect(): void {
|
||||
super.connect();
|
||||
// 设置状态
|
||||
this.status = TerminalSessionStatus.CONNECTING;
|
||||
// 发送会话初始化请求
|
||||
this.channel.send(InputProtocol.CHECK, {
|
||||
sessionId: this.sessionId,
|
||||
hostId: this.hostId,
|
||||
connectType: this.type,
|
||||
});
|
||||
}
|
||||
|
||||
// 写入数据
|
||||
write(value: string): void {
|
||||
this.inst.write(value);
|
||||
|
||||
@@ -65,8 +65,8 @@ export default class TerminalOutputProcessor implements ITerminalOutputProcessor
|
||||
if (success) {
|
||||
// 设置可写
|
||||
ssh.setCanWrite(true);
|
||||
// 执行连接逻辑
|
||||
ssh.connect();
|
||||
// 设置已连接
|
||||
ssh.setConnected();
|
||||
} else {
|
||||
// 未成功展示错误信息
|
||||
ssh.write(`[91m${msg || ''}[0m\r\n\r\n[91m输入回车重新连接...[0m\r\n\r\n`);
|
||||
@@ -77,8 +77,8 @@ export default class TerminalOutputProcessor implements ITerminalOutputProcessor
|
||||
if (success) {
|
||||
// 设置可写
|
||||
sftp.setCanWrite(true);
|
||||
// 执行连接逻辑
|
||||
sftp.connect();
|
||||
// 设置已连接
|
||||
sftp.setConnected();
|
||||
} else {
|
||||
// 未成功提示错误信息
|
||||
sftp.resolver?.onClose(false, msg);
|
||||
|
||||
@@ -52,12 +52,8 @@ export default class TerminalSessionManager implements ITerminalSessionManager {
|
||||
// 添加会话
|
||||
const sessionId = tab.sessionId;
|
||||
this.sessions[sessionId] = session;
|
||||
// 发送会话初始化请求
|
||||
this.channel.send(InputProtocol.CHECK, {
|
||||
sessionId,
|
||||
hostId: tab.hostId,
|
||||
connectType: PanelSessionType.SSH.type
|
||||
});
|
||||
// 连接会话
|
||||
session.connect();
|
||||
return session;
|
||||
}
|
||||
|
||||
@@ -72,17 +68,13 @@ export default class TerminalSessionManager implements ITerminalSessionManager {
|
||||
// 添加会话
|
||||
const sessionId = tab.sessionId;
|
||||
this.sessions[sessionId] = session;
|
||||
// 发送会话初始化请求
|
||||
this.channel.send(InputProtocol.CHECK, {
|
||||
sessionId,
|
||||
hostId: tab.hostId,
|
||||
connectType: PanelSessionType.SFTP.type
|
||||
});
|
||||
// 连接会话
|
||||
session.connect();
|
||||
return session;
|
||||
}
|
||||
|
||||
// 重新打开会话
|
||||
async reOpenSession(type: string, sessionId: string, newSessionId: string): Promise<void> {
|
||||
async reOpenSession(sessionId: string, newSessionId: string): Promise<void> {
|
||||
// 初始化客户端
|
||||
await this.initChannel();
|
||||
// 获取会话并且重新设置 sessionId
|
||||
@@ -90,12 +82,8 @@ export default class TerminalSessionManager implements ITerminalSessionManager {
|
||||
session.sessionId = newSessionId;
|
||||
this.sessions[sessionId] = undefined as unknown as ITerminalSession;
|
||||
this.sessions[newSessionId] = session;
|
||||
// 发送会话初始化请求
|
||||
this.channel.send(InputProtocol.CHECK, {
|
||||
sessionId: newSessionId,
|
||||
hostId: session.hostId,
|
||||
connectType: type,
|
||||
});
|
||||
// 连接会话
|
||||
session.connect();
|
||||
}
|
||||
|
||||
// 获取终端会话
|
||||
|
||||
@@ -132,7 +132,7 @@ export interface ITerminalSessionManager {
|
||||
// 打开 sftp 会话
|
||||
openSftp: (tab: TerminalPanelTabItem, resolver: ISftpSessionResolver) => Promise<ISftpSession>;
|
||||
// 重新打开会话
|
||||
reOpenSession: (type: string, sessionId: string, newSessionId: string) => Promise<void>;
|
||||
reOpenSession: (sessionId: string, newSessionId: string) => Promise<void>;
|
||||
// 获取终端会话
|
||||
getSession: <T extends ITerminalSession>(sessionId: string) => T;
|
||||
// 关闭终端会话
|
||||
@@ -211,7 +211,9 @@ export interface ITerminalSession {
|
||||
|
||||
// 设置是否可写
|
||||
setCanWrite: (canWrite: boolean) => void;
|
||||
// 连接
|
||||
// 设置已连接
|
||||
setConnected: () => void;
|
||||
// 连接会话
|
||||
connect: () => void;
|
||||
// 断开连接
|
||||
disconnect: () => void;
|
||||
|
||||
Reference in New Issue
Block a user