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

View File

@@ -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,24 +60,59 @@ 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});
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 });
};