-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
53 lines (48 loc) · 1.62 KB
/
index.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
const express = require("express");
const bodyParser = require("body-parser");
const multer = require("multer");
const app = express();
const fs = require("fs");
var upload = multer({ dest: "input/" });
const util = require("util");
var cors = require("cors");
const exec = util.promisify(require("child_process").exec);
//CREATE EXPRESS APP
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cors());
//ROUTES WILL GO HERE
app.post("/", upload.single("myFile"), async function (req, res) {
let a = req.body;
console.log(req.file);
if (a.string) {
let filename = new Date().getTime().toString();
fs.writeFileSync(`./input/${filename}.fsa`, a.string);
const { stdout, stderr } = await exec(
`python3 iCarPS_offline.py ${a.key} ./input/${filename}.fsa`
);
let result = fs.readFileSync(`./output/${filename}_finalresult.txt`);
//console.log(result.toString("utf8"));
res.send({ data: result.toString("utf8") });
// res.sendFile(
// "/home/thangdp/tinsinh/iCarPS/test/3940d62ddf5b514cd990b1ee5c8f4fcc"
// );
} else {
console.log(req.body.key);
const { stdout, stderr } = await exec(
`python3 iCarPS_offline.py ${a.key} ./input/${req.file.filename}`
);
let result = fs.readFileSync(
`./output/${req.file.filename}_finalresult.txt`
);
//console.log(result.toString("utf8"));
res.send({ data: result.toString("utf8") });
}
// fs.readFile(req.file, "utf8", (err, data) => {
// if (err) {
// console.error(err);
// return;
// }
// console.log(data);
// });
});
app.listen(5000, () => console.log("Server started on port 3000"));