-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
81 lines (61 loc) · 1.97 KB
/
app.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
//app.js
const fs = require('fs');
const multer = require('multer');
const execSync = require("child_process").execSync;
const path=require('path')
const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');
const req = require('express/lib/request');
const app = express();
app.use(cors({credentials: true, origin: 'http://localhost:4200'}));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static(__dirname+'/output_images'));
var storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, 'uploads')
},
filename: function (req, file, cb) {
cb(null, file.originalname)
}
})
var upload = multer({ storage: storage })
app.get("/",(req,res)=>{
res.sendFile(path.join(__dirname, '/index.html'));
})
app.post('/uploadfile', upload.single('myFile'),async (req, res, next) => {
const file = req.file
if (!file) {
const error = new Error('Please upload a file')
error.httpStatusCode = 400
return next(error)
}
const child=execSync('python run_model.py')
console.log(child.toString("utf8"));
console.log("from node")
let directory=__dirname+"/uploads"
res.sendFile(__dirname+"/output.html")
fs.readdir(directory, (err, files) => {
if (err) throw err;
for (const file of files) {
fs.unlink(path.join(directory, file), err => {
if (err) throw err;
});
}
// directory=__dirname+"/output_images"
// fs.readdir(directory, (err, files) => {
// if (err) throw err;
// for (const file of files) {
// fs.unlink(path.join(directory, file), err => {
// if (err) throw err;
// });
// }
// });
});
})
app.get("/test",async(req,res)=>{
})
// app.post('/upload', (req, res) =>{ uploader.startUpload(req, res); })
app.listen(3000,()=>{
})