forked from reruin/sharelist
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.js
More file actions
63 lines (52 loc) · 1.15 KB
/
config.js
File metadata and controls
63 lines (52 loc) · 1.15 KB
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
55
56
57
58
59
60
61
62
63
const fs = require('fs')
const os = require('os')
const config_path = process.cwd() +'/cache/config.json'
const port = process.env.PORT || 33001
const providers = [
{name:'GoogleDrive',code:'gd'},
{name:'OneDrive',code:'od'},
{name:'Custom',code:'cu'},
]
//onedrive 链接有效期 10 分钟
var data = {
port ,
enabled_proxy : 0 ,
//目录刷新时间 15分钟
cache_refresh_dir:15 * 60 * 1000,
//外链 10分钟
cache_refresh_file: 5 * 60 * 1000
}
try{
var cfg =fs.readFileSync(config_path,'utf-8');
if(cfg){
cfg = JSON.parse(cfg)
for(var i in cfg){
data[i] = cfg[i]
}
}
console.log('Load config from file')
}catch(e){
}
async function save(d){
console.log(d)
for(var i in d){
data[i] = d[i]
}
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 , providers
}