forked from gropox/randomblockchain
-
Notifications
You must be signed in to change notification settings - Fork 1
/
global.js
54 lines (41 loc) · 1.21 KB
/
global.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
var dateFormat = require('dateformat');
module.exports.runtime = {
dl : 0
}
var fs = require("fs");
const HOME = require('os').homedir();
const CONFIG_FILE = HOME + "/.randomblockchain.js";
module.exports.settings = {
api : "https://golos.io",
dbdir : "/tmp",
startNewRound : false,
broadcast : false
};
function init() {
//Load setting Object
try {
let sets = JSON.parse(fs.readFileSync(CONFIG_FILE, "utf8"));
module.exports.settings = sets;
console.log("loaded settings:\n" + JSON.stringify(module.exports.settings, null, 4));
} catch(e) {
console.warn("unable to read config (" + CONFIG_FILE + ")");
try {
fs.writeFileSync(CONFIG_FILE, JSON.stringify(module.exports.settings, null, 4), "utf8");
} catch(e) {
console.error("unable to create dummy config (" + CONFIG_FILE + ")");
}
}
}
module.exports.formatDateTime = function(ms) {
var options = {
year: 'numeric',
month: 'numeric',
day: 'numeric',
timezone: 'UTC',
hour: 'numeric',
minute: 'numeric',
second: 'numeric'
};
return dateFormat(new Date(ms), "dd.mm.yyyy h:MM:ss");
}
init();