Files
Netcatty/domain/quickConnectHost.ts
T
陈大猫 58c6a216ac feat: save SSH input compatibility per host (#3977)
* feat: save SSH input compatibility per host

* test: update extracted input harnesses for host mode

* test: provide required sync vault fields

* test: cover legacy cloud host migration after import

* fix: preserve non-SSH input compatibility behavior

* fix: keep Mosh and Eternal Terminal input policy unchanged

* fix: default new SSH link and importer drafts to standard input

* fix: retain connection input mode across renderer hibernation

* docs: distinguish input timing and native SSH evidence

* docs: record final native input compatibility acceptance
2026-10-26 23:16:06 +08:00

87 lines
2.4 KiB
TypeScript

import { sanitizeCredentialValue } from "./credentials";
import type { Host, Identity, SSHKey } from "./models";
import type { QuickConnectTarget } from "./quickConnect";
export type QuickConnectProtocol = "ssh" | "mosh" | "et" | "telnet";
export type QuickConnectAuthMethod = "password" | "key" | "certificate";
export const getQuickConnectDefaultPort = (
protocol: QuickConnectProtocol,
): number => protocol === "telnet" ? 23 : 22;
export const isQuickConnectIdentityUsable = (
identity: Identity | undefined,
keys: SSHKey[],
protocol: QuickConnectProtocol = "ssh",
): boolean => {
if (!identity?.username.trim() || protocol === "telnet") return false;
if (identity.authMethod === "password") {
return Boolean(sanitizeCredentialValue(identity.password));
}
return Boolean(identity.keyId && keys.some((key) => key.id === identity.keyId));
};
export const isQuickConnectIdentityCompatible = (
identity: Identity,
target: QuickConnectTarget,
): boolean => !target.isJumpServerLogin
|| identity.username === target.username;
type BuildQuickConnectHostInput = {
id: string;
createdAt: number;
target: QuickConnectTarget;
protocol: QuickConnectProtocol;
port: number;
username: string;
authMethod: QuickConnectAuthMethod;
password?: string;
selectedKeyId?: string | null;
selectedIdentityId?: string | null;
save?: boolean;
};
export const buildQuickConnectHost = ({
id,
createdAt,
target,
protocol,
port,
username,
authMethod,
password,
selectedKeyId,
selectedIdentityId,
save = false,
}: BuildQuickConnectHostInput): Host => {
const isTelnet = protocol === "telnet";
const applicableIdentityId = isTelnet ? undefined : selectedIdentityId || undefined;
return {
id,
label: target.hostname,
hostname: target.hostname,
port,
username,
group: "",
tags: [],
os: "linux",
protocol: protocol === "mosh" || protocol === "et" ? "ssh" : protocol,
authMethod,
sshInputCompatibility: false,
identityId: applicableIdentityId,
password: !applicableIdentityId && authMethod === "password" ? password : undefined,
identityFileId:
!applicableIdentityId && authMethod !== "password"
? selectedKeyId || undefined
: undefined,
moshEnabled: protocol === "mosh",
etEnabled: protocol === "et",
etPort: protocol === "et" ? 2022 : undefined,
telnetEnabled: isTelnet,
telnetPort: isTelnet ? port : undefined,
ephemeral: !save,
createdAt,
};
};