fix: 添加缺失的参数
This commit is contained in:
@@ -200,7 +200,7 @@ export function useAddConnectionForm(props: AddConnectionFormProps, emit: AddCon
|
||||
};
|
||||
|
||||
// Helper function to parse a single script line
|
||||
const parseScriptLine = (line: string): { type: 'SSH' | 'RDP' | 'VNC' | null, userHostPort: string, name: string | null, password: string | null, keyName: string | null, tags: string[], note: string | null, error?: string } => {
|
||||
const parseScriptLine = (line: string): { type: 'SSH' | 'RDP' | 'VNC' | null, userHostPort: string, name: string | null, password: string | null, keyName: string | null, proxyName: string | null, tags: string[], note: string | null, error?: string } => {
|
||||
const firstSpaceIndex = line.indexOf(' ');
|
||||
let userHostPortPart = '';
|
||||
let remainingLine = line;
|
||||
@@ -213,12 +213,13 @@ export function useAddConnectionForm(props: AddConnectionFormProps, emit: AddCon
|
||||
remainingLine = '';
|
||||
}
|
||||
|
||||
if (!userHostPortPart) return { type: null, userHostPort: '', name: null, password: null, keyName: null, tags: [], note: null, error: t('connections.form.scriptErrorMissingHost', '缺少 user@host:port 部分') };
|
||||
if (!userHostPortPart) return { type: null, userHostPort: '', name: null, password: null, keyName: null, proxyName: null, tags: [], note: null, error: t('connections.form.scriptErrorMissingHost', '缺少 user@host:port 部分') };
|
||||
|
||||
let type: 'SSH' | 'RDP' | 'VNC' | null = 'SSH';
|
||||
let name: string | null = null;
|
||||
let password: string | null = null;
|
||||
let keyName: string | null = null;
|
||||
let proxyName: string | null = null;
|
||||
const tags: string[] = [];
|
||||
let note: string | null = null;
|
||||
let currentArg: string | null = null;
|
||||
@@ -256,7 +257,7 @@ export function useAddConnectionForm(props: AddConnectionFormProps, emit: AddCon
|
||||
if (upperType === 'SSH' || upperType === 'RDP' || upperType === 'VNC') {
|
||||
type = upperType as 'SSH' | 'RDP' | 'VNC';
|
||||
} else {
|
||||
return { type: null, userHostPort: userHostPortPart, name, password, keyName, tags, note, error: t('connections.form.scriptErrorInvalidType', { type: value }) };
|
||||
return { type: null, userHostPort: userHostPortPart, name, password, keyName, proxyName, tags, note, error: t('connections.form.scriptErrorInvalidType', { type: value }) };
|
||||
}
|
||||
currentArg = null;
|
||||
break;
|
||||
@@ -272,6 +273,10 @@ export function useAddConnectionForm(props: AddConnectionFormProps, emit: AddCon
|
||||
keyName = value;
|
||||
currentArg = null;
|
||||
break;
|
||||
case '-proxy':
|
||||
proxyName = value;
|
||||
currentArg = null;
|
||||
break;
|
||||
case '-tags':
|
||||
tags.push(value);
|
||||
break;
|
||||
@@ -282,7 +287,7 @@ export function useAddConnectionForm(props: AddConnectionFormProps, emit: AddCon
|
||||
if (currentArg === '-note') {
|
||||
noteParts.push(value);
|
||||
} else {
|
||||
return { type, userHostPort: userHostPortPart, name, password, keyName, tags, note, error: t('connections.form.scriptErrorUnknownArg', { arg: currentArg }) };
|
||||
return { type, userHostPort: userHostPortPart, name, password, keyName, proxyName, tags, note, error: t('connections.form.scriptErrorUnknownArg', { arg: currentArg }) };
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -304,7 +309,7 @@ export function useAddConnectionForm(props: AddConnectionFormProps, emit: AddCon
|
||||
} else if (currentArg === '-note') {
|
||||
noteParts.push(remainingPart);
|
||||
} else {
|
||||
return { type, userHostPort: userHostPortPart, name, password, keyName, tags, note, error: t('connections.form.scriptErrorUnexpectedToken', { token: remainingPart }) };
|
||||
return { type, userHostPort: userHostPortPart, name, password, keyName, proxyName, tags, note, error: t('connections.form.scriptErrorUnexpectedToken', { token: remainingPart }) };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -314,10 +319,10 @@ export function useAddConnectionForm(props: AddConnectionFormProps, emit: AddCon
|
||||
|
||||
const userHostPortRegex = /^[^@]+@[^:]+(:[0-9]+)?$/;
|
||||
if (!userHostPortRegex.test(userHostPortPart)) {
|
||||
return { type, userHostPort: userHostPortPart, name, password, keyName, tags, note, error: t('connections.form.scriptErrorInvalidUserHostPort', { part: userHostPortPart })};
|
||||
return { type, userHostPort: userHostPortPart, name, password, keyName, proxyName, tags, note, error: t('connections.form.scriptErrorInvalidUserHostPort', { part: userHostPortPart })};
|
||||
}
|
||||
|
||||
return { type, userHostPort: userHostPortPart, name, password, keyName, tags, note };
|
||||
|
||||
return { type, userHostPort: userHostPortPart, name, password, keyName, proxyName, tags, note };
|
||||
};
|
||||
|
||||
// 处理表单提交
|
||||
@@ -369,6 +374,7 @@ export function useAddConnectionForm(props: AddConnectionFormProps, emit: AddCon
|
||||
username,
|
||||
notes: parsed.note || '',
|
||||
tag_names: parsed.tags,
|
||||
proxy_name: parsed.proxyName,
|
||||
};
|
||||
|
||||
if (parsed.type === 'SSH') {
|
||||
@@ -443,6 +449,18 @@ export function useAddConnectionForm(props: AddConnectionFormProps, emit: AddCon
|
||||
delete connData.ssh_key_name;
|
||||
}
|
||||
|
||||
if (connData.proxy_name) {
|
||||
const foundProxy = proxies.value.find(p => p.name === connData.proxy_name);
|
||||
if (foundProxy) {
|
||||
connData.proxy_id = foundProxy.id;
|
||||
} else {
|
||||
uiNotificationsStore.showError(t('proxies.errors.notFound', { name: connData.proxy_name })); // Assuming you add this translation
|
||||
resolutionErrorOccurred = true;
|
||||
break;
|
||||
}
|
||||
delete connData.proxy_name;
|
||||
}
|
||||
|
||||
if (connData.type !== 'SSH' || connData.auth_method !== 'key') delete connData.ssh_key_id;
|
||||
if (connData.type === 'SSH' && connData.auth_method === 'key') delete connData.password;
|
||||
if (connData.type !== 'SSH') delete connData.auth_method;
|
||||
|
||||
@@ -203,7 +203,7 @@
|
||||
"sectionScriptMode": "Script Mode",
|
||||
"scriptModeInputLabel": "Connection Script (one per line)",
|
||||
"scriptModePlaceholder": "Enter connection script, one connection configuration per line.",
|
||||
"scriptModeFormatInfo": "Format: user@host:port [-type TYPE] [-name NAME] [-p PASSWORD] [-k KEY_NAME] [-tags TAG1 TAG2...] [-note NOTE_TEXT]\nParameter Explanation:\n user@host:port - Username@Hostname or IP:Port (required)\n -type TYPE - Connection type (SSH, RDP, VNC; defaults to SSH)\n -name NAME - Display name for the connection (optional; defaults to user@host)\n -p PASSWORD - Password (required for SSH password auth, RDP, VNC)\n -k KEY_NAME - SSH key name (required for SSH key auth, corresponds to an uploaded key)\n -tags TAG1 TAG2 - List of tags, space-separated (optional)\n -note NOTE_TEXT - Connection notes (optional, supports text with spaces, use quotes if it includes special characters)",
|
||||
"scriptModeFormatInfo": "Format: user@host:port [-type TYPE] [-name NAME] [-p PASSWORD] [-k KEY_NAME] [-proxy PROXY_NAME] [-tags TAG1 TAG2...] [-note NOTE_TEXT]\nParameter Explanation:\n user@host:port - Username@Hostname or IP:Port (required)\n -type TYPE - Connection type (SSH, RDP, VNC; defaults to SSH)\n -name NAME - Display name for the connection (optional; defaults to user@host)\n -p PASSWORD - Password (required for SSH password auth, RDP, VNC)\n -k KEY_NAME - SSH key name (required for SSH key auth, corresponds to an uploaded key)\n -proxy PROXY_NAME - Proxy name (optional, corresponds to a configured proxy)\n -tags TAG1 TAG2 - List of tags, space-separated (optional)\n -note NOTE_TEXT - Connection notes (optional, supports text with spaces, use quotes if it includes special characters)",
|
||||
"scriptErrorMissingHost": "Script line '{line}' is missing the 'user@host:port' part.",
|
||||
"scriptErrorInvalidType": "Invalid type '{type}' in script line '{line}'. Valid types are SSH, RDP, VNC.",
|
||||
"scriptErrorUnknownArg": "Unknown argument '{arg}' in script line '{line}'.",
|
||||
|
||||
@@ -188,7 +188,7 @@
|
||||
"sectionScriptMode": "スクリプトモード",
|
||||
"scriptModeInputLabel": "接続スクリプト (1行に1つ)",
|
||||
"scriptModePlaceholder": "接続スクリプトを入力してください。1行に1つの接続設定。",
|
||||
"scriptModeFormatInfo": "書式: ユーザー名@ホスト名またはIP:ポート [-type タイプ] [-name 名前] [-p パスワード] [-k キー名] [-tags タグ1 タグ2...] [-note 注意書き]\nパラメータ説明:\n ユーザー名@ホスト名またはIP:ポート - ユーザー名@ホスト名またはIPアドレス:ポート番号 (必須)\n -type タイプ - 接続タイプ (SSH, RDP, VNC; デフォルトは SSH)\n -name 名前 - 接続の表示名 (任意; デフォルトは ユーザー名@ホスト名)\n -p パスワード - パスワード (SSHパスワード認証, RDP, VNC の場合に必要)\n -k キー名 - SSHキー名 (SSHキー認証の場合に必要, アップロード済みのキーに対応)\n -tags タグ1 タグ2 - タグのリスト, スペース区切り (任意)\n -note 注意書き - 接続に関する注意書き (任意, スペースを含むテキストをサポート, 特殊文字を含む場合は引用符を使用)",
|
||||
"scriptModeFormatInfo": "書式: ユーザー名@ホスト名またはIP:ポート [-type タイプ] [-name 名前] [-p パスワード] [-k キー名] [-proxy PROXY_NAME] [-tags タグ1 タグ2...] [-note 注意書き]\nパラメータ説明:\n ユーザー名@ホスト名またはIP:ポート - ユーザー名@ホスト名またはIPアドレス:ポート番号 (必須)\n -type タイプ - 接続タイプ (SSH, RDP, VNC; デフォルトは SSH)\n -name 名前 - 接続の表示名 (任意; デフォルトは ユーザー名@ホスト名)\n -p パスワード - パスワード (SSHパスワード認証, RDP, VNC の場合に必要)\n -k キー名 - SSHキー名 (SSHキー認証の場合に必要, アップロード済みのキーに対応)\n -proxy PROXY_NAME - プロキシ名 (任意, 設定済みのプロキシに対応)\n -tags タグ1 タグ2 - タグのリスト, スペース区切り (任意)\n -note 注意書き - 接続に関する注意書き (任意, スペースを含むテキストをサポート, 特殊文字を含む場合は引用符を使用)",
|
||||
"scriptErrorMissingHost": "スクリプト行 '{line}' には 'user@host:port' 部分がありません。",
|
||||
"scriptErrorInvalidType": "スクリプト行 '{line}' のタイプ '{type}' は無効です。有効なタイプは SSH, RDP, VNC です。",
|
||||
"scriptErrorUnknownArg": "スクリプト行 '{line}' に不明な引数 '{arg}' があります。",
|
||||
|
||||
@@ -202,7 +202,7 @@
|
||||
"sectionScriptMode": "脚本模式",
|
||||
"scriptModeInputLabel": "连接脚本 (每行一个)",
|
||||
"scriptModePlaceholder": "请输入连接脚本,每行一个连接配置。",
|
||||
"scriptModeFormatInfo": "格式: user@host:port [-type TYPE] [-name NAME] [-p PASSWORD] [-k KEY_NAME] [-tags TAG1 TAG2...] [-note NOTE_TEXT]\n参数说明:\n user@host:port - 用户名@主机名或IP:端口号 (必需)\n -type TYPE - 连接类型 (SSH, RDP, VNC; 默认为 SSH)\n -name NAME - 连接的显示名称 (可选; 默认为 user@host)\n -p PASSWORD - 密码 (SSH密码认证, RDP, VNC 时需要)\n -k KEY_NAME - SSH密钥名称 (SSH密钥认证时需要, 对应已上传的密钥)\n -tags TAG1 TAG2 - 标签列表, 用空格分隔 (可选)\n -note NOTE_TEXT - 连接备注 (可选, 支持带空格的文本, 如果包含特殊字符请使用引号)",
|
||||
"scriptModeFormatInfo": "格式: user@host:port [-type TYPE] [-name NAME] [-p PASSWORD] [-k KEY_NAME] [-proxy PROXY_NAME] [-tags TAG1 TAG2...] [-note NOTE_TEXT]\n参数说明:\n user@host:port - 用户名@主机名或IP:端口号 (必需)\n -type TYPE - 连接类型 (SSH, RDP, VNC; 默认为 SSH)\n -name NAME - 连接的显示名称 (可选; 默认为 user@host)\n -p PASSWORD - 密码 (SSH密码认证, RDP, VNC 时需要)\n -k KEY_NAME - SSH密钥名称 (SSH密钥认证时需要, 对应已上传的密钥)\n -proxy PROXY_NAME - 代理名称 (可选, 对应已配置的代理)\n -tags TAG1 TAG2 - 标签列表, 用空格分隔 (可选)\n -note NOTE_TEXT - 连接备注 (可选, 支持带空格的文本, 如果包含特殊字符请使用引号)",
|
||||
"scriptErrorMissingHost": "脚本行 '{line}' 缺少 'user@host:port' 部分。",
|
||||
"scriptErrorInvalidType": "脚本行 '{line}' 中的类型 '{type}' 无效。有效类型为 SSH, RDP, VNC。",
|
||||
"scriptErrorUnknownArg": "脚本行 '{line}' 中存在未知参数 '{arg}'。",
|
||||
|
||||
Reference in New Issue
Block a user