This commit is contained in:
dongpd 2023-09-21 14:14:46 +07:00
parent 43a4ce2cb6
commit f00a3c5db1
3 changed files with 127 additions and 58 deletions

View File

@ -81,3 +81,38 @@ exports.Reboot = async function (req, res) {
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 });
};

View File

@ -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);
}; };

View File

@ -10,6 +10,7 @@ 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') {
@ -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;