import { exec } from 'child_process'; import fs from 'fs'; import path from 'path'; export default function handler(req, res) { if (req.method === 'POST') { // Get the input data from the request body const data = req.body; // Prepare arguments to pass to the Python script if needed const scriptArgs = data.args || []; console.log(scriptArgs) const Arguments = "\"" + scriptArgs.join('" "') + "\""; // Run the Python script and pass the arguments exec(`python3 uziom.py ${Arguments}`, (error, stdout, stderr) => { if (error) { // Handle execution errors console.error(`exec error: ${error}`); return res.status(500).json({ message: 'Internal server error' }); } // The output file needs to have been created by the Python script const filePath = path.resolve('./public/uziom.dxf'); const fileName = 'uziom.dxf'; // Set headers for file download res.setHeader('Content-Disposition', `attachment; filename=${fileName}`); res.setHeader('Content-Type', 'application/dxf'); // Read and send the file data const fileStream = fs.createReadStream(filePath); fileStream.pipe(res); }); } else { // Handle any other HTTP methods if necessary res.status(405).json({ message: 'Method not allowed' }); } }