Compare commits
No commits in common. "master" and "BiFaceAPI" have entirely different histories.
|
@ -4,15 +4,15 @@ const fs = require('fs');
|
|||
exports.ReadAPIConfig = async function (req, res) {
|
||||
var path = '/root/monitor/setup/apiConfig.txt';
|
||||
if (fs.existsSync(path)) {
|
||||
var text = fs.readFileSync(path, 'utf8');
|
||||
res.send({ status: true, data: text });
|
||||
var text = fs.readFileSync(path,'utf8');
|
||||
res.send({status:true,data:text});
|
||||
} else {
|
||||
res.send({ status: false });
|
||||
res.send({status:false});
|
||||
}
|
||||
};
|
||||
|
||||
exports.SaveAPIConfig = async function (req, res) {
|
||||
fs.writeFileSync('/root/monitor/setup/apiConfig.txt', JSON.stringify(req.body));
|
||||
fs.writeFileSync('/root/monitor/setup/apiConfig.txt', JSON.stringify(req.body));
|
||||
const { execSync } = require('child_process');
|
||||
execSync('sudo systemctl enable S905X_BI');
|
||||
execSync('sudo systemctl start S905X_BI');
|
||||
|
@ -22,22 +22,22 @@ exports.SaveAPIConfig = async function (req, res) {
|
|||
exports.ReadEngineConfig = async function (req, res) {
|
||||
var path = '/root/monitor/setup/engine.json';
|
||||
if (fs.existsSync(path)) {
|
||||
var text = fs.readFileSync(path, 'utf8');
|
||||
if (text === "") {
|
||||
const { execSync } = require('child_process');
|
||||
execSync('rm /root/monitor/setup/engine.json');
|
||||
execSync('sudo systemctl stop S905X_BI');
|
||||
execSync('sudo systemctl disable S905X_BI');
|
||||
}
|
||||
res.send({ status: true, data: text });
|
||||
var text = fs.readFileSync(path,'utf8');
|
||||
if (text === "") {
|
||||
const { execSync } = require('child_process');
|
||||
execSync('rm /root/monitor/setup/engine.json');
|
||||
execSync('sudo systemctl stop S905X_BI');
|
||||
execSync('sudo systemctl disable S905X_BI');
|
||||
}
|
||||
res.send({status:true,data:text});
|
||||
} else {
|
||||
res.send({ status: false });
|
||||
res.send({status:false});
|
||||
}
|
||||
};
|
||||
|
||||
exports.SaveEngineConfig = async function (req, res) {
|
||||
fs.writeFileSync(req.body.path + "/data/config.json", req.body.configEngine);
|
||||
fs.writeFileSync('/root/monitor/setup/engine.json', JSON.stringify(req.body.config));
|
||||
fs.writeFileSync(req.body.path + "/data/config.json", req.body.configEngine);
|
||||
fs.writeFileSync('/root/monitor/setup/engine.json', JSON.stringify(req.body.config));
|
||||
const { execSync } = require('child_process');
|
||||
execSync('sudo systemctl restart S905X_BI');
|
||||
res.send(req.body);
|
||||
|
@ -46,10 +46,10 @@ exports.SaveEngineConfig = async function (req, res) {
|
|||
exports.ReadConfig = async function (req, res) {
|
||||
var path = req.body.path + "/data/config.json";
|
||||
if (fs.existsSync(path)) {
|
||||
var text = fs.readFileSync(path, 'utf8');
|
||||
res.send({ status: true, data: text });
|
||||
var text = fs.readFileSync(path,'utf8');
|
||||
res.send({status:true,data:text});
|
||||
} else {
|
||||
res.send({ status: false });
|
||||
res.send({status:false});
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -60,59 +60,19 @@ exports.Reset = async function (req, res) {
|
|||
execSync('sudo systemctl stop S905X_BI');
|
||||
execSync('sudo systemctl disable S905X_BI');
|
||||
try {
|
||||
execSync('rm /root/monitor/setup/engine.json');
|
||||
} catch (err) {
|
||||
execSync('rm /root/monitor/setup/engine.json');
|
||||
} catch(err) {
|
||||
//console.log(err);
|
||||
}
|
||||
|
||||
if (req.body.path !== "") {
|
||||
try {
|
||||
execSync('rm -rf ' + req.body.path);
|
||||
} catch (err) {
|
||||
//console.log(err);
|
||||
}
|
||||
try {
|
||||
execSync('rm -rf ' + req.body.path);
|
||||
} catch(err) {
|
||||
//console.log(err);
|
||||
}
|
||||
}
|
||||
res.send({ status: true });
|
||||
res.send({status:true});
|
||||
};
|
||||
|
||||
exports.Reboot = async function (req, res) {
|
||||
const { execSync } = require('child_process');
|
||||
execSync('sudo reboot now');
|
||||
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 });
|
||||
};
|
||||
|
||||
|
|
|
@ -15,11 +15,4 @@ module.exports = function (app) {
|
|||
|
||||
app.route('/Reset').post(Api.Reset);
|
||||
|
||||
app.route('/Reboot').post(Api.Reboot);
|
||||
|
||||
app.route('/ControlEngine').post(Api.ControlEngine);
|
||||
|
||||
app.route('/EngineStatus').get(Api.EngineStatus);
|
||||
|
||||
app.route('/SetupMedia').get(Api.SetupMedia);
|
||||
};
|
||||
|
|
77
server.js
77
server.js
|
@ -1,16 +1,15 @@
|
|||
'use strict';
|
||||
|
||||
var express = require('express'),
|
||||
app = express(),
|
||||
cors = require('cors'),
|
||||
port = 4004,
|
||||
bodyParser = require('body-parser'),
|
||||
jsonwebtoken = require("jsonwebtoken");
|
||||
app = express(),
|
||||
cors = require('cors'),
|
||||
port = 4004,
|
||||
bodyParser = require('body-parser'),
|
||||
jsonwebtoken = require("jsonwebtoken");
|
||||
const http = require("http");
|
||||
var request = require('request');
|
||||
app.use(bodyParser.urlencoded({ extended: true }));
|
||||
app.use(bodyParser.json({ limit: '50mb' }));
|
||||
const { execSync } = require('child_process');
|
||||
var request = require('request');
|
||||
app.use(bodyParser.urlencoded({extended: true}));
|
||||
app.use(bodyParser.json({limit: '50mb'}));
|
||||
|
||||
app.use(function (req, res, next) {
|
||||
if (req.headers && req.headers.authorization && req.headers.authorization.split(' ')[0] === 'JWT') {
|
||||
|
@ -31,7 +30,7 @@ var ApiRoutes = require('./api/routes/ApiRoutes');
|
|||
ApiRoutes(app);
|
||||
|
||||
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);
|
||||
|
@ -44,48 +43,32 @@ io.sockets.on('connection', function (socket) {
|
|||
});
|
||||
});
|
||||
|
||||
setInterval(function () {
|
||||
setInterval(function () {
|
||||
http.get("http://localhost/api/sync", res => {
|
||||
res.on("data", d => {
|
||||
|
||||
});
|
||||
res.on("end", () => {
|
||||
console.log("end");
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}, 60000);
|
||||
|
||||
setInterval(function () {
|
||||
setInterval(function () {
|
||||
http.get("http://localhost/api/check-logs", res => {
|
||||
res.on("data", d => {
|
||||
|
||||
});
|
||||
res.on("end", () => {
|
||||
console.log("end");
|
||||
});
|
||||
});
|
||||
}, 20000);
|
||||
});
|
||||
});
|
||||
}, 60000);
|
||||
|
||||
request.get({
|
||||
url: "http://localhost/api/re-gen-feature",
|
||||
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(data);
|
||||
}
|
||||
});
|
||||
|
||||
setInterval(function () {
|
||||
request.get({
|
||||
url: "http://localhost/api/auto-gen-feature",
|
||||
url: "http://localhost/api/re-gen-feature",
|
||||
json: true,
|
||||
headers: { 'User-Agent': 'request' }
|
||||
headers: {'User-Agent': 'request'}
|
||||
}, (err, res, data) => {
|
||||
if (err) {
|
||||
console.log('Error:', err);
|
||||
|
@ -95,14 +78,13 @@ setInterval(function () {
|
|||
// data is already parsed as JSON:
|
||||
console.log(data);
|
||||
}
|
||||
});
|
||||
}, 120000);
|
||||
});
|
||||
|
||||
setInterval(function () {
|
||||
request.get({
|
||||
url: "http://localhost/api/check-time-engine",
|
||||
url: "http://localhost/api/auto-gen-feature",
|
||||
json: true,
|
||||
headers: { 'User-Agent': 'request' }
|
||||
headers: {'User-Agent': 'request'}
|
||||
}, (err, res, data) => {
|
||||
if (err) {
|
||||
console.log('Error:', err);
|
||||
|
@ -110,21 +92,10 @@ setInterval(function () {
|
|||
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');
|
||||
console.log(data);
|
||||
}
|
||||
});
|
||||
}, 10000);
|
||||
});
|
||||
}, 120000);
|
||||
|
||||
console.log('BiFace Started On Port: ' + port);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user