You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.2 KiB

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 });
}
}

Powered by TurnKey Linux.