Files
przekroj/pages/api/generateDxf.js
Cyber Panel 5c11a289df Add uziom generation script and update wet input documents
- Created a new Python script `uziom.py` for generating DXF drawings of grounding systems based on user input parameters.
- Added detailed documentation in `wet_input_15.docx` and `wet_input_3.docx` for the design of grounding systems, including calculations for resistance and resistivity measurements.
- Included placeholders for dynamic data insertion in the documents to facilitate project-specific customization.
2025-07-01 11:14:49 +02:00

39 lines
1.3 KiB
JavaScript

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