From 7f9427bde551b01bfad067d76ac17a519097a292 Mon Sep 17 00:00:00 2001 From: GoldenFishX Date: Sun, 31 May 2026 19:57:14 +0800 Subject: [PATCH] =?UTF-8?q?fix(file-provider):=20SSHFileProvider=20?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=87=AA=E5=AE=9A=E4=B9=89=E7=AB=AF=E5=8F=A3?= =?UTF-8?q?=20(#1181)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 之前 SSHFileProvider 的 sshArgs() 方法硬编码使用默认端口 22, 完全忽略 TERMINAL_SSH_PORT 环境变量配置的自定义 SSH 端口。 修复内容: - TerminalConfig 接口新增 ssh_port 字段 - SSHFileProvider 构造函数新增 port 参数 - sshArgs() 在 this.port 存在时追加 -p - getSSHEnvVars() 读取 TERMINAL_SSH_PORT 并解析为整数 - createFileProvider() 工厂函数传入 ssh.port 影响范围:所有通过 SSH 后端的文件操作(读/写/列出/删除/重命名/创建目录/复制/上传) --- packages/server/src/services/hermes/file-provider.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/server/src/services/hermes/file-provider.ts b/packages/server/src/services/hermes/file-provider.ts index aad1129..eb80ec1 100644 --- a/packages/server/src/services/hermes/file-provider.ts +++ b/packages/server/src/services/hermes/file-provider.ts @@ -61,6 +61,7 @@ export interface TerminalConfig { docker_container_name?: string cwd?: string singularity_image?: string + ssh_port?: number } /** @@ -421,18 +422,20 @@ export class SSHFileProvider implements FileProvider { private host: string private user: string private keyPath?: string + private port?: number private homeDir: string - constructor(host: string, user: string, keyPath?: string, homeDir = getActiveProfileDir()) { + constructor(host: string, user: string, keyPath?: string, homeDir = getActiveProfileDir(), port?: number) { this.host = host this.user = user this.keyPath = keyPath + this.port = port this.homeDir = homeDir } private sshArgs(): string[] { - // StrictHostKeyChecking disabled for automated tooling with user-configured hosts const args = ['-o', 'StrictHostKeyChecking=no', '-o', 'BatchMode=yes'] + if (this.port) args.push('-p', String(this.port)) if (this.keyPath) args.push('-i', this.keyPath) args.push(`${this.user}@${this.host}`) return args @@ -740,7 +743,7 @@ export function getTerminalConfig(profile?: string): TerminalConfig { /** * Read SSH env vars from hermes .env file. */ -function getSSHEnvVars(profile?: string): { host?: string; user?: string; key?: string } { +function getSSHEnvVars(profile?: string): { host?: string; user?: string; key?: string; port?: number } { try { const envPath = envPathForProfile(profile) if (!existsSync(envPath)) return {} @@ -761,6 +764,7 @@ function getSSHEnvVars(profile?: string): { host?: string; user?: string; key?: host: vars.TERMINAL_SSH_HOST, user: vars.TERMINAL_SSH_USER, key: vars.TERMINAL_SSH_KEY, + port: vars.TERMINAL_SSH_PORT ? parseInt(vars.TERMINAL_SSH_PORT, 10) : undefined, } } catch { return {} @@ -827,7 +831,7 @@ export async function createFileProvider(profile?: string): Promise