fix: wrap ssh host json export in hosts array

This commit is contained in:
LukeGus
2025-12-22 02:09:45 -06:00
parent 28729e3de2
commit a73f767072
4 changed files with 76 additions and 53 deletions

View File

@@ -1,5 +1,6 @@
import type { Client } from "ssh2"; import type { Client } from "ssh2";
import { execCommand } from "./common-utils.js"; import { execCommand } from "./common-utils.js";
import { statsLogger } from "../../utils/logger.js";
export interface LoginRecord { export interface LoginRecord {
user: string; user: string;

View File

@@ -8,8 +8,8 @@ export async function collectProcessesMetrics(client: Client): Promise<{
top: Array<{ top: Array<{
pid: string; pid: string;
user: string; user: string;
cpu: number; cpu: string;
mem: number; mem: string;
command: string; command: string;
}>; }>;
}> { }> {
@@ -18,8 +18,8 @@ export async function collectProcessesMetrics(client: Client): Promise<{
const topProcesses: Array<{ const topProcesses: Array<{
pid: string; pid: string;
user: string; user: string;
cpu: number; cpu: string;
mem: number; mem: string;
command: string; command: string;
}> = []; }> = [];
@@ -38,8 +38,8 @@ export async function collectProcessesMetrics(client: Client): Promise<{
topProcesses.push({ topProcesses.push({
pid: parts[1], pid: parts[1],
user: parts[0], user: parts[0],
cpu: Number.isFinite(cpuVal) ? cpuVal : 0, cpu: Number.isFinite(cpuVal) ? cpuVal.toString() : "0",
mem: Number.isFinite(memVal) ? memVal : 0, mem: Number.isFinite(memVal) ? memVal.toString() : "0",
command: parts.slice(10).join(" ").substring(0, 50), command: parts.slice(10).join(" ").substring(0, 50),
}); });
} }

View File

@@ -363,7 +363,12 @@ export function HostManagerViewer({ onEditHost }: SSHManagerHostViewerProps) {
), ),
); );
const blob = new Blob([JSON.stringify(cleanExportData, null, 2)], { // Wrap in hosts array for valid import format
const exportFormat = {
hosts: [cleanExportData],
};
const blob = new Blob([JSON.stringify(exportFormat, null, 2)], {
type: "application/json", type: "application/json",
}); });
const url = URL.createObjectURL(blob); const url = URL.createObjectURL(blob);

View File

@@ -799,59 +799,76 @@ export function Auth({
if (dbConnectionFailed) { if (dbConnectionFailed) {
return ( return (
<div <div
className={`w-[420px] max-w-full p-6 flex flex-col bg-dark-bg border-2 border-dark-border rounded-md overflow-y-auto my-2 animate-in fade-in zoom-in-95 duration-300 ${className || ""}`} className={`fixed inset-0 flex items-center justify-center ${className || ""}`}
style={{ maxHeight: "calc(100vh - 1rem)" }} style={{
background: "#0e0e10",
backgroundImage: `repeating-linear-gradient(
45deg,
transparent,
transparent 35px,
rgba(255, 255, 255, 0.03) 35px,
rgba(255, 255, 255, 0.03) 37px
)`,
}}
{...props} {...props}
> >
<div className="mb-6 text-center"> <div
<h2 className="text-xl font-bold mb-1"> className={`w-[420px] max-w-full p-6 flex flex-col bg-dark-bg border-2 border-dark-border rounded-md overflow-y-auto my-2 animate-in fade-in zoom-in-95 duration-300 ${className || ""}`}
{t("errors.databaseConnection")} style={{ maxHeight: "calc(100vh - 1rem)" }}
</h2> {...props}
<p className="text-muted-foreground"> >
{t("messages.databaseConnectionFailed")} <div className="mb-6 text-center">
</p> <h2 className="text-xl font-bold mb-1">
</div> {t("errors.databaseConnection")}
</h2>
<div className="flex flex-col gap-4"> <p className="text-muted-foreground">
<Button {t("messages.databaseConnectionFailed")}
type="button" </p>
variant="outline"
className="w-full h-11 text-base font-semibold"
disabled={dbHealthChecking}
onClick={() => window.location.reload()}
>
{t("common.refresh")}
</Button>
</div>
<div className="mt-6 pt-4 border-t border-dark-border space-y-4">
<div className="flex items-center justify-between">
<div>
<Label className="text-sm text-muted-foreground">
{t("common.language")}
</Label>
</div>
<LanguageSwitcher />
</div> </div>
{isElectron() && currentServerUrl && (
<div className="flex flex-col gap-4">
<Button
type="button"
variant="outline"
className="w-full h-11 text-base font-semibold"
disabled={dbHealthChecking}
onClick={() => window.location.reload()}
>
{t("common.refresh")}
</Button>
</div>
<div className="mt-6 pt-4 border-t border-dark-border space-y-4">
<div className="flex items-center justify-between"> <div className="flex items-center justify-between">
<div> <div>
<Label className="text-sm text-muted-foreground">Server</Label> <Label className="text-sm text-muted-foreground">
<div className="text-xs text-muted-foreground truncate max-w-[200px]"> {t("common.language")}
{currentServerUrl} </Label>
</div>
</div> </div>
<Button <LanguageSwitcher />
type="button"
variant="outline"
size="sm"
onClick={() => setShowServerConfig(true)}
className="h-8 px-3"
>
Edit
</Button>
</div> </div>
)} {isElectron() && currentServerUrl && (
<div className="flex items-center justify-between">
<div>
<Label className="text-sm text-muted-foreground">
Server
</Label>
<div className="text-xs text-muted-foreground truncate max-w-[200px]">
{currentServerUrl}
</div>
</div>
<Button
type="button"
variant="outline"
size="sm"
onClick={() => setShowServerConfig(true)}
className="h-8 px-3"
>
Edit
</Button>
</div>
)}
</div>
</div> </div>
</div> </div>
); );