import { NextResponse } from 'next/server'; import { powerControl } from '@/lib/proxmox'; /** * @param {import('next').Request} req */ export async function POST(req) { try { const { node, vmid, type, action } = await req.json(); if (!node || !vmid || !type || !action) { return NextResponse.json({ error: 'Missing required fields' }, { status: 400 }); } if (!['qemu', 'lxc'].includes(type)) { return NextResponse.json({ error: 'Invalid type, must be qemu or lxc' }, { status: 400 }); } if (!['start', 'stop', 'restart'].includes(action)) { return NextResponse.json({ error: 'Invalid action, must be start, stop, or restart' }, { status: 400 }); } await powerControl(node, vmid, type, action); return NextResponse.json({ ok: true, timestamp: Date.now() }); } catch (error) { return NextResponse.json({ error: error.message, ok: false }, { status: 502 }); } }