Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated request with axios. #183

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
15 changes: 11 additions & 4 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 All @@ -51,5 +52,11 @@
"win": {
"icon": "icon.ico"
}
}
}
},
"contributors": [
{
"name": "Josef Fröhle",
"email": "[email protected]"
}
]
}