This commit is contained in:
Baobhan Sith
2025-04-24 14:17:20 +08:00
parent 7c46132d30
commit 1ae14ea80c
5 changed files with 104 additions and 28 deletions
+13 -1
View File
@@ -119,9 +119,21 @@ export const establishSshConnection = (
keepaliveCountMax: 10,
};
const readyHandler = () => {
const readyHandler = async () => { // 改为 async 函数
console.log(`SshService: SSH 连接到 ${connDetails.host}:${connDetails.port} (ID: ${connDetails.id}) 成功。`);
sshClient.removeListener('error', errorHandler); // 成功后移除错误监听器
// --- 新增:更新 last_connected_at ---
try {
const currentTimeSeconds = Math.floor(Date.now() / 1000);
await ConnectionRepository.updateLastConnected(connDetails.id, currentTimeSeconds);
console.log(`SshService: 已更新连接 ${connDetails.id} 的 last_connected_at 为 ${currentTimeSeconds}`);
} catch (updateError) {
// 更新失败不应阻止连接成功,但需要记录错误
console.error(`SshService: 更新连接 ${connDetails.id} 的 last_connected_at 失败:`, updateError);
}
// --- 结束新增 ---
resolve(sshClient); // 返回 Client 实例
};