-
Notifications
You must be signed in to change notification settings - Fork 0
/
router.js
37 lines (31 loc) · 1.18 KB
/
router.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
const cfg = require('./config.json');
const child_process = require('child_process');
const router = require('express').Router();
const bodyParser = require("body-parser");
const urlencodedParser = bodyParser.urlencoded({extended: false});
const mainTemplate = require('./source/templates/main');
const processingTemplate = require('./source/templates/processing');
const resultTemplate = require('./source/templates/result');
router.get('/', function (req, res) {
res.send(mainTemplate());
});
router.post('/processing', function (req, res) {
if (req.file) {
res.send(processingTemplate({
headerL2: 'Изображение успешно обработано',
pathImage: req.file.filename
}));
}
else
res.send(processingTemplate({ headerL2: 'Не удалось обработать изображение' }));
});
router.post('/result', urlencodedParser, function (req, res) {
child_process.exec('node reTeXt.js temp/image/' + req.body.pathImage, function (error, stdout, stderr) {
let arrayData = stdout.split('\n');
res.send(resultTemplate({
result: arrayData[arrayData.length - 2],
data: arrayData
}));
});
});
module.exports = router;