- Replaced static hosts.json and staticConfig.ts with SQLite database (Prisma) - Implemented JWT authentication and Login UI - Added dynamic API routes for hosts, topology, and settings - Updated UI components to fetch and manage state dynamically - Added Settings interface for managing hosts and topology nodes
32 lines
801 B
TypeScript
32 lines
801 B
TypeScript
import { homedir } from 'os';
|
|
import { PrismaClient } from '@prisma/client';
|
|
import { HostConfig } from './types';
|
|
|
|
const prisma = new PrismaClient();
|
|
|
|
export async function getHostConfigs(): Promise<HostConfig[]> {
|
|
try {
|
|
const dbConfigs = await prisma.hostConfig.findMany();
|
|
return dbConfigs.map(h => ({
|
|
name: h.name,
|
|
ip: h.ip,
|
|
sshUser: h.sshUser || 'bear',
|
|
sshKeyPath: h.sshKeyPath?.replace(/^~/, homedir()),
|
|
sshPort: h.sshPort || 22,
|
|
hostType: h.hostType,
|
|
}));
|
|
} catch (error) {
|
|
console.error('Error fetching host configs from DB:', error);
|
|
return [];
|
|
}
|
|
}
|
|
|
|
export async function hasConfig(): Promise<boolean> {
|
|
try {
|
|
const count = await prisma.hostConfig.count();
|
|
return count > 0;
|
|
} catch (error) {
|
|
return false;
|
|
}
|
|
}
|