feat: add export JSON option for SSH hosts (#173)

This commit is contained in:
Shivam Kumar
2025-09-06 11:38:59 +05:30
parent af1926bb3e
commit 3b5ea6f692

View File

@@ -86,6 +86,37 @@ export function HostManagerHostViewer({onEditHost}: SSHManagerHostViewerProps) {
}
};
const handleExport = (host: SSHHost) => {
const exportData = {
name: host.name,
ip: host.ip,
port: host.port,
username: host.username,
authType: host.authType,
folder: host.folder,
tags: host.tags,
pin: host.pin,
enableTerminal: host.enableTerminal,
enableTunnel: host.enableTunnel,
enableFileManager: host.enableFileManager,
defaultPath: host.defaultPath,
tunnelConnections: host.tunnelConnections,
};
const blob = new Blob([JSON.stringify(exportData, null, 2)], { type: 'application/json' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `${host.name || host.username + '@' + host.ip}-credentials.json`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
toast.success(`Exported credentials for ${host.name || host.username}@${host.ip}`);
};
const handleEdit = (host: SSHHost) => {
if (onEditHost) {
onEditHost(host);
@@ -427,6 +458,18 @@ export function HostManagerHostViewer({onEditHost}: SSHManagerHostViewerProps) {
>
<Trash2 className="h-3 w-3"/>
</Button>
<Button
size="sm"
variant="ghost"
onClick={(e) => {
e.stopPropagation();
handleExport(host);
}}
className="h-5 w-5 p-0 text-blue-500 hover:text-blue-700"
>
<Upload className="h-3 w-3"/>
</Button>
</div>
</div>