import { NextResponse } from 'next/server'; import { controlVM } from '@/lib/ssh'; export async function POST( request: Request, { params }: { params: Promise<{ id: string }> } ) { try { const { id } = await params; const { action } = await request.json(); if (!['start', 'stop', 'restart'].includes(action)) { return NextResponse.json( { error: 'Invalid action. Must be start, stop, or restart' }, { status: 400 } ); } await controlVM(id, action as 'start' | 'stop' | 'restart'); return NextResponse.json({ success: true, message: `VM ${action} command sent successfully` }); } catch (error) { console.error('Error controlling VM:', error); return NextResponse.json( { error: 'Failed to control VM' }, { status: 500 } ); } }