-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
55 lines (46 loc) · 1.6 KB
/
app.js
File metadata and controls
55 lines (46 loc) · 1.6 KB
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
function io_connect(io){
return new Promise((resolve)=>{
})
}
async function printer(io,app){
const socket = await io_connect(io);
app.get('/', async (req, res) => {
try {
const files = await readdir('./files/status_db/');
const file = files[0];
if (file) {
const data = require('./files/processed/' + file.replace('.txt', '.json'));
await running_code(
data['layers'],
data['len'],
'./files/status_db/' + file.replace('.gcode', '.txt'),
socket
);
}
} catch (e) {
console.error(e);
}
});
app.post('/upload', async (req, res) => {
try {
const out = await save(req.files, 'uploadedFile', __dirname + '/files/uploads/');
if (out['status'] === 'File uploaded') {
const data = await convert('files/uploads/' + out['filename'], 'files/processed/');
const table = await info_table(data['info']);
res.render('refs/printing', { table });
await running_code(
data['layers'],
data['len'],
'./files/status_db/' + out['filename'].replace('.gcode', '.txt'),
socket
);
} else {
res.send(out['err']);
}
} catch (e) {
console.error(e);
res.status(500).send('Internal Server Error');
}
});
}
module.exports = printer