forked from reruin/sharelist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.js
42 lines (34 loc) · 813 Bytes
/
config.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
const fs = require('fs')
const os = require('os')
const config_path = process.cwd() +'/config/config.json'
const port = process.env.PORT || 33001
var data = {port}
try{
var cfg =fs.readFileSync(config_path,'utf-8');
if(cfg){
data = JSON.parse(cfg)
}
console.log('Load config from file')
}catch(e){
}
async function save(d){
if(d.token) data.token = d.token
if(d.path) data.path = d.path
let str = JSON.stringify( data )
return new Promise((resolve, reject) => {
fs.writeFile(config_path, str, function(err) {
if (err) {
console.log(err,'save config error')
} else {
console.log('save config success')
}
resolve(true)
})
})
}
function installed(){
return data.token && data.path
}
module.exports = {
data, save , installed , port
}