Replaces many uses of logical OR (||) with nullish coalescing (??) for more accurate handling of undefined/null values. Adds explicit type annotations and interfaces to improve type safety, especially in API routes and server-side code. Updates SSH connection test handling and config parsing in installedScripts router for better reliability. Minor fixes to deduplication logic, cookie handling, and error reporting.
34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
import type { NextRequest } from 'next/server';
|
|
import { NextResponse } from 'next/server';
|
|
import { getSSHService } from '../../../../server/ssh-service';
|
|
import { getDatabase } from '../../../../server/database-prisma';
|
|
import { withApiLogging } from '../../../../server/logging/withApiLogging';
|
|
|
|
export const POST = withApiLogging(async function POST(_request: NextRequest) {
|
|
try {
|
|
const sshService = getSSHService();
|
|
const db = getDatabase();
|
|
|
|
// Get the next available server ID for key file naming
|
|
const serverId = await db.getNextServerId();
|
|
|
|
const keyPair = await sshService.generateKeyPair(Number(serverId));
|
|
|
|
return NextResponse.json({
|
|
success: true,
|
|
privateKey: keyPair.privateKey,
|
|
publicKey: keyPair.publicKey,
|
|
serverId: serverId
|
|
});
|
|
} catch (error) {
|
|
// Error handled by withApiLogging
|
|
return NextResponse.json(
|
|
{
|
|
success: false,
|
|
error: error instanceof Error ? error.message : 'Failed to generate SSH key pair'
|
|
},
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}, { redactBody: true });
|