Browse Source

fixed shepherd config bug

all-modes
pbca26 8 years ago
parent
commit
5ae24e777c
  1. 6
      gui/loading.js
  2. 91
      routes/shepherd.js

6
gui/loading.js

@ -1,10 +1,10 @@
function IguanaAJAX(url, ajax_data) { function IguanaAJAX(url, ajax_data, timeout) {
return $.ajax({ return $.ajax({
data: JSON.stringify(ajax_data), data: JSON.stringify(ajax_data),
url: url, url: url,
type: 'POST', type: 'POST',
dataType: 'json', dataType: 'json',
timeout: 120000 timeout: timeout ? timeout : 120000
//beforeSend: showLoadingImgFn //beforeSend: showLoadingImgFn
}) })
.fail(function(xhr, textStatus, error) { .fail(function(xhr, textStatus, error) {
@ -125,7 +125,7 @@ function EDEX_DEXgetinfoAll(skip, minNotaries) {
'method': 'notarychains' 'method': 'notarychains'
}, },
tmp_index = 0, tmp_index = 0,
get_dex_notarychains = IguanaAJAX('http://127.0.0.1:' + config.iguanaPort, ajax_data).done(function(data) { get_dex_notarychains = IguanaAJAX('http://127.0.0.1:' + config.iguanaPort, ajax_data, 10000).done(function(data) {
get_dex_notarychains = JSON.parse(get_dex_notarychains.responseText); get_dex_notarychains = JSON.parse(get_dex_notarychains.responseText);
if (minNotaries > get_dex_notarychains.length) { // if config value exceeds total num of notaries if (minNotaries > get_dex_notarychains.length) { // if config value exceeds total num of notaries
minNotaries = get_dex_notarychains.length; minNotaries = get_dex_notarychains.length;

91
routes/shepherd.js

@ -87,6 +87,49 @@ shepherd.appConfig = {
} }
}; };
shepherd.saveLocalAppConf = function(appSettings) {
var appConfFileName = iguanaDir + '/config.json';
var FixFilePermissions = function() {
return new Promise(function(resolve, reject) {
var result = 'config.json file permissions updated to Read/Write';
fsnode.chmodSync(appConfFileName, '0666');
setTimeout(function() {
console.log(result);
resolve(result);
}, 1000);
});
}
var FsWrite = function() {
return new Promise(function(resolve, reject) {
var result = 'config.json write file is done'
fs.writeFile(appConfFileName,
JSON.stringify(appSettings)
.replace(/,/g, ',\n') // format json in human readable form
.replace(/:/g, ': ')
.replace(/{/g, '{\n')
.replace(/}/g, '\n}'), 'utf8', function(err) {
if (err)
return console.log(err);
});
fsnode.chmodSync(appConfFileName, '0666');
setTimeout(function() {
console.log(result);
console.log('app conf.json file is created successfully at: ' + iguanaConfsDir);
resolve(result);
}, 2000);
});
}
FsWrite()
.then(FixFilePermissions());
}
shepherd.loadLocalConfig = function() { shepherd.loadLocalConfig = function() {
if (fs.existsSync(iguanaDir + '/config.json')) { if (fs.existsSync(iguanaDir + '/config.json')) {
var localAppConfig = fs.readFileSync(iguanaDir + '/config.json', 'utf8'); var localAppConfig = fs.readFileSync(iguanaDir + '/config.json', 'utf8');
@ -106,6 +149,7 @@ shepherd.loadLocalConfig = function() {
return result; return result;
}; };
if (localAppConfig) {
var compareConfigs = compareJSON(shepherd.appConfig, JSON.parse(localAppConfig)); var compareConfigs = compareJSON(shepherd.appConfig, JSON.parse(localAppConfig));
if (Object.keys(compareConfigs).length) { if (Object.keys(compareConfigs).length) {
var newConfig = Object.assign(JSON.parse(localAppConfig), compareConfigs); var newConfig = Object.assign(JSON.parse(localAppConfig), compareConfigs);
@ -119,7 +163,9 @@ shepherd.loadLocalConfig = function() {
} else { } else {
return JSON.parse(localAppConfig); return JSON.parse(localAppConfig);
} }
} else {
return shepherd.appConfig;
}
} else { } else {
console.log('local config file is not found!'); console.log('local config file is not found!');
shepherd.saveLocalAppConf(shepherd.appConfig); shepherd.saveLocalAppConf(shepherd.appConfig);
@ -722,49 +768,6 @@ function slayer(flock) {
}); });
} }
shepherd.saveLocalAppConf = function(appSettings) {
var appConfFileName = iguanaDir + '/config.json';
var FixFilePermissions = function() {
return new Promise(function(resolve, reject) {
var result = 'config.json file permissions updated to Read/Write';
fsnode.chmodSync(appConfFileName, '0666');
setTimeout(function() {
console.log(result);
resolve(result);
}, 1000);
});
}
var FsWrite = function() {
return new Promise(function(resolve, reject) {
var result = 'config.json write file is done'
fs.writeFile(appConfFileName,
JSON.stringify(appSettings)
.replace(/,/g, ',\n') // format json in human readable form
.replace(/:/g, ': ')
.replace(/{/g, '{\n')
.replace(/}/g, '\n}'), 'utf8', function(err) {
if (err)
return console.log(err);
});
fsnode.chmodSync(appConfFileName, '0666');
setTimeout(function() {
console.log(result);
console.log('app conf.json file is created successfully at: ' + iguanaConfsDir);
resolve(result);
}, 2000);
});
}
FsWrite()
.then(FixFilePermissions()); // not really required now
}
function setConf(flock) { function setConf(flock) {
console.log(flock); console.log(flock);

Loading…
Cancel
Save