import { NextResponse } from 'next/server'; import fs from 'fs'; import path from 'path'; const tftpDir = '/var/lib/tftpboot/'; export async function GET(request, { params }) { const { filename } = params; const filepath = path.join(tftpDir, filename); if (fs.existsSync(filepath)) { const fileStream = fs.createReadStream(filepath); return new NextResponse(fileStream, { headers: { 'Content-Disposition': `attachment; filename="${filename}"`, 'Content-Type': 'application/octet-stream', }, }); } else { return NextResponse.json({ error: 'File not found' }, { status: 404 }); } } export async function DELETE(request, { params }) { const { filename } = params; const filepath = path.join(tftpDir, filename); if (fs.existsSync(filepath)) { try { fs.unlinkSync(filepath); return NextResponse.json({ success: true }); } catch (error) { return NextResponse.json({ error: 'Failed to delete file' }, { status: 500 }); } } else { return NextResponse.json({ error: 'File not found' }, { status: 404 }); } }