'use strict'; const util = require('util'); 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}); } else { res.send({status:false}); } }; exports.SaveAPIConfig = async function (req, res) { 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'); res.send(req.body); }; exports.ReadEngineConfig = async function (req, res) { var path = '/root/monitor/setup/engine.json'; if (fs.existsSync(path)) { var text = fs.readFileSync(path,'utf8'); res.send({status:true,data:text}); } else { 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)); const { execSync } = require('child_process'); execSync('sudo systemctl restart S905X_BI'); res.send(req.body); }; 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}); } else { res.send({status:false}); } };