mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-30 15:15:24 +00:00
fix: proxmox guest sync, startup snippet sync, drop dead cloudflare ssh transport
This commit is contained in:
1 parent
44062e30d1
commit
ffa872ebd3
19 files changed
+270
-292
No files matched your search
@@ -0,0 +1,78 @@
|
||||
export type ProxmoxSource = {
|
||||
source: "proxmox";
|
||||
sourceHostId: number;
|
||||
node: string;
|
||||
vmid: number;
|
||||
type: "qemu" | "lxc";
|
||||
lastSeenAt?: string;
|
||||
lastStatus?: string;
|
||||
missingSince?: string | null;
|
||||
};
|
||||
|
||||
export function parseJsonObject(value: unknown): Record<string, unknown> {
|
||||
if (!value) return {};
|
||||
if (typeof value === "object") return value as Record<string, unknown>;
|
||||
if (typeof value !== "string") return {};
|
||||
try {
|
||||
const parsed = JSON.parse(value);
|
||||
return parsed && typeof parsed === "object"
|
||||
? (parsed as Record<string, unknown>)
|
||||
: {};
|
||||
} catch {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
/** The guest a host was imported from, read from its proxmoxConfig setting. */
|
||||
export function getProxmoxSource(config: unknown): ProxmoxSource | null {
|
||||
const source = parseJsonObject(config).source;
|
||||
if (!source || typeof source !== "object") return null;
|
||||
const src = source as Record<string, unknown>;
|
||||
if (
|
||||
src.source !== "proxmox" ||
|
||||
typeof src.sourceHostId !== "number" ||
|
||||
typeof src.node !== "string" ||
|
||||
typeof src.vmid !== "number" ||
|
||||
(src.type !== "qemu" && src.type !== "lxc")
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
return src as ProxmoxSource;
|
||||
}
|
||||
|
||||
export function proxmoxSourceKey(source: {
|
||||
sourceHostId: number;
|
||||
node: string;
|
||||
type: string;
|
||||
vmid: number;
|
||||
}): string {
|
||||
return `${source.sourceHostId}:${source.node}:${source.type}:${source.vmid}`;
|
||||
}
|
||||
|
||||
export interface ImportedGuest {
|
||||
host: Record<string, unknown>;
|
||||
config: Record<string, unknown>;
|
||||
source: ProxmoxSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* The hosts already imported from one Proxmox node, keyed by guest. The
|
||||
* source lives in each guest's proxmoxConfig host setting, not on the host
|
||||
* row, so the caller passes both.
|
||||
*/
|
||||
export function indexImportedGuests(
|
||||
hosts: Record<string, unknown>[],
|
||||
configs: Array<{ hostId: number; value: unknown }>,
|
||||
sourceHostId: number,
|
||||
): Map<string, ImportedGuest> {
|
||||
const configById = new Map(configs.map((c) => [c.hostId, c.value]));
|
||||
const out = new Map<string, ImportedGuest>();
|
||||
for (const host of hosts) {
|
||||
const config = parseJsonObject(configById.get(Number(host.id)));
|
||||
const source = getProxmoxSource(config);
|
||||
if (source?.sourceHostId === sourceHostId) {
|
||||
out.set(proxmoxSourceKey(source), { host, config, source });
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
Reference in new issue
Block a user