Skip to content

Commit

Permalink
Replace deprecated request with axios.
Browse files Browse the repository at this point in the history
remove contributor list
  • Loading branch information
Dexus authored and abebeos committed Dec 25, 2024
1 parent 05df0bf commit 58d9d13
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 51 deletions.
113 changes: 64 additions & 49 deletions main/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
const remote = require('@electron/remote');
const { dialog } = remote;
const fs = require('graceful-fs');
const request = require('request');
const FormData = require('form-data');
const axios = require('axios').default;
const http = require('http');
const path = require('path');

Expand Down Expand Up @@ -627,43 +628,49 @@
url = defaultConversionServer;
}

var req = request.post(url, function (err, resp, body) {
if (err) {
message('could not contact file conversion server', true);
const formData = new FormData();
formData.append('fileUpload', require('fs').readFileSync(file), {
filename: filename,
contentType: 'application/dxf'
});
formData.append('format', 'svg');

axios.post(url, formData.getBuffer(), {
headers: {
...formData.getHeaders(),
},
responseType: 'text'
}).then(resp => {
const body = resp.data;
if (body.substring(0, 5) == 'error') {
message(body, true);
} else {
if(body.substring(0, 5) == 'error'){
message(body, true);
}
else{
// expected input dimensions on server is points
// scale based on unit preferences
var con = null;
var dxfFlag = false;
if(ext.toLowerCase() == '.dxf'){
//var unit = config.getSync('units');
con = Number(config.getSync('dxfImportScale'));
dxfFlag = true;
console.log('con', con);

/*if(unit == 'inch'){
con = 72;
}
else{
// mm
con = 2.83465;
}*/
// expected input dimensions on server is points
// scale based on unit preferences
var con = null;
var dxfFlag = false;
if (ext.toLowerCase() == '.dxf') {
//var unit = config.getSync('units');
con = Number(config.getSync('dxfImportScale'));
dxfFlag = true;
console.log('con', con);

/*if(unit == 'inch'){
con = 72;
}

// dirpath is used for loading images embedded in svg files
// converted svgs will not have images
importData(body, filename, null, con, dxfFlag);
else{
// mm
con = 2.83465;
}*/
}

// dirpath is used for loading images embedded in svg files
// converted svgs will not have images
importData(body, filename, null, con, dxfFlag);
}
}).catch(err => {
message('could not contact file conversion server', true);
});

var form = req.form();
form.append('format', 'svg');
form.append('fileUpload', fs.createReadStream(file));
}
}

Expand Down Expand Up @@ -1090,25 +1097,33 @@

exportbutton.className = 'button export spinner';

var req = request.post(url, function (err, resp, body) {
const formData = new FormData();
formData.append('fileUpload', exportNest(selected.pop(), true), {
filename: 'deepnest.svg',
contentType: 'image/svg+xml'
});
formData.append('format', 'dxf');

axios.post(url, formData.getBuffer(), {
headers: {
...formData.getHeaders(),
},
responseType: 'text'
}).then(resp => {
const body = resp.data;
// function (err, resp, body) {
exportbutton.className = 'button export';
if (err) {
message('could not contact file conversion server', true);
//if (err) {
// message('could not contact file conversion server', true);
//} else {
if (body.substring(0, 5) == 'error') {
message(body, true);
} else {
if(body.substring(0, 5) == 'error'){
message(body, true);
}
else{
fs.writeFileSync(fileName, body);
}
fs.writeFileSync(fileName, body);
}
});

var form = req.form();
form.append('format', 'dxf');
form.append('fileUpload', exportNest(selected.pop(), true), {
filename: 'deepnest.svg',
contentType: 'image/svg+xml'
//}
}).catch(err => {
message('could not contact file conversion server', true);
});
};
};
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@
},
"dependencies": {
"@electron/remote": "^2.1.2",
"graceful-fs": "^4.2.11",
"request": "^2.88.2"
"axios": "^1.7.9",
"form-data": "^4.0.1",
"graceful-fs": "^4.2.11"
},
"build": {
"appId": "com.deepnest.io",
Expand Down

0 comments on commit 58d9d13

Please sign in to comment.