-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
125 lines (110 loc) · 3.06 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
const express = require("express");
const app = express();
const fileUpload = require("express-fileupload");
const exec = require("child_process").exec;
app.use(express.static("public"));
app.use(
fileUpload({
useTempFiles: true,
tempFileDir: "/tmp/",
})
);
app.post("/parse_windtunnel", (req, res) => {
if (req.files && Object.keys(req.files).length !== 0) {
const blackboxZip = req.files.blackboxZip;
const windtunnelZip = req.files.windtunnelZip;
// Logging uploading files
console.log(blackboxZip);
console.log(windtunnelZip);
exec(
"python3 -m python_tools.scripts.parse_windtunnel " +
blackboxZip.tempFilePath +
" " +
windtunnelZip.tempFilePath +
" " +
"/tmp/processed.zip",
(error, stdout, stderr) => {
console.log("stdout: " + stdout);
console.log("stderr: " + stderr);
if (error !== null) {
console.log("exec error: " + error);
res.sendStatus(500);
return;
}
res.download("/tmp/processed.zip", function (err) {
if (err) {
console.log(err);
}
});
}
);
} else {
res.status = 400;
res.send("No file uploaded!!");
}
});
app.post("/decode_blackbox", (req, res) => {
if (req.files && Object.keys(req.files).length !== 0) {
const uploadedFile = req.files.uploadFile;
// Logging uploading file
console.log(uploadedFile);
exec(
"python3 -m python_tools.scripts.decode_blackbox " +
uploadedFile.tempFilePath +
" " +
uploadedFile.tempFilePath +
".csv",
(error, stdout, stderr) => {
console.log("stdout: " + stdout);
console.log("stderr: " + stderr);
if (error !== null) {
console.log("exec error: " + error);
res.sendStatus(500);
return;
}
res.download(uploadedFile.tempFilePath + ".csv", function (err) {
if (err) {
console.log(err);
}
});
}
);
} else {
res.status = 400;
res.send("No file uploaded!!");
}
});
app.post("/decode_thrust", (req, res) => {
if (req.files && Object.keys(req.files).length !== 0) {
const uploadedFile = req.files.uploadFile;
// Logging uploading file
console.log(uploadedFile);
exec(
"python3 -m python_tools.scripts.decode_thrust " +
uploadedFile.tempFilePath +
" " +
uploadedFile.tempFilePath +
"_csvs.zip",
(error, stdout, stderr) => {
console.log("stdout: " + stdout);
console.log("stderr: " + stderr);
if (error !== null) {
console.log("exec error: " + error);
res.sendStatus(500);
return;
}
res.download(uploadedFile.tempFilePath + "_csvs.zip", function (err) {
if (err) {
console.log(err);
}
});
}
);
} else {
res.status = 400;
res.send("No file uploaded!!");
}
});
app.listen(process.env.PORT, () => {
console.log(`Example app listening on port ${process.env.PORT}`);
});