update
This commit is contained in:
parent
43a4ce2cb6
commit
f00a3c5db1
|
@ -4,10 +4,10 @@ const fs = require('fs');
|
||||||
exports.ReadAPIConfig = async function (req, res) {
|
exports.ReadAPIConfig = async function (req, res) {
|
||||||
var path = '/root/monitor/setup/apiConfig.txt';
|
var path = '/root/monitor/setup/apiConfig.txt';
|
||||||
if (fs.existsSync(path)) {
|
if (fs.existsSync(path)) {
|
||||||
var text = fs.readFileSync(path,'utf8');
|
var text = fs.readFileSync(path, 'utf8');
|
||||||
res.send({status:true,data:text});
|
res.send({ status: true, data: text });
|
||||||
} else {
|
} else {
|
||||||
res.send({status:false});
|
res.send({ status: false });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -22,16 +22,16 @@ exports.SaveAPIConfig = async function (req, res) {
|
||||||
exports.ReadEngineConfig = async function (req, res) {
|
exports.ReadEngineConfig = async function (req, res) {
|
||||||
var path = '/root/monitor/setup/engine.json';
|
var path = '/root/monitor/setup/engine.json';
|
||||||
if (fs.existsSync(path)) {
|
if (fs.existsSync(path)) {
|
||||||
var text = fs.readFileSync(path,'utf8');
|
var text = fs.readFileSync(path, 'utf8');
|
||||||
if (text === "") {
|
if (text === "") {
|
||||||
const { execSync } = require('child_process');
|
const { execSync } = require('child_process');
|
||||||
execSync('rm /root/monitor/setup/engine.json');
|
execSync('rm /root/monitor/setup/engine.json');
|
||||||
execSync('sudo systemctl stop S905X_BI');
|
execSync('sudo systemctl stop S905X_BI');
|
||||||
execSync('sudo systemctl disable S905X_BI');
|
execSync('sudo systemctl disable S905X_BI');
|
||||||
}
|
}
|
||||||
res.send({status:true,data:text});
|
res.send({ status: true, data: text });
|
||||||
} else {
|
} else {
|
||||||
res.send({status:false});
|
res.send({ status: false });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -46,10 +46,10 @@ exports.SaveEngineConfig = async function (req, res) {
|
||||||
exports.ReadConfig = async function (req, res) {
|
exports.ReadConfig = async function (req, res) {
|
||||||
var path = req.body.path + "/data/config.json";
|
var path = req.body.path + "/data/config.json";
|
||||||
if (fs.existsSync(path)) {
|
if (fs.existsSync(path)) {
|
||||||
var text = fs.readFileSync(path,'utf8');
|
var text = fs.readFileSync(path, 'utf8');
|
||||||
res.send({status:true,data:text});
|
res.send({ status: true, data: text });
|
||||||
} else {
|
} else {
|
||||||
res.send({status:false});
|
res.send({ status: false });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -61,23 +61,58 @@ exports.Reset = async function (req, res) {
|
||||||
execSync('sudo systemctl disable S905X_BI');
|
execSync('sudo systemctl disable S905X_BI');
|
||||||
try {
|
try {
|
||||||
execSync('rm /root/monitor/setup/engine.json');
|
execSync('rm /root/monitor/setup/engine.json');
|
||||||
} catch(err) {
|
} catch (err) {
|
||||||
//console.log(err);
|
//console.log(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req.body.path !== "") {
|
if (req.body.path !== "") {
|
||||||
try {
|
try {
|
||||||
execSync('rm -rf ' + req.body.path);
|
execSync('rm -rf ' + req.body.path);
|
||||||
} catch(err) {
|
} catch (err) {
|
||||||
//console.log(err);
|
//console.log(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
res.send({status:true});
|
res.send({ status: true });
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.Reboot = async function (req, res) {
|
exports.Reboot = async function (req, res) {
|
||||||
const { execSync } = require('child_process');
|
const { execSync } = require('child_process');
|
||||||
execSync('sudo reboot now');
|
execSync('sudo reboot now');
|
||||||
res.send({status:true});
|
res.send({ status: true });
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.ControlEngine = async function (req, res) {
|
||||||
|
const { execSync } = require('child_process');
|
||||||
|
if (req.body.action == "off")
|
||||||
|
execSync('sudo systemctl stop S905X_BI');
|
||||||
|
else
|
||||||
|
execSync('sudo systemctl start S905X_BI');
|
||||||
|
res.send({ status: true });
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.EngineStatus = async function (req, res) {
|
||||||
|
const { execSync } = require('child_process');
|
||||||
|
try {
|
||||||
|
execSync('pgrep FaceProArm');
|
||||||
|
res.send({ status: true });
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
res.send({ status: false });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.SetupMedia = async function (req, res) {
|
||||||
|
const { execSync } = require('child_process');
|
||||||
|
var text = fs.readFileSync('/root/monitor/setup/engine.json', 'utf8');
|
||||||
|
var json = JSON.parse(text);
|
||||||
|
var folderEngine = json.data.engines[0].name;
|
||||||
|
try {
|
||||||
|
execSync('rm -rf /root/monitor/engine/' + folderEngine + '/data/audio');
|
||||||
|
execSync('ln -s /var/www/html/BiFace_Server_Lite/web/data/uploads /root/monitor/engine/' + folderEngine + '/data/bg/uploads');
|
||||||
|
execSync('ln -s /var/www/html/BiFace_Server_Lite/web/data/audio /root/monitor/engine/' + folderEngine + '/data/audio');
|
||||||
|
} catch (error) {
|
||||||
|
|
||||||
|
}
|
||||||
|
res.send({ status: true });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -17,4 +17,9 @@ module.exports = function (app) {
|
||||||
|
|
||||||
app.route('/Reboot').post(Api.Reboot);
|
app.route('/Reboot').post(Api.Reboot);
|
||||||
|
|
||||||
|
app.route('/ControlEngine').post(Api.ControlEngine);
|
||||||
|
|
||||||
|
app.route('/EngineStatus').get(Api.EngineStatus);
|
||||||
|
|
||||||
|
app.route('/SetupMedia').get(Api.SetupMedia);
|
||||||
};
|
};
|
||||||
|
|
43
server.js
43
server.js
|
@ -8,8 +8,9 @@ var express = require('express'),
|
||||||
jsonwebtoken = require("jsonwebtoken");
|
jsonwebtoken = require("jsonwebtoken");
|
||||||
const http = require("http");
|
const http = require("http");
|
||||||
var request = require('request');
|
var request = require('request');
|
||||||
app.use(bodyParser.urlencoded({extended: true}));
|
app.use(bodyParser.urlencoded({ extended: true }));
|
||||||
app.use(bodyParser.json({limit: '50mb'}));
|
app.use(bodyParser.json({ limit: '50mb' }));
|
||||||
|
const { execSync } = require('child_process');
|
||||||
|
|
||||||
app.use(function (req, res, next) {
|
app.use(function (req, res, next) {
|
||||||
if (req.headers && req.headers.authorization && req.headers.authorization.split(' ')[0] === 'JWT') {
|
if (req.headers && req.headers.authorization && req.headers.authorization.split(' ')[0] === 'JWT') {
|
||||||
|
@ -30,7 +31,7 @@ var ApiRoutes = require('./api/routes/ApiRoutes');
|
||||||
ApiRoutes(app);
|
ApiRoutes(app);
|
||||||
|
|
||||||
app.use(function (req, res) {
|
app.use(function (req, res) {
|
||||||
res.status(404).send({url: req.originalUrl + ' not found'});
|
res.status(404).send({ url: req.originalUrl + ' not found' });
|
||||||
});
|
});
|
||||||
|
|
||||||
const server = app.listen(port);
|
const server = app.listen(port);
|
||||||
|
@ -68,8 +69,8 @@ setInterval(function () {
|
||||||
request.get({
|
request.get({
|
||||||
url: "http://localhost/api/re-gen-feature",
|
url: "http://localhost/api/re-gen-feature",
|
||||||
json: true,
|
json: true,
|
||||||
headers: {'User-Agent': 'request'}
|
headers: { 'User-Agent': 'request' }
|
||||||
}, (err, res, data) => {
|
}, (err, res, data) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log('Error:', err);
|
console.log('Error:', err);
|
||||||
} else if (res.statusCode !== 200) {
|
} else if (res.statusCode !== 200) {
|
||||||
|
@ -78,13 +79,13 @@ request.get({
|
||||||
// data is already parsed as JSON:
|
// data is already parsed as JSON:
|
||||||
console.log(data);
|
console.log(data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
setInterval(function () {
|
setInterval(function () {
|
||||||
request.get({
|
request.get({
|
||||||
url: "http://localhost/api/auto-gen-feature",
|
url: "http://localhost/api/auto-gen-feature",
|
||||||
json: true,
|
json: true,
|
||||||
headers: {'User-Agent': 'request'}
|
headers: { 'User-Agent': 'request' }
|
||||||
}, (err, res, data) => {
|
}, (err, res, data) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log('Error:', err);
|
console.log('Error:', err);
|
||||||
|
@ -97,6 +98,34 @@ setInterval(function () {
|
||||||
});
|
});
|
||||||
}, 120000);
|
}, 120000);
|
||||||
|
|
||||||
|
setInterval(function () {
|
||||||
|
request.get({
|
||||||
|
url: "http://localhost/api/check-time-engine",
|
||||||
|
json: true,
|
||||||
|
headers: { 'User-Agent': 'request' }
|
||||||
|
}, (err, res, data) => {
|
||||||
|
if (err) {
|
||||||
|
console.log('Error:', err);
|
||||||
|
} else if (res.statusCode !== 200) {
|
||||||
|
console.log('Status:', res.statusCode);
|
||||||
|
} else {
|
||||||
|
// data is already parsed as JSON:
|
||||||
|
console.log("check-time-engine", data.status);
|
||||||
|
var processActive = false;
|
||||||
|
try {
|
||||||
|
execSync('pgrep FaceProArm');
|
||||||
|
processActive = true;
|
||||||
|
} catch (error) {
|
||||||
|
|
||||||
|
}
|
||||||
|
if (processActive && !data.status)
|
||||||
|
execSync('sudo systemctl stop S905X_BI');
|
||||||
|
if (!processActive && data.status)
|
||||||
|
execSync('sudo systemctl start S905X_BI');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, 10000);
|
||||||
|
|
||||||
console.log('BiFace Started On Port: ' + port);
|
console.log('BiFace Started On Port: ' + port);
|
||||||
|
|
||||||
module.exports = app;
|
module.exports = app;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user