[Init] Initial commit - NetMesh terminal manager
Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
This commit is contained in:
168
infrastructure/services/vaultImportBatch.ts
Normal file
168
infrastructure/services/vaultImportBatch.ts
Normal file
@@ -0,0 +1,168 @@
|
||||
import type { Host } from "../../domain/models";
|
||||
import {
|
||||
buildVaultHostMergeKey,
|
||||
importVaultHostsFromText,
|
||||
mergeVaultImportIssues,
|
||||
type VaultImportFormat,
|
||||
type VaultImportIssue,
|
||||
type VaultImportResult,
|
||||
} from "../../domain/vaultImport";
|
||||
import {
|
||||
readVaultImportFile,
|
||||
type VaultImportFileEncoding,
|
||||
} from "./vaultImportFile";
|
||||
|
||||
export interface VaultImportBatchProgress {
|
||||
completedFiles: number;
|
||||
totalFiles: number;
|
||||
fileName: string;
|
||||
}
|
||||
|
||||
interface ImportVaultHostFilesOptions {
|
||||
format: VaultImportFormat;
|
||||
files: File[];
|
||||
relativePaths?: string[];
|
||||
encoding?: VaultImportFileEncoding;
|
||||
masterPassword?: string;
|
||||
onProgress?: (progress: VaultImportBatchProgress) => void;
|
||||
}
|
||||
|
||||
const SECURE_CRT_METADATA_FILES = new Set([
|
||||
"__folderdata__.ini",
|
||||
"default.ini",
|
||||
]);
|
||||
|
||||
const normalizeRelativePath = (file: File, transferredRelativePath?: string): string[] => {
|
||||
const relativePath = transferredRelativePath?.trim() || file.webkitRelativePath?.trim();
|
||||
if (!relativePath) return [file.name];
|
||||
return relativePath.split(/[\\/]+/).filter(Boolean);
|
||||
};
|
||||
|
||||
const secureCrtGroupFromFile = (
|
||||
file: File,
|
||||
transferredRelativePath?: string,
|
||||
): string | undefined => {
|
||||
const segments = normalizeRelativePath(file, transferredRelativePath);
|
||||
if (segments.length <= 1) return undefined;
|
||||
|
||||
segments.pop();
|
||||
const selectedRoot = segments.shift();
|
||||
if (
|
||||
selectedRoot?.toLowerCase() !== "sessions"
|
||||
&& segments[0]?.toLowerCase() === "sessions"
|
||||
) {
|
||||
segments.shift();
|
||||
}
|
||||
return segments.length > 0 ? segments.join("/") : undefined;
|
||||
};
|
||||
|
||||
const shouldIgnoreSecureCrtFile = (file: File): boolean => (
|
||||
SECURE_CRT_METADATA_FILES.has(file.name.toLowerCase())
|
||||
|| !file.name.toLowerCase().endsWith(".ini")
|
||||
);
|
||||
|
||||
export async function importVaultHostFiles({
|
||||
format,
|
||||
files,
|
||||
relativePaths,
|
||||
encoding,
|
||||
masterPassword,
|
||||
onProgress,
|
||||
}: ImportVaultHostFilesOptions): Promise<VaultImportResult> {
|
||||
const sourceFiles = files.map((file, index) => ({
|
||||
file,
|
||||
relativePath: relativePaths?.[index],
|
||||
}));
|
||||
const selectedFiles = format === "securecrt"
|
||||
? sourceFiles.filter(({ file }) => !shouldIgnoreSecureCrtFile(file))
|
||||
: sourceFiles.slice(0, 1);
|
||||
const hosts: Host[] = [];
|
||||
const issues: VaultImportIssue[] = [];
|
||||
const keyPassphrases: NonNullable<VaultImportResult["keyPassphrases"]> = [];
|
||||
const keyPassphraseCandidates: NonNullable<VaultImportResult["keyPassphraseCandidates"]> = [];
|
||||
let parsed = 0;
|
||||
let skipped = 0;
|
||||
let duplicates = 0;
|
||||
|
||||
for (let index = 0; index < selectedFiles.length; index++) {
|
||||
const { file, relativePath } = selectedFiles[index];
|
||||
try {
|
||||
const text = await readVaultImportFile(format, file, encoding);
|
||||
const result = importVaultHostsFromText(format, text, {
|
||||
fileName: file.name,
|
||||
masterPassword,
|
||||
});
|
||||
const group = format === "securecrt"
|
||||
? secureCrtGroupFromFile(file, relativePath)
|
||||
: undefined;
|
||||
const fileHosts = result.hosts.map((host) => (
|
||||
group && !host.group ? { ...host, group } : host
|
||||
));
|
||||
|
||||
parsed += result.stats.parsed;
|
||||
skipped += result.stats.skipped;
|
||||
duplicates += result.stats.duplicates;
|
||||
issues.push(...result.issues.map((issue) => ({
|
||||
...issue,
|
||||
message: `${file.name}: ${issue.message}`,
|
||||
})));
|
||||
keyPassphrases.push(...(result.keyPassphrases ?? []));
|
||||
keyPassphraseCandidates.push(...(result.keyPassphraseCandidates ?? []));
|
||||
|
||||
if (fileHosts.length === 0) {
|
||||
if (result.stats.skipped === 0 && result.issues.length === 0) {
|
||||
skipped++;
|
||||
issues.push({
|
||||
level: "warning",
|
||||
message: `${file.name}: no importable SecureCRT session found.`,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
hosts.push(...fileHosts);
|
||||
}
|
||||
} catch (error) {
|
||||
if (format !== "securecrt" || selectedFiles.length <= 1) throw error;
|
||||
skipped++;
|
||||
issues.push({
|
||||
level: "error",
|
||||
message: `${file.name}: ${error instanceof Error ? error.message : "Unable to read file."}`,
|
||||
});
|
||||
} finally {
|
||||
onProgress?.({
|
||||
completedFiles: index + 1,
|
||||
totalFiles: selectedFiles.length,
|
||||
fileName: file.name,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const seen = new Set<string>();
|
||||
const uniqueHosts = format === "securecrt"
|
||||
? hosts
|
||||
: hosts.filter((host) => {
|
||||
const key = buildVaultHostMergeKey(host);
|
||||
if (seen.has(key)) {
|
||||
duplicates++;
|
||||
return false;
|
||||
}
|
||||
seen.add(key);
|
||||
return true;
|
||||
});
|
||||
const groups = Array.from(new Set(
|
||||
uniqueHosts.map((host) => host.group).filter((group): group is string => Boolean(group)),
|
||||
));
|
||||
|
||||
return {
|
||||
hosts: uniqueHosts,
|
||||
groups,
|
||||
issues: mergeVaultImportIssues(issues),
|
||||
stats: {
|
||||
parsed,
|
||||
imported: uniqueHosts.length,
|
||||
skipped,
|
||||
duplicates,
|
||||
},
|
||||
...(keyPassphrases.length > 0 ? { keyPassphrases } : {}),
|
||||
...(keyPassphraseCandidates.length > 0 ? { keyPassphraseCandidates } : {}),
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user